You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by hy...@apache.org on 2013/07/02 16:16:35 UTC
[41/51] [partial] TAJO-22: The package prefix should be
org.apache.tajo. (DaeMyung Kang via hyunsik)
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/datum/DatumFactory.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/DatumFactory.java b/tajo-common/src/main/java/org/apache/tajo/datum/DatumFactory.java
new file mode 100644
index 0000000..89b8472
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/DatumFactory.java
@@ -0,0 +1,130 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.datum;
+
+public class DatumFactory {
+ public static NullDatum createNullDatum() {
+ return NullDatum.get();
+ }
+
+ public static BooleanDatum createBool(String val) {
+ boolean boolVal = val.equalsIgnoreCase("true");
+ return new BooleanDatum(boolVal);
+ }
+
+ public static BooleanDatum createBool(byte val) {
+ boolean boolVal = val == 0x01;
+ return new BooleanDatum(boolVal);
+ }
+
+ public static BooleanDatum createBool(boolean val) {
+ return new BooleanDatum(val);
+ }
+ /*
+ public static BoolDatum createBool(int val) {
+ return new BoolDatum(val);
+ }
+ */
+
+ public static BitDatum createBit(byte val) {
+ return new BitDatum(val);
+ }
+ /*
+ public static ByteDatum createBit(int val) {
+ return new ByteDatum(val);
+ }*/
+
+ public static CharDatum createChar(char val) {
+ return new CharDatum(val);
+ }
+
+ public static CharDatum createChar(byte val) {
+ return new CharDatum(val);
+ }
+
+ /*
+ public static CharDatum createChar(Integer val) {
+ return new CharDatum(val);
+ }
+ */
+
+ public static Int2Datum createInt2(short val) {
+ return new Int2Datum(val);
+ }
+
+ public static Int2Datum createInt2(String val) {
+ return new Int2Datum(Short.valueOf(val));
+ }
+
+ public static Int4Datum createInt4(int val) {
+ return new Int4Datum(val);
+ }
+
+ public static Int4Datum createInt4(String val) {
+ return new Int4Datum(Integer.valueOf(val));
+ }
+
+ public static Int8Datum createInt8(long val) {
+ return new Int8Datum(val);
+ }
+
+ public static Int8Datum createInt8(String val) {
+ return new Int8Datum(Long.valueOf(val));
+ }
+
+ public static Float4Datum createFloat4(float val) {
+ return new Float4Datum(val);
+ }
+
+ public static Float4Datum createFloat4(String val) {
+ return new Float4Datum(Float.valueOf(val));
+ }
+
+ public static Float8Datum createFloat8(double val) {
+ return new Float8Datum(val);
+ }
+
+ public static Float8Datum createFloat8(String val) {
+ return new Float8Datum(Double.valueOf(val));
+ }
+
+ public static TextDatum createText(String val) {
+ return new TextDatum(val);
+ }
+
+ public static TextDatum createText(byte[] val) {
+ return new TextDatum(val);
+ }
+
+ public static BlobDatum createBlob(byte[] val) {
+ return new BlobDatum(val);
+ }
+
+ public static BlobDatum createBlob(String val) {
+ return new BlobDatum(val.getBytes());
+ }
+
+ public static Inet4Datum createInet4(byte[] val) {
+ return new Inet4Datum(val);
+ }
+
+ public static Inet4Datum createInet4(String val) {
+ return new Inet4Datum(val);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/datum/Float4Datum.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/Float4Datum.java b/tajo-common/src/main/java/org/apache/tajo/datum/Float4Datum.java
new file mode 100644
index 0000000..cbe9206
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/Float4Datum.java
@@ -0,0 +1,279 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.datum;
+
+import com.google.gson.annotations.Expose;
+import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.datum.exception.InvalidCastException;
+import org.apache.tajo.datum.exception.InvalidOperationException;
+import org.apache.tajo.datum.json.GsonCreator;
+
+import java.nio.ByteBuffer;
+
+public class Float4Datum extends NumericDatum {
+ private static final int size = 4;
+ @Expose float val;
+
+ public Float4Datum() {
+ super(TajoDataTypes.Type.FLOAT4);
+ }
+
+ public Float4Datum(float val) {
+ this();
+ this.val = val;
+ }
+
+ public Float4Datum(byte[] bytes) {
+ this();
+ ByteBuffer bb = ByteBuffer.wrap(bytes);
+ this.val = bb.getFloat();
+ }
+
+ public boolean asBool() {
+ throw new InvalidCastException();
+ }
+
+ @Override
+ public short asInt2() {
+ return (short) val;
+ }
+
+ @Override
+ public int asInt4() {
+ return (int) val;
+ }
+
+ @Override
+ public long asInt8() {
+ return (long) val;
+ }
+
+ @Override
+ public byte asByte() {
+ throw new InvalidCastException();
+ }
+
+ @Override
+ public byte[] asByteArray() {
+ ByteBuffer bb = ByteBuffer.allocate(4);
+ bb.putFloat(val);
+ return bb.array();
+ }
+
+ @Override
+ public float asFloat4() {
+ return val;
+ }
+
+ @Override
+ public double asFloat8() {
+ return val;
+ }
+
+ @Override
+ public String asChars() {
+ return ""+val;
+ }
+
+ @Override
+ public String toJSON() {
+ return GsonCreator.getInstance().toJson(this, Datum.class);
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ @Override
+ public int hashCode() {
+ return (int) val;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Float4Datum) {
+ Float4Datum other = (Float4Datum) obj;
+ return val == other.val;
+ }
+
+ return false;
+ }
+
+ @Override
+ public BooleanDatum equalsTo(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createBool(val == datum.asInt2());
+ case INT4:
+ return DatumFactory.createBool(val == datum.asInt4());
+ case INT8:
+ return DatumFactory.createBool(val == datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createBool(val == datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createBool(val == datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public int compareTo(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ if (val < datum.asInt2()) {
+ return -1;
+ } else if (datum.asInt2() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ case INT4:
+ if (val < datum.asInt4()) {
+ return -1;
+ } else if (datum.asInt4() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ case INT8:
+ if (val < datum.asInt8()) {
+ return -1;
+ } else if (datum.asInt8() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ case FLOAT4:
+ if (val < datum.asFloat4()) {
+ return -1;
+ } else if (datum.asFloat4() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ case FLOAT8:
+ if (val < datum.asFloat8()) {
+ return -1;
+ } else if (datum.asFloat8() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum plus(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createFloat4(val + datum.asInt2());
+ case INT4:
+ return DatumFactory.createFloat4(val + datum.asInt4());
+ case INT8:
+ return DatumFactory.createFloat8(val + datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat8(val + datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val + datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum minus(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createFloat4(val - datum.asInt2());
+ case INT4:
+ return DatumFactory.createFloat4(val - datum.asInt4());
+ case INT8:
+ return DatumFactory.createFloat8(val - datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat8(val - datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val - datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum multiply(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createFloat4(val * datum.asInt2());
+ case INT4:
+ return DatumFactory.createFloat4(val * datum.asInt4());
+ case INT8:
+ return DatumFactory.createFloat8(val * datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat8(val * datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val * datum.asFloat8());
+ default:
+ throw new InvalidOperationException();
+ }
+ }
+
+ @Override
+ public Datum divide(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createFloat4(val / datum.asInt2());
+ case INT4:
+ return DatumFactory.createFloat4(val / datum.asInt4());
+ case INT8:
+ return DatumFactory.createFloat8(val / datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat8(val / datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val / datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum modular(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createFloat4(val / datum.asInt2());
+ case INT4:
+ return DatumFactory.createFloat4(val / datum.asInt4());
+ case INT8:
+ return DatumFactory.createFloat4(val / datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat4(val / datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val / datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public void inverseSign() {
+ this.val = - val;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/datum/Float8Datum.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/Float8Datum.java b/tajo-common/src/main/java/org/apache/tajo/datum/Float8Datum.java
new file mode 100644
index 0000000..a75f042
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/Float8Datum.java
@@ -0,0 +1,271 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ *
+ */
+package org.apache.tajo.datum;
+
+import com.google.gson.annotations.Expose;
+import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.datum.exception.InvalidOperationException;
+import org.apache.tajo.datum.json.GsonCreator;
+
+import java.nio.ByteBuffer;
+
+public class Float8Datum extends NumericDatum {
+ private static final int size = 8;
+ @Expose private double val;
+
+ public Float8Datum() {
+ super(TajoDataTypes.Type.FLOAT8);
+ }
+
+ public Float8Datum(double val) {
+ this();
+ this.val = val;
+ }
+
+ public Float8Datum(byte[] bytes) {
+ this();
+ ByteBuffer bb = ByteBuffer.wrap(bytes);
+ this.val = bb.getDouble();
+ }
+
+ @Override
+ public short asInt2() {
+ return (short) val;
+ }
+
+ @Override
+ public int asInt4() {
+ return (int) val;
+ }
+
+ @Override
+ public long asInt8() {
+ return (long) val;
+ }
+
+ @Override
+ public byte[] asByteArray() {
+ ByteBuffer bb = ByteBuffer.allocate(8);
+ bb.putDouble(val);
+ return bb.array();
+ }
+
+ @Override
+ public float asFloat4() {
+ return (float) val;
+ }
+
+ @Override
+ public double asFloat8() {
+ return val;
+ }
+
+ @Override
+ public String asChars() {
+ return ""+val;
+ }
+
+ @Override
+ public String toJSON() {
+ return GsonCreator.getInstance().toJson(this, Datum.class);
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ @Override
+ public int hashCode() {
+ return (int) val;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj instanceof Float8Datum) {
+ Float8Datum other = (Float8Datum) obj;
+ return val == other.val;
+ }
+
+ return false;
+ }
+
+ @Override
+ public BooleanDatum equalsTo(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createBool(val == datum.asInt2());
+ case INT4:
+ return DatumFactory.createBool(val == datum.asInt4());
+ case INT8:
+ return DatumFactory.createBool(val == datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createBool(val == datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createBool(val == datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public int compareTo(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ if (val < datum.asInt2()) {
+ return -1;
+ } else if (datum.asInt2() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ case INT4:
+ if (val < datum.asInt4()) {
+ return -1;
+ } else if (datum.asInt4() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ case INT8:
+ if (val < datum.asInt8()) {
+ return -1;
+ } else if (datum.asInt8() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ case FLOAT4:
+ if (val < datum.asFloat4()) {
+ return -1;
+ } else if (datum.asFloat4() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ case FLOAT8:
+ if (val < datum.asFloat8()) {
+ return -1;
+ } else if (datum.asFloat8() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum plus(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createFloat8(val + datum.asInt2());
+ case INT4:
+ return DatumFactory.createFloat8(val + datum.asInt4());
+ case INT8:
+ return DatumFactory.createFloat8(val + datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat8(val + datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val + datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum minus(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createFloat8(val - datum.asInt2());
+ case INT4:
+ return DatumFactory.createFloat8(val - datum.asInt4());
+ case INT8:
+ return DatumFactory.createFloat8(val - datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat8(val - datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val - datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum multiply(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createFloat8(val * datum.asInt2());
+ case INT4:
+ return DatumFactory.createFloat8(val * datum.asInt4());
+ case INT8:
+ return DatumFactory.createFloat8(val * datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat8(val * datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val * datum.asFloat8());
+ default:
+ throw new InvalidOperationException();
+ }
+ }
+
+ @Override
+ public Datum divide(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createFloat8(val / datum.asInt2());
+ case INT4:
+ return DatumFactory.createFloat8(val / datum.asInt4());
+ case INT8:
+ return DatumFactory.createFloat8(val / datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat8(val / datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val / datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum modular(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createFloat8(val % datum.asInt2());
+ case INT4:
+ return DatumFactory.createFloat8(val % datum.asInt4());
+ case INT8:
+ return DatumFactory.createFloat8(val % datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat8(val % datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val % datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public void inverseSign() {
+ this.val = -val;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/datum/Inet4Datum.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/Inet4Datum.java b/tajo-common/src/main/java/org/apache/tajo/datum/Inet4Datum.java
new file mode 100644
index 0000000..f039220
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/Inet4Datum.java
@@ -0,0 +1,138 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.datum;
+
+import com.google.common.base.Preconditions;
+import com.google.gson.annotations.Expose;
+import org.apache.tajo.datum.exception.InvalidOperationException;
+import org.apache.tajo.datum.json.GsonCreator;
+
+import static org.apache.tajo.common.TajoDataTypes.Type;
+
+public class Inet4Datum extends Datum {
+ private static final int size = 4;
+ @Expose private int address;
+
+ public Inet4Datum() {
+ super(Type.INET4);
+ }
+
+ public Inet4Datum(String addr) {
+ this();
+ String [] elems = addr.split("\\.");
+ address = Integer.valueOf(elems[3]) & 0xFF;
+ address |= ((Integer.valueOf(elems[2]) << 8) & 0xFF00);
+ address |= ((Integer.valueOf(elems[1]) << 16) & 0xFF0000);
+ address |= ((Integer.valueOf(elems[0]) << 24) & 0xFF000000);
+ }
+
+ public Inet4Datum(byte[] addr) {
+ this();
+ Preconditions.checkArgument(addr.length == size);
+ address = addr[3] & 0xFF;
+ address |= ((addr[2] << 8) & 0xFF00);
+ address |= ((addr[1] << 16) & 0xFF0000);
+ address |= ((addr[0] << 24) & 0xFF000000);
+ }
+
+ @Override
+ public int asInt4() {
+ return this.address;
+ }
+
+ @Override
+ public long asInt8() {
+ return this.address;
+ }
+
+ @Override
+ public byte[] asByteArray() {
+ byte[] addr = new byte[size];
+ addr[0] = (byte) ((address >>> 24) & 0xFF);
+ addr[1] = (byte) ((address >>> 16) & 0xFF);
+ addr[2] = (byte) ((address >>> 8) & 0xFF);
+ addr[3] = (byte) (address & 0xFF);
+ return addr;
+ }
+
+ @Override
+ public String asChars() {
+ return numericToTextFormat(asByteArray());
+ }
+
+ @Override
+ public String toJSON() {
+ return GsonCreator.getInstance().toJson(this, Datum.class);
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ @Override
+ public int hashCode() {
+ return address;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Inet4Datum) {
+ Inet4Datum other = (Inet4Datum) obj;
+ return this.address == other.address;
+ }
+
+ return false;
+ }
+
+ @Override
+ public BooleanDatum equalsTo(Datum datum) {
+ switch (datum.type()) {
+ case INET4:
+ return DatumFactory.createBool(this.address == ((Inet4Datum)datum).address);
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public int compareTo(Datum datum) {
+ switch (datum.type()) {
+ case INET4:
+ byte [] bytes = asByteArray();
+ byte [] other = datum.asByteArray();
+
+ for (int i = 0; i < 4; i++) {
+ if (bytes[i] > other[i]) {
+ return 1;
+ } else if (bytes[i] < other[i]) {
+ return -1;
+ }
+ }
+
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ static String numericToTextFormat(byte[] src) {
+ return (src[0] & 0xff) + "." + (src[1] & 0xff) + "." + (src[2] & 0xff)
+ + "." + (src[3] & 0xff);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/datum/Int2Datum.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/Int2Datum.java b/tajo-common/src/main/java/org/apache/tajo/datum/Int2Datum.java
new file mode 100644
index 0000000..92a867f
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/Int2Datum.java
@@ -0,0 +1,269 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.datum;
+
+import com.google.gson.annotations.Expose;
+import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.datum.exception.InvalidOperationException;
+import org.apache.tajo.datum.json.GsonCreator;
+
+import java.nio.ByteBuffer;
+
+public class Int2Datum extends NumericDatum {
+ private static final int size = 2;
+ @Expose private short val;
+
+ public Int2Datum() {
+ super(TajoDataTypes.Type.INT2);
+ }
+
+ public Int2Datum(short val) {
+ this();
+ this.val = val;
+ }
+
+ public Int2Datum(byte[] bytes) {
+ this();
+ ByteBuffer bb = ByteBuffer.wrap(bytes);
+ this.val = bb.getShort();
+ }
+
+ @Override
+ public short asInt2() {
+ return val;
+ }
+
+ @Override
+ public int asInt4() {
+ return val;
+ }
+
+ @Override
+ public long asInt8() {
+ return val;
+ }
+
+ @Override
+ public byte [] asByteArray() {
+ ByteBuffer bb = ByteBuffer.allocate(2);
+ bb.putShort(val);
+ return bb.array();
+ }
+
+ @Override
+ public float asFloat4() {
+ return val;
+ }
+
+ @Override
+ public double asFloat8() {
+ return val;
+ }
+
+ @Override
+ public String asChars() {
+ return ""+val;
+ }
+
+ @Override
+ public String toJSON() {
+ return GsonCreator.getInstance().toJson(this, Datum.class);
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ @Override
+ public int hashCode() {
+ return val;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Int2Datum) {
+ Int2Datum other = (Int2Datum) obj;
+ return val == other.val;
+ }
+
+ return false;
+ }
+
+ @Override
+ public BooleanDatum equalsTo(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createBool(val == datum.asInt2());
+ case INT4:
+ return DatumFactory.createBool(val == datum.asInt4());
+ case INT8:
+ return DatumFactory.createBool(val == datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createBool(val == datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createBool(val == datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public int compareTo(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ if (val < datum.asInt2()) {
+ return -1;
+ } else if (datum.asInt2() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ case INT4:
+ if (val < datum.asInt4()) {
+ return -1;
+ } else if (datum.asInt4() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ case INT8:
+ if (val < datum.asInt8()) {
+ return -1;
+ } else if (datum.asInt8() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ case FLOAT4:
+ if (val < datum.asFloat4()) {
+ return -1;
+ } else if (datum.asFloat4() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ case FLOAT8:
+ if (val < datum.asFloat8()) {
+ return -1;
+ } else if (datum.asFloat8() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum plus(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createInt2((short) (val + datum.asInt2()));
+ case INT4:
+ return DatumFactory.createInt4(val + datum.asInt4());
+ case INT8:
+ return DatumFactory.createInt8(val + datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat4(val + datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val + datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum minus(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createInt2((short) (val - datum.asInt2()));
+ case INT4:
+ return DatumFactory.createInt4(val - datum.asInt4());
+ case INT8:
+ return DatumFactory.createInt8(val - datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat4(val - datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val - datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum multiply(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createInt4(val * datum.asInt2());
+ case INT4:
+ return DatumFactory.createInt4(val * datum.asInt4());
+ case INT8:
+ return DatumFactory.createInt8(val * datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat4(val * datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val * datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum divide(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createInt2((short) (val / datum.asInt2()));
+ case INT4:
+ return DatumFactory.createInt4(val / datum.asInt4());
+ case INT8:
+ return DatumFactory.createInt8(val / datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat4(val / datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val / datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum modular(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createInt2((short) (val % datum.asInt2()));
+ case INT4:
+ return DatumFactory.createInt4(val % datum.asInt4());
+ case INT8:
+ return DatumFactory.createInt8(val % datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat4(val % datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val % datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public void inverseSign() {
+ this.val = (short) -val;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/datum/Int4Datum.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/Int4Datum.java b/tajo-common/src/main/java/org/apache/tajo/datum/Int4Datum.java
new file mode 100644
index 0000000..38f3588
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/Int4Datum.java
@@ -0,0 +1,274 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.datum;
+
+import com.google.gson.annotations.Expose;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.datum.exception.InvalidCastException;
+import org.apache.tajo.datum.exception.InvalidOperationException;
+import org.apache.tajo.datum.json.GsonCreator;
+
+import java.nio.ByteBuffer;
+
+public class Int4Datum extends NumericDatum {
+ private static final int size = 4;
+ @Expose private int val;
+
+ public Int4Datum() {
+ super(Type.INT4);
+ }
+
+ public Int4Datum(int val) {
+ this();
+ this.val = val;
+ }
+
+ public Int4Datum(byte[] bytes) {
+ this();
+ ByteBuffer bb = ByteBuffer.wrap(bytes);
+ this.val = bb.getInt();
+ }
+
+ @Override
+ public short asInt2() {
+ return (short) val;
+ }
+
+ @Override
+ public int asInt4() {
+ return val;
+ }
+
+ @Override
+ public long asInt8() {
+ return val;
+ }
+
+ @Override
+ public byte asByte() {
+ throw new InvalidCastException();
+ }
+
+ @Override
+ public byte[] asByteArray() {
+ ByteBuffer bb = ByteBuffer.allocate(4);
+ bb.putInt(val);
+ return bb.array();
+ }
+
+ @Override
+ public float asFloat4() {
+ return val;
+ }
+
+ @Override
+ public double asFloat8() {
+ return val;
+ }
+
+ @Override
+ public String asChars() {
+ return ""+val;
+ }
+
+ @Override
+ public String toJSON() {
+ return GsonCreator.getInstance().toJson(this, Datum.class);
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ @Override
+ public int hashCode() {
+ return val;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj instanceof Int4Datum) {
+ Int4Datum other = (Int4Datum) obj;
+ return val == other.val;
+ }
+
+ return false;
+ }
+
+ @Override
+ public BooleanDatum equalsTo(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createBool(val == datum.asInt2());
+ case INT4:
+ return DatumFactory.createBool(val == datum.asInt4());
+ case INT8:
+ return DatumFactory.createBool(val == datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createBool(val == datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createBool(val == datum.asFloat8());
+ default:
+ throw new InvalidOperationException();
+ }
+ }
+
+ @Override
+ public int compareTo(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ if (val < datum.asInt2()) {
+ return -1;
+ } else if (datum.asInt2() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ case INT4:
+ if (val < datum.asInt4()) {
+ return -1;
+ } else if (datum.asInt4() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ case INT8:
+ if (val < datum.asInt8()) {
+ return -1;
+ } else if (datum.asInt8() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ case FLOAT4:
+ if (val < datum.asFloat4()) {
+ return -1;
+ } else if (datum.asFloat4() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ case FLOAT8:
+ if (val < datum.asFloat8()) {
+ return -1;
+ } else if (datum.asFloat8() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum plus(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createInt4(val + datum.asInt2());
+ case INT4:
+ return DatumFactory.createInt4(val + datum.asInt4());
+ case INT8:
+ return DatumFactory.createInt8(val + datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat4(val + datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val + datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum minus(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createInt4(val - datum.asInt2());
+ case INT4:
+ return DatumFactory.createInt4(val - datum.asInt4());
+ case INT8:
+ return DatumFactory.createInt8(val - datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat4(val - datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val - datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum multiply(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createInt4(val * datum.asInt2());
+ case INT4:
+ return DatumFactory.createInt4(val * datum.asInt4());
+ case INT8:
+ return DatumFactory.createInt8(val * datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat4(val * datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val * datum.asFloat8());
+ default:
+ throw new InvalidOperationException();
+ }
+ }
+
+ @Override
+ public Datum divide(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createInt4(val / datum.asInt2());
+ case INT4:
+ return DatumFactory.createInt4(val / datum.asInt4());
+ case INT8:
+ return DatumFactory.createInt8(val / datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat4(val / datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val / datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum modular(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createInt4(val % datum.asInt2());
+ case INT4:
+ return DatumFactory.createInt4(val % datum.asInt4());
+ case INT8:
+ return DatumFactory.createInt8(val % datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat4(val % datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val % datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public void inverseSign() {
+ this.val = - val;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/datum/Int8Datum.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/Int8Datum.java b/tajo-common/src/main/java/org/apache/tajo/datum/Int8Datum.java
new file mode 100644
index 0000000..fc02b16
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/Int8Datum.java
@@ -0,0 +1,280 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.datum;
+
+import com.google.gson.annotations.Expose;
+import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.datum.exception.InvalidCastException;
+import org.apache.tajo.datum.exception.InvalidOperationException;
+import org.apache.tajo.datum.json.GsonCreator;
+
+import java.nio.ByteBuffer;
+
+public class Int8Datum extends NumericDatum {
+ private static final int size = 8;
+ @Expose private long val;
+
+ public Int8Datum() {
+ super(TajoDataTypes.Type.INT8);
+ }
+
+ public Int8Datum(long val) {
+ this();
+ this.val = val;
+ }
+
+ public Int8Datum(byte[] bytes) {
+ this();
+ ByteBuffer bb = ByteBuffer.wrap(bytes);
+ val = bb.getLong();
+ }
+
+ @Override
+ public boolean asBool() {
+ throw new InvalidCastException();
+ }
+
+ @Override
+ public short asInt2() {
+ return (short) val;
+ }
+
+ @Override
+ public int asInt4() {
+ return (int) val;
+ }
+
+ @Override
+ public long asInt8() {
+ return val;
+ }
+
+ @Override
+ public byte asByte() {
+ throw new InvalidCastException();
+ }
+
+ @Override
+ public byte[] asByteArray() {
+ ByteBuffer bb = ByteBuffer.allocate(8);
+ bb.putLong(val);
+ return bb.array();
+ }
+
+ @Override
+ public float asFloat4() {
+ return val;
+ }
+
+ @Override
+ public double asFloat8() {
+ return val;
+ }
+
+ @Override
+ public String asChars() {
+ return ""+val;
+ }
+
+ @Override
+ public String toJSON() {
+ return GsonCreator.getInstance().toJson(this, Datum.class);
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ @Override
+ public int hashCode() {
+ return (int) val;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Int8Datum) {
+ Int8Datum other = (Int8Datum) obj;
+ return val == other.val;
+ }
+
+ return false;
+ }
+
+ @Override
+ public BooleanDatum equalsTo(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createBool(val == datum.asInt2());
+ case INT4:
+ return DatumFactory.createBool(val == datum.asInt4());
+ case INT8:
+ return DatumFactory.createBool(val == datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createBool(val == datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createBool(val == datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public int compareTo(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ if (val < datum.asInt2()) {
+ return -1;
+ } else if (datum.asInt2() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ case INT4:
+ if (val < datum.asInt4()) {
+ return -1;
+ } else if (datum.asInt4() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ case INT8:
+ if (val < datum.asInt8()) {
+ return -1;
+ } else if (datum.asInt8() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ case FLOAT4:
+ if (val < datum.asFloat4()) {
+ return -1;
+ } else if (datum.asFloat4() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ case FLOAT8:
+ if (val < datum.asFloat8()) {
+ return -1;
+ } else if (datum.asFloat8() < val) {
+ return 1;
+ } else {
+ return 0;
+ }
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum plus(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createInt8(val + datum.asInt2());
+ case INT4:
+ return DatumFactory.createInt8(val + datum.asInt4());
+ case INT8:
+ return DatumFactory.createInt8(val + datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat8(val + datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val + datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum minus(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createInt8(val - datum.asInt2());
+ case INT4:
+ return DatumFactory.createInt8(val - datum.asInt4());
+ case INT8:
+ return DatumFactory.createInt8(val - datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat8(val - datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val - datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum multiply(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createInt8(val * datum.asInt2());
+ case INT4:
+ return DatumFactory.createInt8(val * datum.asInt4());
+ case INT8:
+ return DatumFactory.createInt8(val * datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat8(val * datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val * datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum divide(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createInt8(val / datum.asInt2());
+ case INT4:
+ return DatumFactory.createInt8(val / datum.asInt4());
+ case INT8:
+ return DatumFactory.createInt8(val / datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat8(val / datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val / datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public Datum modular(Datum datum) {
+ switch (datum.type()) {
+ case INT2:
+ return DatumFactory.createInt8(val % datum.asInt2());
+ case INT4:
+ return DatumFactory.createInt8(val % datum.asInt4());
+ case INT8:
+ return DatumFactory.createInt8(val % datum.asInt8());
+ case FLOAT4:
+ return DatumFactory.createFloat8(val % datum.asFloat4());
+ case FLOAT8:
+ return DatumFactory.createFloat8(val % datum.asFloat8());
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public void inverseSign() {
+ this.val = -val;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/datum/NullDatum.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/NullDatum.java b/tajo-common/src/main/java/org/apache/tajo/datum/NullDatum.java
new file mode 100644
index 0000000..222a81e
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/NullDatum.java
@@ -0,0 +1,109 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.datum;
+
+import org.apache.tajo.util.Bytes;
+
+import static org.apache.tajo.common.TajoDataTypes.Type;
+
+public class NullDatum extends Datum {
+ private static final NullDatum instance;
+
+ static {
+ instance = new NullDatum();
+ }
+
+ private NullDatum() {
+ super(Type.ANY);
+ }
+
+ public static NullDatum get() {
+ return instance;
+ }
+
+ @Override
+ public boolean asBool() {
+ return false;
+ }
+
+ @Override
+ public byte asByte() {
+ return 0;
+ }
+
+ @Override
+ public short asInt2() {
+ return Short.MIN_VALUE;
+ }
+
+ @Override
+ public int asInt4() {
+ return Integer.MIN_VALUE;
+ }
+
+ @Override
+ public long asInt8() {
+ return Long.MIN_VALUE;
+ }
+
+ @Override
+ public byte[] asByteArray() {
+ return Bytes.toBytes("NULL");
+ }
+
+ @Override
+ public float asFloat4() {
+ return Float.NaN;
+ }
+
+ @Override
+ public double asFloat8() {
+ return Double.NaN;
+ }
+
+ @Override
+ public String asChars() {
+ return "NULL";
+ }
+
+ @Override
+ public int size() {
+ return 0;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return obj instanceof NullDatum;
+ }
+
+ @Override
+ public int compareTo(Datum datum) {
+ return 0;
+ }
+
+ @Override
+ public int hashCode() {
+ return 23244; // one of the prime number
+ }
+
+ @Override
+ public String toJSON() {
+ return "";
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/datum/NumericDatum.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/NumericDatum.java b/tajo-common/src/main/java/org/apache/tajo/datum/NumericDatum.java
new file mode 100644
index 0000000..e4422c2
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/NumericDatum.java
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.datum;
+
+
+import org.apache.tajo.common.TajoDataTypes;
+
+public abstract class NumericDatum extends Datum {
+
+ public NumericDatum(TajoDataTypes.Type type) {
+ super(type);
+ }
+
+ public abstract Datum plus(Datum datum);
+
+ public abstract Datum minus(Datum datum);
+
+ public abstract Datum multiply(Datum datum);
+
+ public abstract Datum divide(Datum datum);
+
+ public abstract void inverseSign();
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/datum/TextDatum.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/TextDatum.java b/tajo-common/src/main/java/org/apache/tajo/datum/TextDatum.java
new file mode 100644
index 0000000..8612a35
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/TextDatum.java
@@ -0,0 +1,146 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.datum;
+
+import com.google.gson.annotations.Expose;
+import org.apache.hadoop.io.WritableComparator;
+import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.datum.exception.InvalidCastException;
+import org.apache.tajo.datum.exception.InvalidOperationException;
+import org.apache.tajo.datum.json.GsonCreator;
+
+import java.util.Arrays;
+
+public class TextDatum extends Datum {
+ @Expose
+ private int size;
+ @Expose
+ private byte[] bytes;
+
+ public TextDatum() {
+ super(TajoDataTypes.Type.TEXT);
+ }
+
+ public TextDatum(byte[] bytes) {
+ this();
+ this.bytes = bytes;
+ this.size = bytes.length;
+ }
+
+ public TextDatum(String string) {
+ this(string.getBytes());
+ }
+
+ @Override
+ public boolean asBool() {
+ throw new InvalidCastException();
+ }
+
+ @Override
+ public byte asByte() {
+ throw new InvalidCastException();
+ }
+
+ @Override
+ public short asInt2() {
+ return Short.valueOf(new String(bytes));
+ }
+
+ @Override
+ public int asInt4() {
+ return Integer.valueOf(new String(bytes));
+ }
+
+ @Override
+ public long asInt8() {
+ return Long.valueOf(new String(bytes));
+ }
+
+ @Override
+ public float asFloat4() {
+ return Float.valueOf(new String(bytes));
+ }
+
+ @Override
+ public double asFloat8() {
+ return Double.valueOf(new String(bytes));
+ }
+
+ @Override
+ public byte[] asByteArray() {
+ return this.bytes;
+ }
+
+ public String asChars() {
+ return new String(this.bytes);
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ @Override
+ public int compareTo(Datum datum) {
+ switch (datum.type()) {
+ case TEXT:
+ byte[] o = datum.asByteArray();
+ return WritableComparator.compareBytes(this.bytes, 0, this.bytes.length,
+ o, 0, o.length);
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof TextDatum) {
+ TextDatum o = (TextDatum) obj;
+ return Arrays.equals(this.bytes, o.bytes);
+ }
+
+ return false;
+ }
+
+ @Override
+ public BooleanDatum equalsTo(Datum datum) {
+ switch (datum.type()) {
+ case TEXT:
+ return DatumFactory.createBool(
+ Arrays.equals(this.bytes, datum.asByteArray()));
+ default:
+ throw new InvalidOperationException(datum.type());
+ }
+ }
+
+ @Override
+ public String toJSON() {
+ return GsonCreator.getInstance().toJson(this, Datum.class);
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(bytes);
+ }
+
+ @Override
+ public String toString() {
+ return asChars();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/datum/exception/InvalidCastException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/exception/InvalidCastException.java b/tajo-common/src/main/java/org/apache/tajo/datum/exception/InvalidCastException.java
new file mode 100644
index 0000000..445c9e2
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/exception/InvalidCastException.java
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.datum.exception;
+
+public class InvalidCastException extends RuntimeException {
+ private static final long serialVersionUID = -7689027447969916148L;
+
+ public InvalidCastException() {
+ }
+
+ /**
+ * @param message
+ */
+ public InvalidCastException(String message) {
+ super(message);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/datum/exception/InvalidOperationException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/exception/InvalidOperationException.java b/tajo-common/src/main/java/org/apache/tajo/datum/exception/InvalidOperationException.java
new file mode 100644
index 0000000..4610a38
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/exception/InvalidOperationException.java
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.datum.exception;
+
+import static org.apache.tajo.common.TajoDataTypes.Type;
+
+public class InvalidOperationException extends RuntimeException {
+ private static final long serialVersionUID = -7689027447969916148L;
+
+ /**
+ *
+ */
+ public InvalidOperationException() {
+ }
+
+ /**
+ * @param message
+ */
+ public InvalidOperationException(String message) {
+ super(message);
+ }
+
+ public InvalidOperationException(Type type) {
+ super("Cannot compare to " + type + " type datum");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/datum/json/DatumAdapter.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/json/DatumAdapter.java b/tajo-common/src/main/java/org/apache/tajo/datum/json/DatumAdapter.java
new file mode 100644
index 0000000..dfe0e21
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/json/DatumAdapter.java
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.datum.json;
+
+import com.google.gson.*;
+import org.apache.tajo.datum.Datum;
+
+import java.lang.reflect.Type;
+
+public class DatumAdapter implements JsonSerializer<Datum>, JsonDeserializer<Datum> {
+
+ @Override
+ public Datum deserialize(JsonElement json, Type typeOfT,
+ JsonDeserializationContext context) throws JsonParseException {
+ JsonObject jsonObject = json.getAsJsonObject();
+ String className = jsonObject.get("classname").getAsJsonPrimitive().getAsString();
+
+ Class clazz;
+ try {
+ clazz = Class.forName(className);
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ throw new JsonParseException(e);
+ }
+ return context.deserialize(jsonObject.get("property"), clazz);
+ }
+
+ @Override
+ public JsonElement serialize(Datum src, Type typeOfSrc,
+ JsonSerializationContext context) {
+ JsonObject jsonObj = new JsonObject();
+ String className = src.getClass().getCanonicalName();
+ jsonObj.addProperty("classname", className);
+ JsonElement jsonElem = context.serialize(src);
+ jsonObj.add("property", jsonElem);
+ return jsonObj;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/datum/json/GsonCreator.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/json/GsonCreator.java b/tajo-common/src/main/java/org/apache/tajo/datum/json/GsonCreator.java
new file mode 100644
index 0000000..d1a9bf2
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/json/GsonCreator.java
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.datum.json;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import org.apache.tajo.datum.Datum;
+
+public class GsonCreator {
+
+ private static GsonBuilder builder;
+ private static Gson gson;
+
+ private static void init() {
+ if (builder == null) {
+ builder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
+ builder.registerTypeAdapter(Datum.class, new DatumAdapter());
+ }
+ if (gson == null ) {
+ gson = builder.create();
+ }
+ }
+
+ public static Gson getInstance() {
+ init();
+ return gson;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/exception/InternalException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/InternalException.java b/tajo-common/src/main/java/org/apache/tajo/exception/InternalException.java
new file mode 100644
index 0000000..af4ee5c
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/InternalException.java
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ *
+ */
+package org.apache.tajo.exception;
+
+import java.io.IOException;
+
+public class InternalException extends IOException {
+ private static final long serialVersionUID = -262149616685882358L;
+
+ public InternalException() {
+ }
+
+ public InternalException(String message) {
+ super(message);
+ }
+
+ public InternalException(String message, Exception t) {
+ super(message, t);
+ }
+
+ public InternalException(Throwable t) {
+ super(t);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/exception/UnimplementedException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/UnimplementedException.java b/tajo-common/src/main/java/org/apache/tajo/exception/UnimplementedException.java
new file mode 100644
index 0000000..3e4555d
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/UnimplementedException.java
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.exception;
+
+public class UnimplementedException extends RuntimeException {
+ private static final long serialVersionUID = -5467580471721530536L;
+
+ public UnimplementedException() {
+ }
+
+ public UnimplementedException(String message) {
+ super(message);
+ }
+
+ public UnimplementedException(Throwable cause) {
+ super(cause);
+ }
+
+ public UnimplementedException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/exception/UnsupportedException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/UnsupportedException.java b/tajo-common/src/main/java/org/apache/tajo/exception/UnsupportedException.java
new file mode 100644
index 0000000..1e19622
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/UnsupportedException.java
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.exception;
+
+public class UnsupportedException extends RuntimeException {
+ private static final long serialVersionUID = 6702291354858193578L;
+
+ public UnsupportedException() {
+ }
+
+ public UnsupportedException(String message) {
+ super(message);
+ }
+
+ public UnsupportedException(Throwable cause) {
+ super(cause);
+ }
+
+ public UnsupportedException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/gson/ClassNameDeserializer.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/gson/ClassNameDeserializer.java b/tajo-common/src/main/java/org/apache/tajo/gson/ClassNameDeserializer.java
new file mode 100644
index 0000000..43a378e
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/gson/ClassNameDeserializer.java
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ *
+ */
+package org.apache.tajo.gson;
+
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParseException;
+
+import java.lang.reflect.Type;
+
+public class ClassNameDeserializer implements JsonDeserializer<Class> {
+
+ @Override
+ public Class deserialize(JsonElement json, Type type,
+ JsonDeserializationContext ctx) throws JsonParseException {
+ try {
+ return Class.forName(json.getAsString());
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/gson/ClassNameSerializer.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/gson/ClassNameSerializer.java b/tajo-common/src/main/java/org/apache/tajo/gson/ClassNameSerializer.java
new file mode 100644
index 0000000..7cc9245
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/gson/ClassNameSerializer.java
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ *
+ */
+package org.apache.tajo.gson;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+
+import java.lang.reflect.Type;
+
+public class ClassNameSerializer implements JsonSerializer<Class> {
+
+ @Override
+ public JsonElement serialize(Class clazz, Type type,
+ JsonSerializationContext ctx) {
+ return new JsonPrimitive(clazz.getName());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/gson/DataTypeAdapter.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/gson/DataTypeAdapter.java b/tajo-common/src/main/java/org/apache/tajo/gson/DataTypeAdapter.java
new file mode 100644
index 0000000..9fc0586
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/gson/DataTypeAdapter.java
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.gson;
+
+import com.google.gson.*;
+import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+
+import java.lang.reflect.Type;
+
+
+public class DataTypeAdapter implements JsonSerializer<DataType>, JsonDeserializer<DataType> {
+
+ @Override
+ public DataType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
+ throws JsonParseException {
+
+
+ JsonObject obj = (JsonObject) json;
+ DataType.Builder builder = DataType.newBuilder();
+ TajoDataTypes.Type type = Enum.valueOf(TajoDataTypes.Type.class, obj.get("type").getAsString());
+ builder.setType(type);
+
+ JsonElement len = obj.get("len");
+ if (len != null) {
+ builder.setLength(len.getAsInt());
+ }
+ JsonElement code = obj.get("code");
+ if (code != null) {
+ builder.setCode(code.getAsString());
+ }
+ return builder.build();
+ }
+
+ @Override
+ public JsonElement serialize(DataType src, Type typeOfSrc, JsonSerializationContext context) {
+ JsonObject json = new JsonObject();
+ json.addProperty("type", src.getType().name());
+ if (src.hasLength()) {
+ json.addProperty("len", src.getLength());
+ }
+ if (src.hasCode()) {
+ json.addProperty("code", src.getCode());
+ }
+
+ return json;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/gson/DatumTypeAdapter.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/gson/DatumTypeAdapter.java b/tajo-common/src/main/java/org/apache/tajo/gson/DatumTypeAdapter.java
new file mode 100644
index 0000000..b457fc1
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/gson/DatumTypeAdapter.java
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.gson;
+
+import com.google.gson.*;
+import org.apache.tajo.datum.Datum;
+
+import java.lang.reflect.Type;
+
+public class DatumTypeAdapter implements JsonSerializer<Datum>, JsonDeserializer<Datum> {
+
+ @Override
+ public Datum deserialize(JsonElement json, Type typeOfT,
+ JsonDeserializationContext context) throws JsonParseException {
+ JsonObject jsonObject = json.getAsJsonObject();
+ String className = jsonObject.get("classname").getAsJsonPrimitive().getAsString();
+
+ Class clazz;
+ try {
+ clazz = Class.forName(className);
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ throw new JsonParseException(e);
+ }
+ return context.deserialize(jsonObject.get("property"), clazz);
+ }
+
+ @Override
+ public JsonElement serialize(Datum src, Type typeOfSrc,
+ JsonSerializationContext context) {
+ JsonObject jsonObj = new JsonObject();
+ String className = src.getClass().getCanonicalName();
+ jsonObj.addProperty("classname", className);
+ JsonElement jsonElem = context.serialize(src);
+ jsonObj.add("property", jsonElem);
+ return jsonObj;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/gson/PathDeserializer.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/gson/PathDeserializer.java b/tajo-common/src/main/java/org/apache/tajo/gson/PathDeserializer.java
new file mode 100644
index 0000000..ae3eb81
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/gson/PathDeserializer.java
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ *
+ */
+package org.apache.tajo.gson;
+
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParseException;
+import org.apache.hadoop.fs.Path;
+
+import java.lang.reflect.Type;
+
+public class PathDeserializer implements JsonDeserializer<Path> {
+
+ @Override
+ public Path deserialize(JsonElement arg0, Type arg1,
+ JsonDeserializationContext arg2) throws JsonParseException {
+ return new Path(arg0.getAsJsonPrimitive().getAsString());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/gson/PathSerializer.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/gson/PathSerializer.java b/tajo-common/src/main/java/org/apache/tajo/gson/PathSerializer.java
new file mode 100644
index 0000000..6564d7d
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/gson/PathSerializer.java
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ *
+ */
+package org.apache.tajo.gson;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+import org.apache.hadoop.fs.Path;
+
+import java.lang.reflect.Type;
+
+public class PathSerializer implements JsonSerializer<Path> {
+
+ @Override
+ public JsonElement serialize(Path arg0, Type arg1,
+ JsonSerializationContext arg2) {
+ return new JsonPrimitive(arg0.toString());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/storage/Tuple.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/storage/Tuple.java b/tajo-common/src/main/java/org/apache/tajo/storage/Tuple.java
new file mode 100644
index 0000000..e56a7a4
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/storage/Tuple.java
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.storage;
+
+import org.apache.tajo.datum.*;
+
+import java.net.InetAddress;
+
+public interface Tuple {
+
+ public int size();
+
+ public boolean contains(int fieldid);
+
+ public boolean isNull(int fieldid);
+
+ public void clear();
+
+ public void put(int fieldId, Datum value);
+
+ public void put(int fieldId, Datum [] values);
+
+ public void put(int fieldId, Tuple tuple);
+
+ public void put(Datum [] values);
+
+ public Datum get(int fieldId);
+
+ public void setOffset(long offset);
+
+ public long getOffset();
+
+ public BooleanDatum getBoolean(int fieldId);
+
+ public BitDatum getByte(int fieldId);
+
+ public CharDatum getChar(int fieldId);
+
+ public BlobDatum getBytes(int fieldId);
+
+ public Int2Datum getShort(int fieldId);
+
+ public Int4Datum getInt(int fieldId);
+
+ public Int8Datum getLong(int fieldId);
+
+ public Float4Datum getFloat(int fieldId);
+
+ public Float8Datum getDouble(int fieldId);
+
+ public Inet4Datum getIPv4(int fieldId);
+
+ public byte [] getIPv4Bytes(int fieldId);
+
+ public InetAddress getIPv6(int fieldId);
+
+ public byte [] getIPv6Bytes(int fieldId);
+
+ public TextDatum getString(int fieldId);
+
+ public TextDatum getText(int fieldId);
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/unit/StorageUnit.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/unit/StorageUnit.java b/tajo-common/src/main/java/org/apache/tajo/unit/StorageUnit.java
new file mode 100644
index 0000000..8cde659
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/unit/StorageUnit.java
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.unit;
+
+public class StorageUnit {
+
+ public static final int B = 8;
+ public static final int KB = B * 1024;
+ public static final int MB = KB * 1024;
+ public static final int GB = MB * 1024;
+ public static final int TB = GB * 1024;
+ public static final int PB = TB * 1024;
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/bc6359b8/tajo-common/src/main/java/org/apache/tajo/unit/TimeUnit.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/unit/TimeUnit.java b/tajo-common/src/main/java/org/apache/tajo/unit/TimeUnit.java
new file mode 100644
index 0000000..8062f2d
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/unit/TimeUnit.java
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.unit;
+
+public class TimeUnit {
+
+ public static final int SEC = 1000;
+ public static final int MIN = SEC * 60;
+ public static final int HOUR = MIN * 60;
+ public static final int DAY = HOUR * 24;
+
+ public static final int PART_UNIT = 5*TimeUnit.MIN;
+}