tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject [08/57] [abbrv] [partial] TAJO-752: Escalate sub modules in tajo-core into the top-level modules. (hyunsik)
Date Fri, 18 Apr 2014 11:44:11 GMT
http://git-wip-us.apache.org/repos/asf/tajo/blob/6594ac1c/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java
new file mode 100644
index 0000000..22a178f
--- /dev/null
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLExpression.java
@@ -0,0 +1,206 @@
+/**
+ * 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.engine.eval;
+
+import org.apache.tajo.catalog.Schema;
+import org.apache.tajo.catalog.exception.NoSuchFunctionException;
+import org.apache.tajo.datum.TimestampDatum;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.apache.tajo.common.TajoDataTypes.Type.TEXT;
+
+public class TestSQLExpression extends ExprTestBase {
+
+  @Test
+  public void testQuotedIdentifiers() throws IOException {
+    Schema schema = new Schema();
+    schema.addColumn("컬럼1", TEXT);
+    schema.addColumn("컬럼2", TEXT);
+    testEval(schema, "테이블1", "123,234", "select \"컬럼1\"::float, cast (\"컬럼2\" as float4) as a from \"테이블1\"",
+        new String[]{"123.0", "234.0"});
+    testEval(schema,
+        "테이블1", "123,234", "select char_length(\"컬럼1\"), \"컬럼2\"::float4 as \"별명1\" from \"테이블1\"",
+        new String[]{"3", "234.0"});
+  }
+
+  @Test(expected = NoSuchFunctionException.class)
+  public void testNoSuchFunction() throws IOException {
+    testSimpleEval("select test123('abc') col1 ", new String[]{"abc"});
+  }
+
+  @Test
+  public void testCast() throws IOException {
+    testSimpleEval("select cast (1 as char)", new String[] {"1"});
+    testSimpleEval("select cast (119 as char)", new String[] {"1"});
+
+    testSimpleEval("select cast (1 as int2)", new String[ ]{"1"});
+    testSimpleEval("select cast (1 as int4)", new String[] {"1"});
+    testSimpleEval("select cast (1 as int8)", new String[] {"1"});
+    testSimpleEval("select cast (1 as float)", new String[] {"1.0"});
+    testSimpleEval("select cast (1 as double)", new String[] {"1.0"});
+    testSimpleEval("select cast (1 as text)", new String[] {"1"});
+
+    testSimpleEval("select cast ('123' as int2)", new String[] {"123"});
+    testSimpleEval("select cast ('123' as int4)", new String[] {"123"});
+    testSimpleEval("select cast ('123' as int8)", new String[] {"123"});
+    testSimpleEval("select cast ('123' as float)", new String[] {"123.0"});
+    testSimpleEval("select cast ('123' as double)", new String[] {"123.0"});
+    testSimpleEval("select cast ('123' as text)", new String[] {"123"});
+
+    testSimpleEval("select 123::int2", new String[] {"123"});
+    testSimpleEval("select 123::int4", new String[] {"123"});
+    testSimpleEval("select 123::int8", new String[] {"123"});
+    testSimpleEval("select 123::float", new String[] {"123.0"});
+    testSimpleEval("select 123::double", new String[] {"123.0"});
+    testSimpleEval("select 123::text", new String[] {"123"});
+
+    testSimpleEval("select 123.0::float", new String[] {"123.0"});
+    testSimpleEval("select 123.0::double", new String[] {"123.0"});
+
+    testSimpleEval("select '123'::int", new String[] {"123"});
+    testSimpleEval("select '123'::double", new String[] {"123.0"});
+  }
+
+  @Test
+  public void testCastWithNestedFunction() throws IOException {
+    int timestamp = (int) (System.currentTimeMillis() / 1000);
+    TimestampDatum expected = new TimestampDatum(timestamp);
+    testSimpleEval(String.format("select to_timestamp(CAST(split_part('%d.999', '.', 1) as INT8));", timestamp),
+        new String[] {expected.asChars()});
+  }
+
+  @Test
+  public void testCastFromTable() throws IOException {
+    Schema schema = new Schema();
+    schema.addColumn("col1", TEXT);
+    schema.addColumn("col2", TEXT);
+    testEval(schema, "table1", "123,234", "select cast(col1 as float) as b, cast(col2 as float) as a from table1",
+        new String[]{"123.0", "234.0"});
+    testEval(schema, "table1", "123,234", "select col1::float, col2::float from table1",
+        new String[]{"123.0", "234.0"});
+    testEval(schema, "table1", "1980-04-01 01:50:01,234", "select col1::timestamp as t1, col2::float from table1 " +
+        "where t1 = '1980-04-01 01:50:01'::timestamp",
+        new String[]{"1980-04-01 01:50:01", "234.0"});
+
+    testSimpleEval("select '1980-04-01 01:50:01'::timestamp;", new String [] {"1980-04-01 01:50:01"});
+    testSimpleEval("select '1980-04-01 01:50:01'::timestamp::text", new String [] {"1980-04-01 01:50:01"});
+
+    testSimpleEval("select (cast ('99999'::int8 as text))::int4 + 1", new String [] {"100000"});
+  }
+
+  @Test
+  public void testBooleanLiteral() throws IOException {
+    testSimpleEval("select true", new String[] {"t"});
+    testSimpleEval("select false", new String[]{"f"});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", TEXT);
+    schema.addColumn("col2", TEXT);
+    testEval(schema, "table1", "123,234", "select col1, col2 from table1 where true", new String[]{"123", "234"});
+  }
+
+  @Test
+  public void testNullComparisons() throws IOException {
+    testSimpleEval("select null is null", new String[] {"t"});
+    testSimpleEval("select null is not null", new String[] {"f"});
+
+    testSimpleEval("select (1::int2 > null) is null", new String[] {"t"});
+    testSimpleEval("select (1::int2 < null) is null", new String[] {"t"});
+    testSimpleEval("select (1::int2 >= null) is null", new String[] {"t"});
+    testSimpleEval("select (1::int2 <= null) is null", new String[] {"t"});
+    testSimpleEval("select (1::int2 <> null) is null", new String[] {"t"});
+
+    testSimpleEval("select (1::int4 > null) is null", new String[] {"t"});
+    testSimpleEval("select (1::int4 < null) is null", new String[] {"t"});
+    testSimpleEval("select (1::int4 >= null) is null", new String[] {"t"});
+    testSimpleEval("select (1::int4 <= null) is null", new String[] {"t"});
+    testSimpleEval("select (1::int4 <> null) is null", new String[] {"t"});
+
+    testSimpleEval("select (1::int8 > null) is null", new String[] {"t"});
+    testSimpleEval("select (1::int8 < null) is null", new String[] {"t"});
+    testSimpleEval("select (1::int8 >= null) is null", new String[] {"t"});
+    testSimpleEval("select (1::int8 <= null) is null", new String[] {"t"});
+    testSimpleEval("select (1::int8 <> null) is null", new String[] {"t"});
+
+    testSimpleEval("select (1::float > null) is null", new String[] {"t"});
+    testSimpleEval("select (1::float < null) is null", new String[] {"t"});
+    testSimpleEval("select (1::float >= null) is null", new String[] {"t"});
+    testSimpleEval("select (1::float <= null) is null", new String[] {"t"});
+    testSimpleEval("select (1::float <> null) is null", new String[] {"t"});
+
+    testSimpleEval("select (1::float8 > null) is null", new String[] {"t"});
+    testSimpleEval("select (1::float8 < null) is null", new String[] {"t"});
+    testSimpleEval("select (1::float8 >= null) is null", new String[] {"t"});
+    testSimpleEval("select (1::float8 <= null) is null", new String[] {"t"});
+    testSimpleEval("select (1::float8 <> null) is null", new String[] {"t"});
+
+    testSimpleEval("select ('abc' > null) is null", new String[] {"t"});
+    testSimpleEval("select ('abc' < null) is null", new String[] {"t"});
+    testSimpleEval("select ('abc' >= null) is null", new String[] {"t"});
+    testSimpleEval("select ('abc' <= null) is null", new String[] {"t"});
+    testSimpleEval("select ('abc' <> null) is null", new String[] {"t"});
+
+    testSimpleEval("select ('1980-04-01'::date > null) is null", new String[] {"t"});
+    testSimpleEval("select ('1980-04-01'::date < null) is null", new String[] {"t"});
+    testSimpleEval("select ('1980-04-01'::date >= null) is null", new String[] {"t"});
+    testSimpleEval("select ('1980-04-01'::date <= null) is null", new String[] {"t"});
+    testSimpleEval("select ('1980-04-01'::date <> null) is null", new String[] {"t"});
+
+    testSimpleEval("select ('09:08:50'::time > null) is null", new String[] {"t"});
+    testSimpleEval("select ('09:08:50'::time < null) is null", new String[] {"t"});
+    testSimpleEval("select ('09:08:50'::time >= null) is null", new String[] {"t"});
+    testSimpleEval("select ('09:08:50'::time <= null) is null", new String[] {"t"});
+    testSimpleEval("select ('09:08:50'::time <> null) is null", new String[] {"t"});
+
+    testSimpleEval("select ('1980-04-01 01:50:30'::timestamp > null) is null", new String[] {"t"});
+    testSimpleEval("select ('1980-04-01 01:50:30'::timestamp < null) is null", new String[] {"t"});
+    testSimpleEval("select ('1980-04-01 01:50:30'::timestamp >= null) is null", new String[] {"t"});
+    testSimpleEval("select ('1980-04-01 01:50:30'::timestamp <= null) is null", new String[] {"t"});
+    testSimpleEval("select ('1980-04-01 01:50:30'::timestamp <> null) is null", new String[] {"t"});
+
+
+    // Three Valued Logic - AND
+    testSimpleEval("select (true AND true)", new String[] {"t"}); // true - true -> true
+    testSimpleEval("select (true AND 1 > null) is null", new String[] {"t"}); // true - unknown -> unknown
+    testSimpleEval("select (true AND false)", new String[] {"f"}); // true - false -> true
+
+    testSimpleEval("select (1 > null AND true) is null", new String[] {"t"}); // unknown - true -> true
+    testSimpleEval("select (1 > null AND 1 > null) is null", new String[] {"t"}); // unknown - unknown -> unknown
+    testSimpleEval("select (1 > null AND false)", new String[] {"f"}); // unknown - false -> false
+
+    testSimpleEval("select (false AND true)", new String[] {"f"}); // false - true -> true
+    testSimpleEval("select (false AND 1 > null) is null", new String[] {"f"}); // false - unknown -> unknown
+    testSimpleEval("select (false AND false)", new String[] {"f"}); // false - false -> false
+
+    // Three Valued Logic - OR
+    testSimpleEval("select (true OR true)", new String[] {"t"}); // true - true -> true
+    testSimpleEval("select (true OR 1 > null)", new String[] {"t"}); // true - unknown -> true
+    testSimpleEval("select (true OR false)", new String[] {"t"}); // true - false -> true
+
+    testSimpleEval("select (1 > null OR true)", new String[] {"t"}); // unknown - true -> true
+    testSimpleEval("select (1 > null OR 1 > null) is null", new String[] {"t"}); // unknown - unknown -> unknown
+    testSimpleEval("select (1 > null OR false) is null", new String[] {"t"}); // unknown - false -> false
+
+    testSimpleEval("select (false OR true)", new String[] {"t"}); // false - true -> true
+    testSimpleEval("select (false OR 1 > null) is null", new String[] {"t"}); // false - unknown -> unknown
+    testSimpleEval("select (false OR false)", new String[] {"f"}); // false - false -> false
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/6594ac1c/tajo-core/src/test/java/org/apache/tajo/engine/function/TestAggFunction.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestAggFunction.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestAggFunction.java
new file mode 100644
index 0000000..f635468
--- /dev/null
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestAggFunction.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.engine.function;
+
+import org.junit.Test;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.datum.DatumFactory;
+import org.apache.tajo.engine.function.builtin.AvgLong;
+import org.apache.tajo.storage.Tuple;
+import org.apache.tajo.storage.VTuple;
+
+import static org.junit.Assert.assertTrue;
+
+public class TestAggFunction {
+
+  @Test
+  public void testAvgInt() {
+    Tuple [] tuples = new Tuple[5];
+
+    for (int i = 1; i <= 5; i++) {
+      tuples[i-1] = new VTuple(1);
+      tuples[i-1].put(0, DatumFactory.createInt4(i));
+    }
+
+    AvgLong avg = new AvgLong();
+    FunctionContext ctx = avg.newContext();
+    for (int i = 1; i <= 5; i++) {
+      avg.eval(ctx, tuples[i-1]);
+    }
+
+    assertTrue(15 / 5 == avg.terminate(ctx).asFloat8());
+
+
+    Tuple [] tuples2 = new Tuple[10];
+
+    FunctionContext ctx2 = avg.newContext();
+    for (int i = 1; i <= 10; i++) {
+      tuples2[i-1] = new VTuple(1);
+      tuples2[i-1].put(0, DatumFactory.createInt4(i));
+      avg.eval(ctx2, tuples2[i-1]);
+    }
+    assertTrue((double)55 / 10 == avg.terminate(ctx2).asFloat8());
+
+
+    avg.merge(ctx, new VTuple(new Datum[] {avg.getPartialResult(ctx2)}));
+    assertTrue((double)(15 + 55) / (5 + 10) == avg.terminate(ctx).asFloat8());
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/6594ac1c/tajo-core/src/test/java/org/apache/tajo/engine/function/TestBuiltinFunctions.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestBuiltinFunctions.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestBuiltinFunctions.java
new file mode 100644
index 0000000..65612f7
--- /dev/null
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestBuiltinFunctions.java
@@ -0,0 +1,123 @@
+/**
+ * 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.engine.function;
+
+import org.apache.tajo.IntegrationTest;
+import org.apache.tajo.QueryTestCaseBase;
+import org.apache.tajo.TajoConstants;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.sql.ResultSet;
+
+import static org.junit.Assert.assertTrue;
+
+@Category(IntegrationTest.class)
+public class TestBuiltinFunctions extends QueryTestCaseBase {
+
+  public TestBuiltinFunctions() {
+    super(TajoConstants.DEFAULT_DATABASE_NAME);
+  }
+
+  @Test
+  public void testMaxLong() throws Exception {
+    ResultSet res = executeQuery();
+    assertResultSet(res);
+    cleanupQuery(res);
+  }
+
+  @Test
+  public void testMinLong() throws Exception {
+    ResultSet res = executeQuery();
+    assertResultSet(res);
+    cleanupQuery(res);
+  }
+
+  @Test
+  public void testMaxString() throws Exception {
+    ResultSet res = executeQuery();
+    assertResultSet(res);
+    cleanupQuery(res);
+  }
+
+  @Test
+  public void testMinString() throws Exception {
+    ResultSet res = executeQuery();
+    assertResultSet(res);
+    cleanupQuery(res);
+  }
+
+  @Test
+  public void testCount() throws Exception {
+    ResultSet res = executeQuery();
+    assertResultSet(res);
+    cleanupQuery(res);
+  }
+
+  @Test
+  public void testAvgDouble() throws Exception {
+    ResultSet res = executeQuery();
+    assertResultSet(res);
+    cleanupQuery(res);
+  }
+
+  @Test
+  public void testAvgLong() throws Exception {
+    ResultSet res = executeQuery();
+    assertResultSet(res);
+    cleanupQuery(res);
+  }
+
+  @Test
+  public void testAvgInt() throws Exception {
+    ResultSet res = executeQuery();
+    assertResultSet(res);
+    cleanupQuery(res);
+  }
+
+  @Test
+  public void testRandom() throws Exception {
+    ResultSet res = executeQuery();
+    while(res.next()) {
+      assertTrue(res.getInt(2) >= 0 && res.getInt(2) < 3);
+    }
+    cleanupQuery(res);
+  }
+
+  @Test
+  public void testSplitPart() throws Exception {
+    ResultSet res = executeQuery();
+    assertResultSet(res);
+    cleanupQuery(res);
+  }
+
+  @Test
+  public void testSplitPartByString() throws Exception {
+    ResultSet res = executeQuery();
+    assertResultSet(res);
+    cleanupQuery(res);
+  }
+
+  @Test
+  public void testSplitPartNested() throws Exception {
+    ResultSet res = executeQuery();
+    assertResultSet(res);
+    cleanupQuery(res);
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/6594ac1c/tajo-core/src/test/java/org/apache/tajo/engine/function/TestConditionalExpressions.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestConditionalExpressions.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestConditionalExpressions.java
new file mode 100644
index 0000000..af86387
--- /dev/null
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestConditionalExpressions.java
@@ -0,0 +1,82 @@
+/**
+ * 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.engine.function;
+
+import org.apache.tajo.catalog.exception.NoSuchFunctionException;
+import org.apache.tajo.engine.eval.ExprTestBase;
+import org.junit.Test;
+
+import static org.junit.Assert.fail;
+
+public class TestConditionalExpressions extends ExprTestBase {
+  @Test
+  public void testCoalesceText() throws Exception {
+    testSimpleEval("select coalesce(null, 'value2');", new String[]{"value2"});
+    testSimpleEval("select coalesce(null, null, 'value3');", new String[]{"value3"});
+    testSimpleEval("select coalesce('value1', null, 'value3');", new String[]{"value1"});
+    testSimpleEval("select coalesce(null, 'value2', 'value3');", new String[]{"value2"});
+
+    //no matched function
+    try {
+      testSimpleEval("select coalesce(null, 2, 'value3');", new String[]{"2"});
+      fail("coalesce(NULL, INT, TEXT) not defined. So should throw exception.");
+    } catch (NoSuchFunctionException e) {
+      //success
+    }
+  }
+
+  @Test
+  public void testCoalesceLong() throws Exception {
+    testSimpleEval("select coalesce(null, 2);", new String[]{"2"});
+    testSimpleEval("select coalesce(null, null, 3);", new String[]{"3"});
+    testSimpleEval("select coalesce(1, null, 3);", new String[]{"1"});
+    testSimpleEval("select coalesce(null, 2, 3);", new String[]{"2"});
+
+    //no matched function
+    try {
+      testSimpleEval("select coalesce(null, 'value2', 3);", new String[]{"2"});
+      fail("coalesce(NULL, TEXT, INT) not defined. So should throw exception.");
+    } catch (NoSuchFunctionException e) {
+      //success
+    }
+  }
+
+  @Test
+  public void testCoalesceDouble() throws Exception {
+    testSimpleEval("select coalesce(null, 2.0);", new String[]{"2.0"});
+    testSimpleEval("select coalesce(null, null, 3.0);", new String[]{"3.0"});
+    testSimpleEval("select coalesce(1.0, null, 3.0);", new String[]{"1.0"});
+    testSimpleEval("select coalesce(null, 2.0, 3.0);", new String[]{"2.0"});
+
+    //no matched function
+    try {
+      testSimpleEval("select coalesce('value1', null, 3.0);", new String[]{"1.0"});
+      fail("coalesce(TEXT, NULL, FLOAT8) not defined. So should throw exception.");
+    } catch (NoSuchFunctionException e) {
+      //success
+    }
+
+    try {
+      testSimpleEval("select coalesce(null, 'value2', 3.0);", new String[]{"2.0"});
+      fail("coalesce(NULL, TEXT, FLOAT8) not defined. So should throw exception.");
+    } catch (NoSuchFunctionException e) {
+      //success
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/6594ac1c/tajo-core/src/test/java/org/apache/tajo/engine/function/TestDateTimeFunctions.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestDateTimeFunctions.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestDateTimeFunctions.java
new file mode 100644
index 0000000..ac7a2b8
--- /dev/null
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestDateTimeFunctions.java
@@ -0,0 +1,253 @@
+/**
+ * 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.engine.function;
+
+
+import org.apache.tajo.catalog.Schema;
+import org.apache.tajo.datum.TimestampDatum;
+import org.apache.tajo.engine.eval.ExprTestBase;
+import org.joda.time.DateTime;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.apache.tajo.common.TajoDataTypes.Type.*;
+
+public class TestDateTimeFunctions extends ExprTestBase {
+
+  @Test
+  public void testToTimestamp() throws IOException {
+    long expectedTimestamp = System.currentTimeMillis();
+    DateTime expectedDateTime = new DateTime(expectedTimestamp);
+
+    // (expectedTimestamp / 1000) means the translation from millis seconds to unix timestamp
+    String q1 = String.format("select to_timestamp(%d);", (expectedTimestamp / 1000));
+    testSimpleEval(q1, new String[]{expectedDateTime.toString(TimestampDatum.DEFAULT_FORMAT_STRING)});
+  }
+
+  @Test
+  public void testToChar() throws IOException {
+    long expectedTimestamp = System.currentTimeMillis();
+    DateTime expectedDateTime = new DateTime(expectedTimestamp);
+    String dateFormatStr = "yyyy-MM";
+    // (expectedTimestamp / 1000) means the translation from millis seconds to unix timestamp
+    String q = String.format("select to_char(to_timestamp(%d), 'yyyy-MM');", (expectedTimestamp / 1000));
+    testSimpleEval(q, new String[]{expectedDateTime.toString(dateFormatStr)});
+  }
+
+  @Test
+  public void testExtract() throws IOException {
+    Schema schema2 = new Schema();
+    schema2.addColumn("col1", TIMESTAMP);
+    testEval(schema2, "table1",
+        "1970-01-17 10:09:37",
+        "select extract(year from col1), extract(month from col1), extract(day from col1) from table1;",
+        new String[]{"1970.0", "1.0", "17.0"});
+
+    Schema schema3 = new Schema();
+    schema3.addColumn("col1", TIME);
+    testEval(schema3, "table1",
+        "10:09:37.5",
+        "select extract(hour from col1), extract(minute from col1), extract(second from col1) from table1;",
+        new String[]{"10.0", "9.0", "37.5"});
+
+    Schema schema4 = new Schema();
+    schema4.addColumn("col1", DATE);
+    testEval(schema4, "table1",
+        "1970-01-17",
+        "select extract(year from col1), extract(month from col1), extract(day from col1) from table1;",
+        new String[]{"1970.0", "1.0", "17.0"});
+
+    testSimpleEval("select extract(century from TIMESTAMP '1970-01-17 10:09:37');", new String[]{"19.0"});
+
+    testSimpleEval("select extract(century from DATE '1970-01-17');", new String[]{"19.0"});
+
+    testSimpleEval("select extract(decade from TIMESTAMP '1970-01-17 10:09:37');", new String[]{"197.0"});
+
+    testSimpleEval("select extract(decade from DATE '1970-01-17');", new String[]{"197.0"});
+
+    testSimpleEval("select extract(millennium from TIMESTAMP '2001-02-16 10:09:37');", new String[]{"3.0"});
+    testSimpleEval("select extract(millennium from TIMESTAMP '2000-02-16 10:09:37');", new String[]{"2.0"});
+
+    testSimpleEval("select extract(millennium from DATE '2001-02-16');", new String[]{"3.0"});
+    testSimpleEval("select extract(millennium from DATE '2000-02-16');", new String[]{"2.0"});
+
+    testSimpleEval("select extract(year from TIMESTAMP '1970-01-17 10:09:37');", new String[]{"1970.0"});
+    testSimpleEval("select extract(month from TIMESTAMP '1970-01-17 10:09:37');", new String[]{"1.0"});
+    testSimpleEval("select extract(day from TIMESTAMP '1970-01-17 10:09:37');", new String[]{"17.0"});
+
+    testSimpleEval("select extract(hour from TIMESTAMP '1970-01-17 10:09:37');", new String[]{"10.0"});
+    testSimpleEval("select extract(minute from TIMESTAMP '1970-01-17 10:09:37');", new String[]{"9.0"});
+    testSimpleEval("select extract(second from TIMESTAMP '1970-01-17 10:09:37');", new String[]{"37.0"});
+    testSimpleEval("select extract(second from TIMESTAMP '1970-01-17 10:09:37.5');", new String[]{"37.5"});
+
+    testSimpleEval("select extract(hour from TIME '10:09:37');", new String[]{"10.0"});
+    testSimpleEval("select extract(minute from TIME '10:09:37');", new String[]{"9.0"});
+    testSimpleEval("select extract(second from TIME '10:09:37');", new String[]{"37.0"});
+    testSimpleEval("select extract(second from TIME '10:09:37.5');", new String[]{"37.5"});
+
+    testSimpleEval("select extract(year from DATE '1970-01-17');", new String[]{"1970.0"});
+    testSimpleEval("select extract(month from DATE '1970-01-17');", new String[]{"1.0"});
+    testSimpleEval("select extract(day from DATE '1970-01-17');", new String[]{"17.0"});
+
+    testSimpleEval("select extract(milliseconds from TIMESTAMP '1970-01-17 10:09:37.5');", new String[]{"37500.0"});
+    testSimpleEval("select extract(milliseconds from TIME '10:09:37.123');", new String[]{"37123.0"});
+
+    testSimpleEval("select extract(microseconds from TIMESTAMP '1970-01-17 10:09:37.5');", new String[]{"3.75E7"});
+    testSimpleEval("select extract(microseconds from TIME '10:09:37.123');", new String[]{"3.7123E7"});
+
+    testSimpleEval("select extract(dow from TIMESTAMP '1970-01-17 10:09:37');", new String[]{"6.0"});
+    testSimpleEval("select extract(dow from TIMESTAMP '1970-01-18 10:09:37');", new String[]{"0.0"});
+    testSimpleEval("select extract(isodow from TIMESTAMP '1970-01-17 10:09:37');", new String[]{"6.0"});
+    testSimpleEval("select extract(isodow from TIMESTAMP '1970-01-18 10:09:37');", new String[]{"7.0"});
+
+    testSimpleEval("select extract(year from TIMESTAMP '2006-01-02 10:09:37');", new String[]{"2006.0"});
+    testSimpleEval("select extract(year from TIMESTAMP '2006-01-01 10:09:37');", new String[]{"2006.0"});
+    testSimpleEval("select extract(isoyear from TIMESTAMP '2006-01-02 10:09:37');", new String[]{"2006.0"});
+    testSimpleEval("select extract(isoyear from TIMESTAMP '2006-01-01 10:09:37');", new String[]{"2005.0"});
+
+    testSimpleEval("select extract(quarter from TIMESTAMP '2006-02-01 10:09:37');", new String[]{"1.0"});
+    testSimpleEval("select extract(quarter from TIMESTAMP '2006-04-01 10:09:37');", new String[]{"2.0"});
+    testSimpleEval("select extract(quarter from TIMESTAMP '2006-07-01 10:09:37');", new String[]{"3.0"});
+    testSimpleEval("select extract(quarter from TIMESTAMP '2006-12-01 10:09:37');", new String[]{"4.0"});
+
+    testSimpleEval("select extract(week from TIMESTAMP '1970-01-17 10:09:37');", new String[]{"3.0"});
+
+    testSimpleEval("select extract(dow from DATE '1970-01-17');", new String[]{"6.0"});
+    testSimpleEval("select extract(dow from DATE '1970-01-18');", new String[]{"0.0"});
+    testSimpleEval("select extract(isodow from DATE '1970-01-17');", new String[]{"6.0"});
+    testSimpleEval("select extract(isodow from DATE '1970-01-18');", new String[]{"7.0"});
+
+    testSimpleEval("select extract(year from DATE '2006-01-02');", new String[]{"2006.0"});
+    testSimpleEval("select extract(year from DATE '2006-01-01');", new String[]{"2006.0"});
+    testSimpleEval("select extract(isoyear from DATE '2006-01-02');", new String[]{"2006.0"});
+    testSimpleEval("select extract(isoyear from DATE '2006-01-01');", new String[]{"2005.0"});
+
+    testSimpleEval("select extract(quarter from DATE '2006-02-01');", new String[]{"1.0"});
+    testSimpleEval("select extract(quarter from DATE '2006-04-01');", new String[]{"2.0"});
+    testSimpleEval("select extract(quarter from DATE '2006-07-01');", new String[]{"3.0"});
+    testSimpleEval("select extract(quarter from DATE '2006-12-01');", new String[]{"4.0"});
+
+    testSimpleEval("select extract(week from DATE '1970-01-17');", new String[]{"3.0"});
+  }
+
+  @Test
+  public void testDatePart() throws IOException {
+    Schema schema2 = new Schema();
+    schema2.addColumn("col1", TIMESTAMP);
+    testEval(schema2, "table1",
+        "1970-01-17 10:09:37",
+        "select date_part('year', col1), date_part('month', col1), date_part('day', col1) from table1;",
+        new String[]{"1970.0", "1.0", "17.0"});
+
+    Schema schema3 = new Schema();
+    schema3.addColumn("col1", TIME);
+    testEval(schema3, "table1", "10:09:37.5",
+        "select date_part('hour', col1), date_part('minute', col1), date_part('second', col1) from table1;",
+        new String[]{"10.0", "9.0", "37.5"});
+
+    Schema schema4 = new Schema();
+    schema4.addColumn("col1", DATE);
+    testEval(schema4, "table1",
+        "1970-01-17",
+        "select date_part('year', col1), date_part('month', col1), date_part('day', col1) from table1;",
+        new String[]{"1970.0", "1.0", "17.0"});
+
+    testSimpleEval("select date_part('century', TIMESTAMP '1970-01-17 10:09:37');", new String[]{"19.0"});
+
+    testSimpleEval("select date_part('century', DATE '1970-01-17');", new String[]{"19.0"});
+
+    testSimpleEval("select date_part('decade', TIMESTAMP '1970-01-17 10:09:37');", new String[]{"197.0"});
+
+    testSimpleEval("select date_part('decade', DATE '1970-01-17');", new String[]{"197.0"});
+
+    testSimpleEval("select date_part('millennium', TIMESTAMP '2001-02-16 10:09:37');", new String[]{"3.0"});
+    testSimpleEval("select date_part('millennium', TIMESTAMP '2000-02-16 10:09:37');", new String[]{"2.0"});
+
+    testSimpleEval("select date_part('millennium', DATE '2001-02-16');", new String[]{"3.0"});
+    testSimpleEval("select date_part('millennium', DATE '2000-02-16');", new String[]{"2.0"});
+
+    testSimpleEval("select date_part('year', TIMESTAMP '1970-01-17 10:09:37');", new String[]{"1970.0"});
+    testSimpleEval("select date_part('month', TIMESTAMP '1970-01-17 10:09:37');", new String[]{"1.0"});
+    testSimpleEval("select date_part('day', TIMESTAMP '1970-01-17 10:09:37');", new String[]{"17.0"});
+
+    testSimpleEval("select date_part('hour', TIMESTAMP '1970-01-17 10:09:37');", new String[]{"10.0"});
+    testSimpleEval("select date_part('minute', TIMESTAMP '1970-01-17 10:09:37');", new String[]{"9.0"});
+    testSimpleEval("select date_part('second', TIMESTAMP '1970-01-17 10:09:37');", new String[]{"37.0"});
+    testSimpleEval("select date_part('second', TIMESTAMP '1970-01-17 10:09:37.5');", new String[]{"37.5"});
+
+    testSimpleEval("select date_part('hour', TIME '10:09:37');", new String[]{"10.0"});
+    testSimpleEval("select date_part('minute', TIME '10:09:37');", new String[]{"9.0"});
+    testSimpleEval("select date_part('second', TIME '10:09:37');", new String[]{"37.0"});
+    testSimpleEval("select date_part('second', TIME '10:09:37.5');", new String[]{"37.5"});
+
+    testSimpleEval("select date_part('year', DATE '1970-01-17');", new String[]{"1970.0"});
+    testSimpleEval("select date_part('month', DATE '1970-01-17');", new String[]{"1.0"});
+    testSimpleEval("select date_part('day', DATE '1970-01-17');", new String[]{"17.0"});
+
+    testSimpleEval("select date_part('milliseconds', TIMESTAMP '1970-01-17 10:09:37.5');", new String[]{"37500.0"});
+    testSimpleEval("select date_part('milliseconds', TIME '10:09:37.123');", new String[]{"37123.0"});
+
+    testSimpleEval("select date_part('microseconds', TIMESTAMP '1970-01-17 10:09:37.5');", new String[]{"3.75E7"});
+    testSimpleEval("select date_part('microseconds', TIME '10:09:37.123');", new String[]{"3.7123E7"});
+
+    testSimpleEval("select date_part('dow', TIMESTAMP '1970-01-17 10:09:37');", new String[]{"6.0"});
+    testSimpleEval("select date_part('dow', TIMESTAMP '1970-01-18 10:09:37');", new String[]{"0.0"});
+    testSimpleEval("select date_part('isodow', TIMESTAMP '1970-01-17 10:09:37');", new String[]{"6.0"});
+    testSimpleEval("select date_part('isodow', TIMESTAMP '1970-01-18 10:09:37');", new String[]{"7.0"});
+
+    testSimpleEval("select date_part('year', TIMESTAMP '2006-01-02 10:09:37');", new String[]{"2006.0"});
+    testSimpleEval("select date_part('year', TIMESTAMP '2006-01-01 10:09:37');", new String[]{"2006.0"});
+    testSimpleEval("select date_part('isoyear', TIMESTAMP '2006-01-02 10:09:37');", new String[]{"2006.0"});
+    testSimpleEval("select date_part('isoyear', TIMESTAMP '2006-01-01 10:09:37');", new String[]{"2005.0"});
+
+    testSimpleEval("select date_part('quarter', TIMESTAMP '2006-02-01 10:09:37');", new String[]{"1.0"});
+    testSimpleEval("select date_part('quarter', TIMESTAMP '2006-04-01 10:09:37');", new String[]{"2.0"});
+    testSimpleEval("select date_part('quarter', TIMESTAMP '2006-07-01 10:09:37');", new String[]{"3.0"});
+    testSimpleEval("select date_part('quarter', TIMESTAMP '2006-12-01 10:09:37');", new String[]{"4.0"});
+
+    testSimpleEval("select date_part('week', TIMESTAMP '1970-01-17 10:09:37');", new String[]{"3.0"});
+
+    testSimpleEval("select date_part('dow', DATE '1970-01-17');", new String[]{"6.0"});
+    testSimpleEval("select date_part('dow', DATE '1970-01-18');", new String[]{"0.0"});
+    testSimpleEval("select date_part('isodow', DATE '1970-01-17');", new String[]{"6.0"});
+    testSimpleEval("select date_part('isodow', DATE '1970-01-18');", new String[]{"7.0"});
+
+    testSimpleEval("select date_part('year', DATE '2006-01-02');", new String[]{"2006.0"});
+    testSimpleEval("select date_part('year', DATE '2006-01-01');", new String[]{"2006.0"});
+    testSimpleEval("select date_part('isoyear', DATE '2006-01-02');", new String[]{"2006.0"});
+    testSimpleEval("select date_part('isoyear', DATE '2006-01-01');", new String[]{"2005.0"});
+
+    testSimpleEval("select date_part('quarter', DATE '2006-02-01');", new String[]{"1.0"});
+    testSimpleEval("select date_part('quarter', DATE '2006-04-01');", new String[]{"2.0"});
+    testSimpleEval("select date_part('quarter', DATE '2006-07-01');", new String[]{"3.0"});
+    testSimpleEval("select date_part('quarter', DATE '2006-12-01');", new String[]{"4.0"});
+
+    testSimpleEval("select date_part('week', DATE '1970-01-17');", new String[]{"3.0"});
+  }
+
+  @Test
+  public void testUtcUsecTo() throws IOException {
+     testSimpleEval("select utc_usec_to('day' ,1274259481071200);", new String[]{1274227200000000L+""});
+     testSimpleEval("select utc_usec_to('hour' ,1274259481071200);", new String[]{1274256000000000L+""});
+     testSimpleEval("select utc_usec_to('month' ,1274259481071200);", new String[]{1272672000000000L+""});
+     testSimpleEval("select utc_usec_to('year' ,1274259481071200);", new String[]{1262304000000000L+""});
+     testSimpleEval("select utc_usec_to('week' ,1207929480000000, 2);", new String[]{1207612800000000L+""});
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/6594ac1c/tajo-core/src/test/java/org/apache/tajo/engine/function/TestGeneralFunction.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestGeneralFunction.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestGeneralFunction.java
new file mode 100644
index 0000000..81ddba5
--- /dev/null
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestGeneralFunction.java
@@ -0,0 +1,49 @@
+/**
+ * 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.engine.function;
+
+import org.junit.Test;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.datum.Int8Datum;
+import org.apache.tajo.datum.TextDatum;
+import org.apache.tajo.engine.function.builtin.Date;
+import org.apache.tajo.storage.Tuple;
+import org.apache.tajo.storage.VTuple;
+
+import java.util.Calendar;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestGeneralFunction {
+
+  @Test
+  public void testDate() {
+    Date date = new Date();
+    Tuple tuple = new VTuple(new Datum[] {new TextDatum("25/12/2012 00:00:00")});
+    Int8Datum unixtime = (Int8Datum) date.eval(tuple);
+    Calendar c = Calendar.getInstance();
+    c.setTimeInMillis(unixtime.asInt8());
+    assertEquals(2012, c.get(Calendar.YEAR));
+    assertEquals(11, c.get(Calendar.MONTH));
+    assertEquals(25, c.get(Calendar.DAY_OF_MONTH));
+    assertEquals(0, c.get(Calendar.HOUR_OF_DAY));
+    assertEquals(0, c.get(Calendar.MINUTE));
+    assertEquals(0, c.get(Calendar.SECOND));
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/6594ac1c/tajo-core/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java
new file mode 100644
index 0000000..09f7f68
--- /dev/null
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java
@@ -0,0 +1,428 @@
+/**
+ * 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.engine.function;
+
+import org.apache.tajo.catalog.Schema;
+import org.apache.tajo.engine.eval.ExprTestBase;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.apache.tajo.common.TajoDataTypes.Type.*;
+
+public class TestMathFunctions extends ExprTestBase {
+  @Test
+  public void testRound() throws IOException {
+    testSimpleEval("select round(5.1) as col1 ", new String[]{"5"});
+    testSimpleEval("select round(5.5) as col1 ", new String[]{"6"});
+    testSimpleEval("select round(5.6) as col1 ", new String[]{"6"});
+
+    testSimpleEval("select round(-5.1) as col1 ", new String[]{"-5"});
+    testSimpleEval("select round(-5.5) as col1 ", new String[]{"-6"});
+    testSimpleEval("select round(-5.6) as col1 ", new String[]{"-6"});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT8);
+    schema.addColumn("col2", FLOAT8);
+    schema.addColumn("col3", FLOAT8);
+
+    testEval(schema, "table1", "1.0, 0.2, 0.4", "select round(col1 + col2 + col3) from table1",
+        new String[]{"2"});
+  }
+
+  @Test
+  public void testFloor() throws IOException {
+    testSimpleEval("select floor(5.1) as col1 ", new String[]{"5"});
+    testSimpleEval("select floor(5.5) as col1 ", new String[]{"5"});
+    testSimpleEval("select floor(5.6) as col1 ", new String[]{"5"});
+
+    testSimpleEval("select floor(-5.1) as col1 ", new String[]{"-6"});
+    testSimpleEval("select floor(-5.6) as col1 ", new String[]{"-6"});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT8);
+    schema.addColumn("col2", FLOAT8);
+    schema.addColumn("col3", FLOAT8);
+
+    testEval(schema, "table1", "1.0, 0.2, 0.4", "select floor(col1 + col2 + col3) from table1",
+        new String[]{"1"});
+  }
+
+  @Test
+  public void testCeil() throws IOException {
+    testSimpleEval("select ceil(5.0) as col1 ", new String[]{"5"});
+    testSimpleEval("select ceil(5.1) as col1 ", new String[]{"6"});
+    testSimpleEval("select ceil(5.5) as col1 ", new String[]{"6"});
+    testSimpleEval("select ceil(5.6) as col1 ", new String[]{"6"});
+
+    testSimpleEval("select ceil(-5.1) as col1 ", new String[]{"-5"});
+    testSimpleEval("select ceil(-5.6) as col1 ", new String[]{"-5"});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT8);
+    schema.addColumn("col2", FLOAT8);
+    schema.addColumn("col3", FLOAT8);
+
+    testEval(schema, "table1", "1.0, 0.2, 0.1", "select ceil(col1 + col2 + col3) from table1",
+        new String[]{"2"});
+  }
+
+  @Test
+  public void testCeiling() throws IOException {
+    testSimpleEval("select ceiling(5.0) as col1 ", new String[]{"5"});
+    testSimpleEval("select ceiling(5.1) as col1 ", new String[]{"6"});
+    testSimpleEval("select ceiling(5.5) as col1 ", new String[]{"6"});
+    testSimpleEval("select ceiling(5.6) as col1 ", new String[]{"6"});
+
+    testSimpleEval("select ceiling(-5.1) as col1 ", new String[]{"-5"});
+    testSimpleEval("select ceiling(-5.6) as col1 ", new String[]{"-5"});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT8);
+    schema.addColumn("col2", FLOAT8);
+    schema.addColumn("col3", FLOAT8);
+
+    testEval(schema, "table1", "1.0, 0.2, 0.1", "select ceiling(col1 + col2 + col3) from table1",
+        new String[]{"2"});
+  }
+
+  @Test
+  public void testSin() throws IOException {
+    testSimpleEval("select sin(0.0) as col1 ", new String[]{"0.0"});
+    testSimpleEval("select sin(0.7) as col1 ", new String[]{"0.644217687237691"});
+    testSimpleEval("select sin(1.2) as col1 ", new String[]{"0.9320390859672263"});
+    testSimpleEval("select sin(-0.5) as col1 ", new String[]{"-0.479425538604203"});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT8);
+    schema.addColumn("col2", FLOAT8);
+    schema.addColumn("col3", FLOAT8);
+
+    testEval(schema, "table1", "1.0, 0.2, 0.1", "select sin(col1 + col2 + col3) from table1",
+        new String[]{"0.963558185417193"});
+  }
+
+
+  @Test
+  public void testCos() throws IOException {
+    testSimpleEval("select cos(0.0) as col1 ", new String[]{"1.0"});
+    testSimpleEval("select cos(0.7) as col1 ", new String[]{"0.7648421872844885"});
+    testSimpleEval("select cos(1.2) as col1 ", new String[]{"0.3623577544766736"});
+    testSimpleEval("select cos(-0.5) as col1 ", new String[]{"0.8775825618903728"});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT8);
+    schema.addColumn("col2", FLOAT8);
+    schema.addColumn("col3", FLOAT8);
+
+    testEval(schema, "table1", "1.0, 0.2, 0.1", "select cos(col1 + col2 + col3) from table1",
+        new String[]{"0.26749882862458735"});
+  }
+
+  @Test
+  public void testTan() throws IOException {
+    testSimpleEval("select tan(0.0) as col1 ", new String[]{"0.0"});
+    testSimpleEval("select tan(0.3) as col1 ", new String[]{"0.30933624960962325"});
+    testSimpleEval("select tan(0.8) as col1 ", new String[]{"1.0296385570503641"});
+    testSimpleEval("select tan(-0.5) as col1 ", new String[]{"-0.5463024898437905"});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT8);
+    schema.addColumn("col2", FLOAT8);
+    schema.addColumn("col3", FLOAT8);
+
+    testEval(schema, "table1", "1.0, 0.2, 0.1", "select tan(col1 - col2 - col3) from table1",
+        new String[]{"0.8422883804630795"});
+  }
+
+  @Test
+  public void testAsin() throws IOException {
+    testSimpleEval("select asin(0.0) as col1 ", new String[]{"0.0"});
+    testSimpleEval("select asin(0.3) as col1 ", new String[]{"0.3046926540153975"});
+    testSimpleEval("select asin(0.8) as col1 ", new String[]{"0.9272952180016123"});
+    testSimpleEval("select asin(-0.5) as col1 ", new String[]{"-0.5235987755982989"});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT8);
+    schema.addColumn("col2", FLOAT8);
+    schema.addColumn("col3", FLOAT8);
+
+    testEval(schema, "table1", "1.0, 0.2, 0.1", "select asin(col1 - col2 - col3) from table1",
+        new String[]{"0.7753974966107532"});
+  }
+
+  @Test
+  public void testAcos() throws IOException {
+    testSimpleEval("select acos(0.0) as col1 ", new String[]{"1.5707963267948966"});
+    testSimpleEval("select acos(0.3) as col1 ", new String[]{"1.2661036727794992"});
+    testSimpleEval("select acos(0.8) as col1 ", new String[]{"0.6435011087932843"});
+    testSimpleEval("select acos(-0.5) as col1 ", new String[]{"2.0943951023931957"});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT8);
+    schema.addColumn("col2", FLOAT8);
+    schema.addColumn("col3", FLOAT8);
+
+    testEval(schema, "table1", "1.0, 0.2, 0.1", "select acos(col1 - col2 - col3) from table1",
+        new String[]{"0.7953988301841435"});
+  }
+
+  @Test
+  public void testAtan() throws IOException {
+    testSimpleEval("select atan(0.0) as col1 ", new String[]{"0.0"});
+    testSimpleEval("select atan(0.8) as col1 ", new String[]{"0.6747409422235527"});
+    testSimpleEval("select atan(1.2) as col1 ", new String[]{"0.8760580505981934"});
+    testSimpleEval("select atan(-0.5) as col1 ", new String[]{"-0.4636476090008061"});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT8);
+    schema.addColumn("col2", FLOAT8);
+    schema.addColumn("col3", FLOAT8);
+
+    testEval(schema, "table1", "1.0, 0.2, 0.1", "select atan(col1 + col2 + col3) from table1",
+        new String[]{"0.9151007005533605"});
+  }
+
+  @Test
+  public void testAtan2() throws IOException {
+    testSimpleEval("select atan2(0.8, 0.0) as col1 ", new String[]{"1.5707963267948966"});
+    testSimpleEval("select atan2(0.8, 1.1) as col1 ", new String[]{"0.628796286415433"});
+    testSimpleEval("select atan2(2.7, 0.3) as col1 ", new String[]{"1.460139105621001"});
+    testSimpleEval("select atan2(-0.5, 0.3) as col1 ", new String[]{"-1.0303768265243125"});
+    testSimpleEval("select atan2(-0.2, -1.3) as col1 ", new String[]{"-2.988943325194528"});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT8);
+    schema.addColumn("col2", FLOAT8);
+    schema.addColumn("col3", FLOAT8);
+
+    testEval(schema, "table1", "1.0, 0.2, 0.1", "select atan2(col1 + col2, col3) from table1",
+        new String[]{"1.4876550949064553"});
+  }
+
+  @Test
+  public void testMod() throws IOException {
+    testSimpleEval("select mod(9,4) as col1 ", new String[]{"1"});
+    testSimpleEval("select mod(200000000001,200000000000) as col1 ", new String[]{"1"});
+    testSimpleEval("select mod(200000000000,2) as col1 ", new String[]{"0"});
+    testSimpleEval("select mod(2,200000000000) as col1 ", new String[]{"2"});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", INT8);
+    schema.addColumn("col2", INT8);
+    schema.addColumn("col3", INT8);
+
+    testEval(schema, "table1", "9,2,3", "select mod(col1 + col2, col3) from table1", 
+        new String[]{"2"});
+  }
+
+  @Test
+  public void testDiv() throws IOException {
+    testSimpleEval("select div(9,4) as col1 ", new String[]{"2"});
+    testSimpleEval("select div(200000000001,200000000000) as col1 ", new String[]{"1"});
+    testSimpleEval("select div(200000000000,2) as col1 ", new String[]{"100000000000"});
+    testSimpleEval("select div(2,200000000000) as col1 ", new String[]{"0"});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", INT8);
+    schema.addColumn("col2", INT8);
+    schema.addColumn("col3", INT8);
+
+    testEval(schema, "table1", "9,2,3", "select div(col1 + col2, col3) from table1", 
+        new String[]{"3"});
+  }
+
+  @Test
+  public void testSign() throws IOException {
+    testSimpleEval("select sign(2) as col1 ", new String[]{"1.0"});
+    testSimpleEval("select sign(2.345) as col1 ", new String[]{"1.0"});
+    testSimpleEval("select sign(0.3) as col1 ", new String[]{"1.0"});
+
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT4);
+    schema.addColumn("col2", FLOAT4);
+    schema.addColumn("col3", FLOAT4);
+
+    testEval(schema, "table1", "1.0, 0.2, 0.1", "select sign(col1 + col2 + col3) from table1",
+        new String[]{"1.0"});
+
+
+    Schema schema2 = new Schema();
+    schema2.addColumn("col1", FLOAT8);
+    schema2.addColumn("col2", FLOAT8);
+    schema2.addColumn("col3", FLOAT8);
+
+    testEval(schema2, "table1", "1.0, 0.2, 0.1", "select sign(col1 + col2 + col3) from table1",
+        new String[]{"1.0"});
+  }
+
+  @Test
+  public void testSqrt() throws IOException {
+    testSimpleEval("select sqrt(27.0) as col1 ", new String[]{"5.196152422706632"});
+    testSimpleEval("select sqrt(64.0) as col1 ", new String[]{"8.0"});
+    testSimpleEval("select sqrt(8.0) as col1 ", new String[]{"2.8284271247461903"});
+
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT4);
+    schema.addColumn("col2", FLOAT4);
+    schema.addColumn("col3", FLOAT4);
+
+    testEval(schema, "table1", "1.0, 0.2, 0.1", "select sqrt(col1 + col2 + col3) from table1",
+        new String[]{"1.1401754466632896"});
+
+
+    Schema schema2 = new Schema();
+    schema2.addColumn("col1", FLOAT8);
+    schema2.addColumn("col2", FLOAT8);
+    schema2.addColumn("col3", FLOAT8);
+
+    testEval(schema2, "table1", "1.0, 0.2, 0.1", "select sqrt(col1 + col2 + col3) from table1",
+        new String[]{"1.140175425099138"});
+  }
+
+  @Test
+  public void testExp() throws IOException {
+    testSimpleEval("select exp(1.0) as col1 ", new String[]{String.valueOf(Math.exp(1.0d))});
+    testSimpleEval("select exp(1.1) as col1 ", new String[]{String.valueOf(Math.exp(1.1d))});
+    testSimpleEval("select exp(1.2) as col1 ", new String[]{String.valueOf(Math.exp(1.2d))});
+
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT4);
+
+    testEval(schema, "table1", "1.123", "select exp(col1) from table1",
+        new String[]{String.valueOf(Math.exp(1.123f))});
+
+    Schema schema2 = new Schema();
+    schema2.addColumn("col1", FLOAT8);
+
+    testEval(schema2, "table1", "1.123", "select exp(col1) from table1",
+        new String[]{String.valueOf(Math.exp(1.123d))});
+  }
+
+
+  @Test
+  public void testAbs() throws IOException {
+    testSimpleEval("select abs(9) as col1 ", new String[]{"9"});
+    testSimpleEval("select abs(-9) as col1 ", new String[]{"9"});
+    testSimpleEval("select abs(200000000000) as col1 ", new String[]{"200000000000"});
+    testSimpleEval("select abs(-200000000000) as col1 ", new String[]{"200000000000"});
+    testSimpleEval("select abs(2.0) as col1 ", new String[]{"2.0"});
+    testSimpleEval("select abs(-2.0) as col1 ", new String[]{"2.0"});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT4);
+    schema.addColumn("col2", FLOAT4);
+    testEval(schema, "table1", "0.39,-0.39", "select abs(col1), abs(col2) from table1", new String[]{"0.39", "0.39"});
+
+    Schema schema2 = new Schema();
+    schema2.addColumn("col1", FLOAT8);
+    schema2.addColumn("col2", FLOAT8);
+    testEval(schema2, "table1", "0.033312347,-0.033312347", "select abs(col1), abs(col2) from table1",
+        new String[]{"0.033312347", "0.033312347"});
+  }
+
+  @Test
+  public void testCbrt() throws IOException {
+    testSimpleEval("select cbrt(27.0) as col1 ", new String[]{"3.0"});
+    testSimpleEval("select cbrt(64.0) as col1 ", new String[]{"4.0"});
+    testSimpleEval("select cbrt(8.0) as col1 ", new String[]{"2.0"});
+
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT4);
+    schema.addColumn("col2", FLOAT4);
+    schema.addColumn("col3", FLOAT4);
+    testEval(schema, "table1", "1.0, 0.2, 0.1", "select cbrt(col1 + col2 + col3) from table1",
+        new String[]{"1.0913928968221236"});
+
+    Schema schema2 = new Schema();
+    schema2.addColumn("col1", FLOAT8);
+    schema2.addColumn("col2", FLOAT8);
+    schema2.addColumn("col3", FLOAT8);
+    testEval(schema2, "table1", "1.0, 0.2, 0.1", "select cbrt(col1 + col2 + col3) from table1",
+        new String[]{"1.091392883061106"});
+  }
+
+  @Test
+  public void testDegrees() throws IOException {
+    testSimpleEval("select degrees(0.0) as col1 ", new String[]{String.valueOf(Math.toDegrees(0.0))});
+    testSimpleEval("select degrees(0.8) as col1 ", new String[]{String.valueOf(Math.toDegrees(0.8))});
+    testSimpleEval("select degrees(2.7) as col1 ", new String[]{String.valueOf(Math.toDegrees(2.7))});
+    testSimpleEval("select degrees(-0.8) as col1 ", new String[]{String.valueOf(Math.toDegrees(-0.8))});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT4);
+    schema.addColumn("col2", FLOAT8);
+    schema.addColumn("col3", FLOAT8);
+
+    testEval(schema, "table1", "0.8,2.7,-0.8", "select degrees(col1), degrees(col2), degrees(col3) from table1",
+        new String[]{
+            String.valueOf(Math.toDegrees((float)0.8)),
+            String.valueOf(Math.toDegrees(2.7)),
+            String.valueOf(Math.toDegrees(-0.8))
+        });
+  }
+
+  @Test
+  public void testPow() throws IOException {
+    testSimpleEval("select pow(9,3) as col1 ", new String[]{String.valueOf(Math.pow(9,3))});
+    testSimpleEval("select pow(1.0,3) as col1 ", new String[]{String.valueOf(Math.pow(1.0,3))});
+    testSimpleEval("select pow(20.1,3.1) as col1 ", new String[]{String.valueOf(Math.pow(20.1,3.1))});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT4);
+    schema.addColumn("col2", FLOAT8);
+    schema.addColumn("col3", INT4);
+    schema.addColumn("col4", INT8);
+
+    testEval(schema, "table1", "0.4,2.7,3,2", "select pow(col1, col2), pow(col3, col4) from table1",
+        new String[]{
+            String.valueOf(Math.pow((float)0.4, 2.7)),
+            String.valueOf(Math.pow(3,2))
+        });
+  }
+
+  @Test
+  public void testRadians() throws IOException {
+    testSimpleEval("select radians(0.0) as col1 ", new String[]{String.valueOf(Math.toRadians(0.0))});
+    testSimpleEval("select radians(0.8) as col1 ", new String[]{String.valueOf(Math.toRadians(0.8))});
+    testSimpleEval("select radians(2.7) as col1 ", new String[]{String.valueOf(Math.toRadians(2.7))});
+    testSimpleEval("select radians(-0.8) as col1 ", new String[]{String.valueOf(Math.toRadians(-0.8))});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT4);
+    schema.addColumn("col2", FLOAT8);
+    schema.addColumn("col3", FLOAT8);
+
+    testEval(schema, "table1", "0.8,2.7,-0.8", "select radians(col1), radians(col2), radians(col3) from table1",
+        new String[]{
+            String.valueOf(Math.toRadians((float)0.8)),
+            String.valueOf(Math.toRadians(2.7)),
+            String.valueOf(Math.toRadians(-0.8))
+        });
+  }
+
+  @Test
+  public void testPi() throws IOException {
+    testSimpleEval("select pi() as col1 ", new String[]{String.valueOf(Math.PI)});
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/6594ac1c/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPatternMatchingPredicates.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPatternMatchingPredicates.java b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPatternMatchingPredicates.java
new file mode 100644
index 0000000..7d8eba4
--- /dev/null
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestPatternMatchingPredicates.java
@@ -0,0 +1,140 @@
+/**
+ * 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.engine.function;
+
+import org.apache.tajo.catalog.Schema;
+import org.apache.tajo.engine.eval.ExprTestBase;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.apache.tajo.common.TajoDataTypes.Type.TEXT;
+
+public class TestPatternMatchingPredicates extends ExprTestBase {
+
+  @Test
+  public void testLike() throws IOException {
+    Schema schema = new Schema();
+    schema.addColumn("col1", TEXT);
+
+    // test for null values
+    testEval(schema, "table1", ",", "select col1 like 'a%' from table1", new String[]{""});
+    //testSimpleEval("select null like 'a%'", new String[]{""});
+
+    testEval(schema, "table1", "abc", "select col1 like '%c' from table1", new String[]{"t"});
+    testEval(schema, "table1", "abc", "select col1 like 'a%' from table1", new String[]{"t"});
+    testEval(schema, "table1", "abc", "select col1 like '_bc' from table1", new String[]{"t"});
+    testEval(schema, "table1", "abc", "select col1 like 'ab_' from table1", new String[]{"t"});
+    testEval(schema, "table1", "abc", "select col1 like '_b_' from table1", new String[]{"t"});
+    testEval(schema, "table1", "abc", "select col1 like '%b%' from table1", new String[]{"t"});
+
+    // test for escaping regular expressions
+    testEval(schema, "table1", "abc", "select col1 not like '.bc' from table1", new String[]{"t"});
+    testEval(schema, "table1", "abc", "select col1 not like '.*bc' from table1", new String[]{"t"});
+    testEval(schema, "table1", "abc", "select col1 not like '.bc' from table1", new String[]{"t"});
+    testEval(schema, "table1", "abc", "select col1 not like '*bc' from table1", new String[]{"t"});
+
+    // test for case sensitive
+    testEval(schema, "table1", "abc", "select col1 not like '%C' from table1", new String[]{"t"});
+    testEval(schema, "table1", "abc", "select col1 not like 'A%' from table1", new String[]{"t"});
+    testEval(schema, "table1", "abc", "select col1 not like '_BC' from table1", new String[]{"t"});
+    testEval(schema, "table1", "abc", "select col1 not like '_C_' from table1", new String[]{"t"});
+  }
+
+  @Test
+  public void testILike() throws IOException {
+    testSimpleEval("select 'abc' ilike '%c'", new String[]{"t"});
+    testSimpleEval("select 'abc' ilike 'a%'", new String[]{"t"});
+    testSimpleEval("select 'abc' ilike '_bc'", new String[]{"t"});
+    testSimpleEval("select 'abc' ilike 'ab_'", new String[]{"t"});
+    testSimpleEval("select 'abc' ilike '_b_'", new String[]{"t"});
+    testSimpleEval("select 'abc' ilike '%b%'", new String[]{"t"});
+
+    // test for escaping regular expressions
+    testSimpleEval("select 'abc' not like '.bc'", new String[]{"t"});
+    testSimpleEval("select 'abc' not like '.*bc'", new String[]{"t"});
+    testSimpleEval("select 'abc' not like '.bc'", new String[]{"t"});
+    testSimpleEval("select 'abc' not like '*bc'", new String[]{"t"});
+
+    // test for case insensitive
+    testSimpleEval("select 'abc' ilike '%C'", new String[]{"t"});
+    testSimpleEval("select 'abc' ilike 'A%'", new String[]{"t"});
+    testSimpleEval("select 'abc' ilike '_BC'", new String[]{"t"});
+    testSimpleEval("select 'abc' ilike '_B_'", new String[]{"t"});
+  }
+
+  @Test
+  public void testSimilarToLike() throws IOException {
+    testSimpleEval("select 'abc' similar to '%c'", new String[]{"t"});
+    testSimpleEval("select 'abc' similar to 'a%'", new String[]{"t"});
+    testSimpleEval("select 'abc' similar to '_bc'", new String[]{"t"});
+    testSimpleEval("select 'abc' similar to 'ab_'", new String[]{"t"});
+    testSimpleEval("select 'abc' similar to '_b_'", new String[]{"t"});
+    testSimpleEval("select 'abc' similar to '%b%'", new String[]{"t"});
+
+    // test for now allowed
+    testSimpleEval("select 'abc' not similar to '.bc'", new String[]{"t"});
+    testSimpleEval("select 'abc' not similar to 'ab.'", new String[]{"t"});
+
+    // test for escaping regular expressions
+    testSimpleEval("select 'abc' similar to '(a|f)b%'", new String[]{"t"});
+    testSimpleEval("select 'abc' similar to '[a-z]b%'", new String[]{"t"});
+    testSimpleEval("select 'abc' similar to '_+bc'", new String[]{"t"});
+    testSimpleEval("select 'abc' similar to 'abc'", new String[]{"t"});
+
+    // test for case sensitive
+    testSimpleEval("select 'abc' not similar to '%C'", new String[]{"t"});
+    testSimpleEval("select 'abc' not similar to '_Bc'", new String[]{"t"});
+  }
+
+  @Test
+  public void testRegexWithSimilarOperator() throws IOException {
+    testSimpleEval("select 'abc' ~ '.*c'", new String[]{"t"});
+    testSimpleEval("select 'abc' ~ '.*c$'", new String[]{"t"});
+    testSimpleEval("select 'aaabc' ~ '([a-z]){3}bc'", new String[]{"t"});
+
+    // for negative condition
+    testSimpleEval("select 'abc' !~ '.*c$'", new String[]{"f"});
+
+    // for case sensitivity
+    testSimpleEval("select 'abc' ~ '.*C'", new String[]{"f"});
+
+    // for case insensitivity
+    testSimpleEval("select 'abc' ~* '.*C'", new String[]{"t"});
+    testSimpleEval("select 'abc' !~* '.*C'", new String[]{"f"});
+  }
+
+  @Test
+  public void testRegexp() throws IOException {
+    testSimpleEval("select 'abc' regexp '.*c'", new String[]{"t"});
+    testSimpleEval("select 'abc' regexp '.*c$'", new String[]{"t"});
+
+    // for negative condition
+    testSimpleEval("select 'abc' not regexp '.*c$'", new String[]{"f"});
+  }
+
+  @Test
+  public void testRLike() throws IOException {
+    testSimpleEval("select 'abc' rlike '.*c'", new String[]{"t"});
+    testSimpleEval("select 'abc' rlike '.*c$'", new String[]{"t"});
+
+    // for negative condition
+    testSimpleEval("select 'abc' not rlike '.*c$'", new String[]{"f"});
+  }
+}


Mime
View raw message