Repository: tajo
Updated Branches:
  refs/heads/master 98f142cc7 -> 526dca28b


http://git-wip-us.apache.org/repos/asf/tajo/blob/526dca28/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestIntervalType.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestIntervalType.java 
b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestIntervalType.java
index 4d18be3..6450028 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestIntervalType.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestIntervalType.java
@@ -28,24 +28,32 @@ import static org.junit.Assert.fail;
 public class TestIntervalType extends ExprTestBase {
   @Test
   public void testIntervalPostgresqlCase() throws IOException {
+
     // http://www.postgresql.org/docs/8.2/static/functions-datetime.html
     testSimpleEval("select date '2001-09-28' + 7", new String[]{"2001-10-05"});
-    testSimpleEval("select date '2001-09-28' + interval '1 hour'", new 
String[]{"2001-09-28 01:00:00"});
+    testSimpleEval("select date '2001-09-28' + interval '1 hour'",
+        new String[]{"2001-09-28 01:00:00" + getUserTimeZoneDisplay()});
 
-    testSimpleEval("select date '2001-09-28' + time '03:00'", new 
String[]{"2001-09-28 03:00:00"});
+    testSimpleEval("select date '2001-09-28' + time '03:00'",
+        new String[]{"2001-09-28 03:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select time '03:00' + date '2001-09-28'",
+        new String[]{"2001-09-28 03:00:00" + getUserTimeZoneDisplay()});
     testSimpleEval("select interval '1 day' + interval '1 hour'", new 
String[]{"1 day 01:00:00"});
 
-    testSimpleEval("select timestamp '2001-09-28 01:00' + interval '23 
hours'", new String[]{"2001-09-29 00:00:00"});
+    testSimpleEval("select timestamp '2001-09-28 01:00' + interval '23 hours'",
+        new String[]{"2001-09-29 00:00:00" + getUserTimeZoneDisplay()});
 
-    testSimpleEval("select time '01:00' + interval '3 hours'", new 
String[]{"04:00:00"});
+    testSimpleEval("select time '01:00' + interval '3 hours'", new 
String[]{"04:00:00" + getUserTimeZoneDisplay()});
 
     testSimpleEval("select date '2001-10-01' - date '2001-09-28'", new 
String[]{"3"});
     testSimpleEval("select date '2001-10-01' - 7", new String[]{"2001-09-24"});
-    testSimpleEval("select date '2001-09-28' - interval '1 hour'", new 
String[]{"2001-09-27 23:00:00"});
+    testSimpleEval("select date '2001-09-28' - interval '1 hour'",
+        new String[]{"2001-09-27 23:00:00" + getUserTimeZoneDisplay()});
 
     testSimpleEval("select time '05:00' - time '03:00'", new 
String[]{"02:00:00"});
-    testSimpleEval("select time '05:00' - interval '2 hours'", new 
String[]{"03:00:00"});
-    testSimpleEval("select timestamp '2001-09-28 23:00' - interval '23 
hours'", new String[]{"2001-09-28 00:00:00"});
+    testSimpleEval("select time '05:00' - interval '2 hours'", new 
String[]{"03:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select timestamp '2001-09-28 23:00' - interval '23 hours'",
+        new String[]{"2001-09-28 00:00:00" + getUserTimeZoneDisplay()});
 
     testSimpleEval("select interval '1 day' - interval '1 hour'", new 
String[]{"23:00:00"});
 
@@ -58,21 +66,33 @@ public class TestIntervalType extends ExprTestBase {
 
   @Test
   public void testCaseByCase() throws Exception {
-    testSimpleEval("select date '2001-08-28' + interval '10 day 1 hour'", new 
String[]{"2001-09-07 01:00:00"});
-    testSimpleEval("select interval '10 day 01:00:00' + date '2001-08-28'", 
new String[]{"2001-09-07 01:00:00"});
-    testSimpleEval("select time '10:20:30' + interval '1 day 01:00:00'", new 
String[]{"11:20:30"});
-    testSimpleEval("select interval '1 day 01:00:00' + time '10:20:30'", new 
String[]{"11:20:30"});
-    testSimpleEval("select time '10:20:30' - interval '1 day 01:00:00'", new 
String[]{"09:20:30"});
+    testSimpleEval("select date '2001-08-28' + interval '10 day 1 hour'",
+        new String[]{"2001-09-07 01:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select interval '10 day 01:00:00' + date '2001-08-28'",
+        new String[]{"2001-09-07 01:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select time '10:20:30' + interval '1 day 01:00:00'",
+        new String[]{"11:20:30" + getUserTimeZoneDisplay()});
+    testSimpleEval("select interval '1 day 01:00:00' + time '10:20:30'",
+        new String[]{"11:20:30" + getUserTimeZoneDisplay()});
+    testSimpleEval("select time '10:20:30' - interval '1 day 01:00:00'",
+        new String[]{"09:20:30" + getUserTimeZoneDisplay()});
 
     testSimpleEval("select (interval '1 month 20 day' + interval '50 day')", 
new String[]{"1 month 70 days"});
-    testSimpleEval("select date '2013-01-01' + interval '1 month 70 day'", new 
String[]{"2013-04-12 00:00:00"});
-    testSimpleEval("select date '2013-01-01' + (interval '1 month 20 day' + 
interval '50 day')", new String[]{"2013-04-12 00:00:00"});
-    testSimpleEval("select interval '1 month 70 day' + date '2013-01-01'", new 
String[]{"2013-04-12 00:00:00"});
-    testSimpleEval("select date '2013-01-01' - interval '1 month 70 day'", new 
String[]{"2012-09-22 00:00:00"});
-
-    testSimpleEval("select timestamp '2001-09-28 23:00' - interval '1 month 2 
day 10:20:30'", new String[]{"2001-08-26 12:39:30"});
-    testSimpleEval("select timestamp '2001-09-28 23:00' + interval '1 month 2 
day 10:20:30'", new String[]{"2001-10-31 09:20:30"});
-    testSimpleEval("select interval '1 month 2 day 10:20:30' + timestamp 
'2001-09-28 23:00'", new String[]{"2001-10-31 09:20:30"});
+    testSimpleEval("select date '2013-01-01' + interval '1 month 70 day'",
+        new String[]{"2013-04-12 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select date '2013-01-01' + (interval '1 month 20 day' + 
interval '50 day')",
+        new String[]{"2013-04-12 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select interval '1 month 70 day' + date '2013-01-01'",
+        new String[]{"2013-04-12 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select date '2013-01-01' - interval '1 month 70 day'",
+        new String[]{"2012-09-22 00:00:00" + getUserTimeZoneDisplay()});
+
+    testSimpleEval("select timestamp '2001-09-28 23:00' - interval '1 month 2 
day 10:20:30'",
+        new String[]{"2001-08-26 12:39:30" + getUserTimeZoneDisplay()});
+    testSimpleEval("select timestamp '2001-09-28 23:00' + interval '1 month 2 
day 10:20:30'",
+        new String[]{"2001-10-31 09:20:30" + getUserTimeZoneDisplay()});
+    testSimpleEval("select interval '1 month 2 day 10:20:30' + timestamp 
'2001-09-28 23:00'",
+        new String[]{"2001-10-31 09:20:30" + getUserTimeZoneDisplay()});
 
 
     testSimpleEval("select interval '5 month' / 3", new String[]{"1 month 20 
days"});
@@ -82,6 +102,8 @@ public class TestIntervalType extends ExprTestBase {
 
     testSimpleEval("select interval '1 month' * 2.3", new String[]{"2 months 9 
days"});
     testSimpleEval("select interval '3 year 5 month 1 hour' / 1.5", new 
String[]{"2 years 3 months 10 days 00:40:00"});
+
+    testSimpleEval("select date '2001-09-28' - time '03:00'", new 
String[]{"2001-09-27 21:00:00" + getUserTimeZoneDisplay()});
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/tajo/blob/526dca28/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLDateTimeTypes.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLDateTimeTypes.java 
b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLDateTimeTypes.java
index c9c8dd4..60f7dcd 100644
--- 
a/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLDateTimeTypes.java
+++ 
b/tajo-core/src/test/java/org/apache/tajo/engine/eval/TestSQLDateTimeTypes.java
@@ -26,22 +26,26 @@ public class TestSQLDateTimeTypes extends ExprTestBase {
 
   @Test
   public void testTimestamp() throws IOException {
-    testSimpleEval("select TIMESTAMP '1970-01-17 10:09:37';", new 
String[]{"1970-01-17 10:09:37"});
-    testSimpleEval("select TIMESTAMP '1970-01-17 10:09:37.5';", new 
String[]{"1970-01-17 10:09:37.5"});
-    testSimpleEval("select TIMESTAMP '1970-01-17 10:09:37.01';", new 
String[]{"1970-01-17 10:09:37.01"});
-    testSimpleEval("select TIMESTAMP '1970-01-17 10:09:37.003';", new 
String[]{"1970-01-17 10:09:37.003"});
+    testSimpleEval("select TIMESTAMP '1970-01-17 10:09:37';",
+        new String[]{"1970-01-17 10:09:37" + getUserTimeZoneDisplay()});
+    testSimpleEval("select TIMESTAMP '1970-01-17 10:09:37.5';",
+        new String[]{"1970-01-17 10:09:37.5" + getUserTimeZoneDisplay()});
+    testSimpleEval("select TIMESTAMP '1970-01-17 10:09:37.01';",
+        new String[]{"1970-01-17 10:09:37.01" + getUserTimeZoneDisplay()});
+    testSimpleEval("select TIMESTAMP '1970-01-17 10:09:37.003';",
+        new String[]{"1970-01-17 10:09:37.003" + getUserTimeZoneDisplay()});
   }
 
   @Test
   public void testToTimestamp() throws IOException {
-    testSimpleEval("select to_char(TIMESTAMP '1970-01-17 10:09:37', 
'yyyy-MM-dd HH:mm:ss');",
+    testSimpleEval("select to_char(TIMESTAMP '1970-01-17 10:09:37', 
'YYYY-MM-DD HH24:MI:SS');",
         new String[]{"1970-01-17 10:09:37"});
   }
 
   @Test
   public void testTimeLiteral() throws IOException {
     testSimpleEval("select TIME '10:09:37';",
-        new String[]{"10:09:37"});
+        new String[]{"10:09:37" + getUserTimeZoneDisplay()});
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/tajo/blob/526dca28/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
index 6e35d3b..9bd26b8 100644
--- 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
@@ -22,12 +22,15 @@ import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.Schema;
 import org.apache.tajo.catalog.exception.NoSuchFunctionException;
 import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.conf.TajoConf;
+import org.apache.tajo.datum.DatumFactory;
 import org.apache.tajo.datum.TimestampDatum;
 import org.junit.Test;
 
 import java.io.IOException;
 
 import static org.apache.tajo.common.TajoDataTypes.Type.TEXT;
+import static org.junit.Assert.fail;
 
 public class TestSQLExpression extends ExprTestBase {
 
@@ -43,9 +46,16 @@ public class TestSQLExpression extends ExprTestBase {
         new String[]{"3", "234.0"});
   }
 
-  @Test(expected = NoSuchFunctionException.class)
+  @Test
   public void testNoSuchFunction() throws IOException {
-    testSimpleEval("select test123('abc') col1 ", new String[]{"abc"});
+    try {
+      testSimpleEval("select test123('abc') col1 ", new String[]{"abc"});
+      fail("This test should throw NoSuchFunctionException");
+    } catch (NoSuchFunctionException e) {
+      //success
+    } catch (Exception e) {
+      fail("This test should throw NoSuchFunctionException: " + e);
+    }
   }
 
   @Test
@@ -841,10 +851,10 @@ public class TestSQLExpression extends ExprTestBase {
 
   @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()});
+    int unixtime = 1389071574;//(int) (System.currentTimeMillis() / 1000);
+    TimestampDatum expected = 
DatumFactory.createTimestmpDatumWithUnixTime(unixtime);
+    testSimpleEval(String.format("select 
to_timestamp(CAST(split_part('%d.999', '.', 1) as INT8));", unixtime),
+        new String[] {expected.asChars(TajoConf.getCurrentTimeZone(), true)});
   }
 
   @Test
@@ -856,11 +866,13 @@ public class TestSQLExpression extends ExprTestBase {
         new String[]{"123.0", "234.0"});
     testEval(schema, "table1", "123,234", "select col1::float, col2::float 
from table1",
         new String[]{"123.0", "234.0"});
+
+    TimestampDatum timestamp = DatumFactory.createTimestamp("1980-04-01 
01:50:01+09");
     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"});
+        new String[]{timestamp.asChars(TajoConf.getCurrentTimeZone(), true), 
"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;", new String [] 
{timestamp.asChars(TajoConf.getCurrentTimeZone(), true)});
     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"});

http://git-wip-us.apache.org/repos/asf/tajo/blob/526dca28/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
index 507ef61..9639bb6 100644
--- 
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
@@ -20,6 +20,8 @@ package org.apache.tajo.engine.function;
 
 
 import org.apache.tajo.catalog.Schema;
+import org.apache.tajo.conf.TajoConf;
+import org.apache.tajo.datum.DatumFactory;
 import org.apache.tajo.datum.TimestampDatum;
 import org.apache.tajo.engine.eval.ExprTestBase;
 import org.joda.time.DateTime;
@@ -30,15 +32,65 @@ 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);
+    TimestampDatum expected = 
DatumFactory.createTimestmpDatumWithUnixTime((int)(expectedTimestamp/ 1000));
 
     // (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)});
+    testSimpleEval(q1, new 
String[]{expected.toString(TajoConf.getCurrentTimeZone(), true)});
+
+    testSimpleEval("select to_timestamp('1997-12-30 11:40:50.345', 'YYYY-MM-DD 
HH24:MI:SS.MS');",
+        new String[]{"1997-12-30 11:40:50.345" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('1997-12-30 11:40:50.345 PM', 
'YYYY-MM-DD HH24:MI:SS.MS PM');",
+        new String[]{"1997-12-30 23:40:50.345" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('0097/Feb/16 --> 08:14:30', 
'YYYY/Mon/DD --> HH:MI:SS');",
+        new String[]{"0097-02-16 08:14:30" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('97/2/16 8:14:30', 'FMYYYY/FMMM/FMDD 
FMHH:FMMI:FMSS');",
+        new String[]{"0097-02-16 08:14:30" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('1985 September 12', 'YYYY FMMonth 
DD');",
+        new String[]{"1985-09-12 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('1,582nd VIII 21', 'Y,YYYth FMRM 
DD');",
+        new String[]{"1582-08-21 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('05121445482000', 
'MMDDHH24MISSYYYY');",
+        new String[]{"2000-05-12 14:45:48" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('2000January09Sunday', 
'YYYYFMMonthDDFMDay');",
+        new String[]{"2000-01-09 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('97/Feb/16', 'YY/Mon/DD');",
+        new String[]{"1997-02-16 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('19971116', 'YYYYMMDD');",
+        new String[]{"1997-11-16 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('20000-1116', 'YYYY-MMDD');",
+        new String[]{"20000-11-16 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('9-1116', 'Y-MMDD');",
+        new String[]{"2009-11-16 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('95-1116', 'YY-MMDD');",
+        new String[]{"1995-11-16 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('995-1116', 'YYY-MMDD');",
+        new String[]{"1995-11-16 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('2005426', 'YYYYWWD');",
+        new String[]{"2005-10-15 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('2005300', 'YYYYDDD');",
+        new String[]{"2005-10-27 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('2005527', 'IYYYIWID');",
+        new String[]{"2006-01-01 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('005527', 'IYYIWID');",
+        new String[]{"2006-01-01 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('05527', 'IYIWID');",
+        new String[]{"2006-01-01 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('5527', 'IIWID');",
+        new String[]{"2006-01-01 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('2005364', 'IYYYIDDD');",
+        new String[]{"2006-01-01 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('20050302', 'YYYYMMDD');",
+        new String[]{"2005-03-02 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('2005 03 02', 'YYYYMMDD');",
+        new String[]{"2005-03-02 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp(' 2005 03 02', 'YYYYMMDD');",
+        new String[]{"2005-03-02 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("select to_timestamp('  20050302', 'YYYYMMDD');",
+        new String[]{"2005-03-02 00:00:00" + getUserTimeZoneDisplay()});
   }
 
   @Test
@@ -56,14 +108,15 @@ public class TestDateTimeFunctions extends ExprTestBase {
     Schema schema2 = new Schema();
     schema2.addColumn("col1", TIMESTAMP);
     testEval(schema2, "table1",
-        "1970-01-17 10:09:37",
+        "1970-01-17 10:09:37" + getUserTimeZoneDisplay(),
         "select extract(year from col1), extract(month from col1), extract(day 
from col1) from table1;",
         new String[]{"1970.0", "1.0", "17.0"});
 
+    // Currently TIME type can be loaded with INT8 type.
     Schema schema3 = new Schema();
     schema3.addColumn("col1", TIME);
     testEval(schema3, "table1",
-        "10:09:37.5",
+        "10:09:37.5" + getUserTimeZoneDisplay(),
         "select extract(hour from col1), extract(minute from col1), 
extract(second from col1) from table1;",
         new String[]{"10.0", "9.0", "37.5"});
 
@@ -74,9 +127,9 @@ public class TestDateTimeFunctions extends ExprTestBase {
         "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 TIMESTAMP '1970-01-17 
10:09:37');", new String[]{"20.0"});
 
-    testSimpleEval("select extract(century from DATE '1970-01-17');", new 
String[]{"19.0"});
+    testSimpleEval("select extract(century from DATE '1970-01-17');", new 
String[]{"20.0"});
 
     testSimpleEval("select extract(decade from TIMESTAMP '1970-01-17 
10:09:37');", new String[]{"197.0"});
 
@@ -152,13 +205,13 @@ public class TestDateTimeFunctions extends ExprTestBase {
     Schema schema2 = new Schema();
     schema2.addColumn("col1", TIMESTAMP);
     testEval(schema2, "table1",
-        "1970-01-17 10:09:37",
+        "1970-01-17 22:09:37" + getUserTimeZoneDisplay(),
         "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",
+    testEval(schema3, "table1", "10:09:37.5" + getUserTimeZoneDisplay(),
         "select date_part('hour', col1), date_part('minute', col1), 
date_part('second', col1) from table1;",
         new String[]{"10.0", "9.0", "37.5"});
 
@@ -169,9 +222,9 @@ public class TestDateTimeFunctions extends ExprTestBase {
         "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', TIMESTAMP '1970-01-17 
10:09:37');", new String[]{"20.0"});
 
-    testSimpleEval("select date_part('century', DATE '1970-01-17');", new 
String[]{"19.0"});
+    testSimpleEval("select date_part('century', DATE '1970-01-17');", new 
String[]{"20.0"});
 
     testSimpleEval("select date_part('decade', TIMESTAMP '1970-01-17 
10:09:37');", new String[]{"197.0"});
 
@@ -253,45 +306,70 @@ public class TestDateTimeFunctions extends ExprTestBase {
 
   @Test
   public void testToDate() throws IOException {
-    testSimpleEval("select to_date('2014-01-04', 'yyyy-MM-dd')", new 
String[]{"2014-01-04"});
-    testSimpleEval("select to_date('2014-01-04', 'yyyy-MM-dd') + interval '1 
day'", new String[]{"2014-01-05 00:00:00"});
+    testSimpleEval("select to_date('2014-01-04', 'YYYY-MM-DD')", new 
String[]{"2014-01-04"});
+    testSimpleEval("select to_date('2014-01-04', 'YYYY-MM-DD') + interval '1 
day'",
+        new String[]{"2014-01-05 00:00:00" + getUserTimeZoneDisplay()});
   }
 
   @Test
   public void testAddMonths() throws Exception {
-    testSimpleEval("SELECT add_months(date '2013-12-17', 2::INT2);", new 
String[]{"2014-02-17 00:00:00"});
-    testSimpleEval("SELECT add_months(date '2013-12-17', 2::INT4);", new 
String[]{"2014-02-17 00:00:00"});
-    testSimpleEval("SELECT add_months(date '2013-12-17', 2::INT8);", new 
String[]{"2014-02-17 00:00:00"});
-
-    testSimpleEval("SELECT add_months(timestamp '2013-12-17 12:10:20', 
2::INT2);", new String[]{"2014-02-17 12:10:20"});
-    testSimpleEval("SELECT add_months(timestamp '2013-12-17 12:10:20', 
2::INT4);", new String[]{"2014-02-17 12:10:20"});
-    testSimpleEval("SELECT add_months(timestamp '2013-12-17 12:10:20', 
2::INT8);", new String[]{"2014-02-17 12:10:20"});
-
-    testSimpleEval("SELECT add_months(date '2014-02-05', -3::INT2);", new 
String[]{"2013-11-05 00:00:00"});
-    testSimpleEval("SELECT add_months(date '2014-02-05', -3::INT4);", new 
String[]{"2013-11-05 00:00:00"});
-    testSimpleEval("SELECT add_months(date '2014-02-05', -3::INT8);", new 
String[]{"2013-11-05 00:00:00"});
-
-    testSimpleEval("SELECT add_months(timestamp '2014-02-05 12:10:20', 
-3::INT2);", new String[]{"2013-11-05 12:10:20"});
-    testSimpleEval("SELECT add_months(timestamp '2014-02-05 12:10:20', 
-3::INT4);", new String[]{"2013-11-05 12:10:20"});
-    testSimpleEval("SELECT add_months(timestamp '2014-02-05 12:10:20', 
-3::INT8);", new String[]{"2013-11-05 12:10:20"});
+    testSimpleEval("SELECT add_months(date '2013-12-17', 2::INT2);",
+        new String[]{"2014-02-17 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("SELECT add_months(date '2013-12-17', 2::INT4);",
+        new String[]{"2014-02-17 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("SELECT add_months(date '2013-12-17', 2::INT8);",
+        new String[]{"2014-02-17 00:00:00" + getUserTimeZoneDisplay()});
+
+    testSimpleEval("SELECT add_months(timestamp '2013-12-17 12:10:20', 
2::INT2);",
+        new String[]{"2014-02-17 12:10:20" + getUserTimeZoneDisplay()});
+    testSimpleEval("SELECT add_months(timestamp '2013-12-17 12:10:20', 
2::INT4);",
+        new String[]{"2014-02-17 12:10:20" + getUserTimeZoneDisplay()});
+    testSimpleEval("SELECT add_months(timestamp '2013-12-17 12:10:20', 
2::INT8);",
+        new String[]{"2014-02-17 12:10:20" + getUserTimeZoneDisplay()});
+
+    testSimpleEval("SELECT add_months(date '2014-02-05', -3::INT2);",
+        new String[]{"2013-11-05 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("SELECT add_months(date '2014-02-05', -3::INT4);",
+        new String[]{"2013-11-05 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("SELECT add_months(date '2014-02-05', -3::INT8);",
+        new String[]{"2013-11-05 00:00:00" + getUserTimeZoneDisplay()});
+
+    testSimpleEval("SELECT add_months(timestamp '2014-02-05 12:10:20', 
-3::INT2);",
+        new String[]{"2013-11-05 12:10:20" + getUserTimeZoneDisplay()});
+    testSimpleEval("SELECT add_months(timestamp '2014-02-05 12:10:20', 
-3::INT4);",
+        new String[]{"2013-11-05 12:10:20" + getUserTimeZoneDisplay()});
+    testSimpleEval("SELECT add_months(timestamp '2014-02-05 12:10:20', 
-3::INT8);",
+        new String[]{"2013-11-05 12:10:20" + getUserTimeZoneDisplay()});
   }
 
   @Test
   public void testAddDays() throws IOException {
-    testSimpleEval("SELECT add_days(date '2013-12-30', 5::INT2);", new 
String[]{"2014-01-04 00:00:00"});
-    testSimpleEval("SELECT add_days(date '2013-12-30', 5::INT4);", new 
String[]{"2014-01-04 00:00:00"});
-    testSimpleEval("SELECT add_days(date '2013-12-30', 5::INT8);", new 
String[]{"2014-01-04 00:00:00"});
-
-    testSimpleEval("SELECT add_days(timestamp '2013-12-30 12:10:20', 
5::INT2);", new String[]{"2014-01-04 12:10:20"});
-    testSimpleEval("SELECT add_days(timestamp '2013-12-30 12:10:20', 
5::INT4);", new String[]{"2014-01-04 12:10:20"});
-    testSimpleEval("SELECT add_days(timestamp '2013-12-30 12:10:20', 
5::INT8);", new String[]{"2014-01-04 12:10:20"});
-
-    testSimpleEval("SELECT add_days(date '2013-12-05', -7::INT2);", new 
String[]{"2013-11-28 00:00:00"});
-    testSimpleEval("SELECT add_days(date '2013-12-05', -7::INT4);", new 
String[]{"2013-11-28 00:00:00"});
-    testSimpleEval("SELECT add_days(date '2013-12-05', -7::INT8);", new 
String[]{"2013-11-28 00:00:00"});
-
-    testSimpleEval("SELECT add_days(timestamp '2013-12-05 12:10:20', 
-7::INT2);", new String[]{"2013-11-28 12:10:20"});
-    testSimpleEval("SELECT add_days(timestamp '2013-12-05 12:10:20', 
-7::INT4);", new String[]{"2013-11-28 12:10:20"});
-    testSimpleEval("SELECT add_days(timestamp '2013-12-05 12:10:20', 
-7::INT8);", new String[]{"2013-11-28 12:10:20"});
+    testSimpleEval("SELECT add_days(date '2013-12-30', 5::INT2);",
+        new String[]{"2014-01-04 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("SELECT add_days(date '2013-12-30', 5::INT4);",
+        new String[]{"2014-01-04 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("SELECT add_days(date '2013-12-30', 5::INT8);",
+        new String[]{"2014-01-04 00:00:00" + getUserTimeZoneDisplay()});
+
+    testSimpleEval("SELECT add_days(timestamp '2013-12-30 12:10:20', 
5::INT2);",
+        new String[]{"2014-01-04 12:10:20" + getUserTimeZoneDisplay()});
+    testSimpleEval("SELECT add_days(timestamp '2013-12-30 12:10:20', 
5::INT4);",
+        new String[]{"2014-01-04 12:10:20" + getUserTimeZoneDisplay()});
+    testSimpleEval("SELECT add_days(timestamp '2013-12-30 12:10:20', 
5::INT8);",
+        new String[]{"2014-01-04 12:10:20" + getUserTimeZoneDisplay()});
+
+    testSimpleEval("SELECT add_days(date '2013-12-05', -7::INT2);",
+        new String[]{"2013-11-28 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("SELECT add_days(date '2013-12-05', -7::INT4);",
+        new String[]{"2013-11-28 00:00:00" + getUserTimeZoneDisplay()});
+    testSimpleEval("SELECT add_days(date '2013-12-05', -7::INT8);",
+        new String[]{"2013-11-28 00:00:00" + getUserTimeZoneDisplay()});
+
+    testSimpleEval("SELECT add_days(timestamp '2013-12-05 12:10:20', 
-7::INT2);",
+        new String[]{"2013-11-28 12:10:20" + getUserTimeZoneDisplay()});
+    testSimpleEval("SELECT add_days(timestamp '2013-12-05 12:10:20', 
-7::INT4);",
+        new String[]{"2013-11-28 12:10:20" + getUserTimeZoneDisplay()});
+    testSimpleEval("SELECT add_days(timestamp '2013-12-05 12:10:20', 
-7::INT8);",
+        new String[]{"2013-11-28 12:10:20" + getUserTimeZoneDisplay()});
   }
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/526dca28/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSortQuery.java
----------------------------------------------------------------------
diff --git 
a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSortQuery.java 
b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSortQuery.java
index 2f5a755..415ed49 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSortQuery.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSortQuery.java
@@ -21,10 +21,12 @@ package org.apache.tajo.engine.query;
 import org.apache.tajo.IntegrationTest;
 import org.apache.tajo.QueryTestCaseBase;
 import org.apache.tajo.TajoConstants;
+import org.apache.tajo.conf.TajoConf;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
 import java.sql.ResultSet;
+import java.util.TimeZone;
 
 @Category(IntegrationTest.class)
 public class TestSortQuery extends QueryTestCaseBase {
@@ -117,13 +119,18 @@ public class TestSortQuery extends QueryTestCaseBase {
   public final void testSortWithDate() throws Exception {
     // skip this test if catalog uses HCatalogStore.
     // It is because HCatalogStore does not support Time data type.
-    if (!testingCluster.isHCatalogStoreRunning()) {
-      // create external table table1 (col1 timestamp, col2 date, col3 time) 
...
-      executeDDL("create_table_with_date_ddl.sql", "table1");
-
-      ResultSet res = executeQuery();
-      assertResultSet(res);
-      cleanupQuery(res);
+    TimeZone oldTimeZone = 
TajoConf.setCurrentTimeZone(TimeZone.getTimeZone("UTC"));
+    try {
+      if (!testingCluster.isHCatalogStoreRunning()) {
+        // create external table table1 (col1 timestamp, col2 date, col3 time) 
...
+        executeDDL("create_table_with_date_ddl.sql", "table1");
+
+        ResultSet res = executeQuery();
+        assertResultSet(res);
+        cleanupQuery(res);
+      }
+    } finally {
+      TajoConf.setCurrentTimeZone(oldTimeZone);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/526dca28/tajo-storage/src/main/java/org/apache/tajo/storage/TextSerializerDeserializer.java
----------------------------------------------------------------------
diff --git 
a/tajo-storage/src/main/java/org/apache/tajo/storage/TextSerializerDeserializer.java
 
b/tajo-storage/src/main/java/org/apache/tajo/storage/TextSerializerDeserializer.java
index 41ee720..ad732c7 100644
--- 
a/tajo-storage/src/main/java/org/apache/tajo/storage/TextSerializerDeserializer.java
+++ 
b/tajo-storage/src/main/java/org/apache/tajo/storage/TextSerializerDeserializer.java
@@ -22,6 +22,7 @@ import com.google.protobuf.Message;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.tajo.catalog.Column;
 import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.conf.TajoConf;
 import org.apache.tajo.datum.*;
 import org.apache.tajo.datum.protobuf.ProtobufJsonFormat;
 import org.apache.tajo.util.Bytes;
@@ -77,13 +78,21 @@ public class TextSerializerDeserializer implements 
SerializerDeserializer {
       case FLOAT8:
       case INET4:
       case DATE:
-      case TIME:
-      case TIMESTAMP:
       case INTERVAL:
         bytes = datum.asTextBytes();
         length = bytes.length;
         out.write(bytes);
         break;
+      case TIME:
+        bytes = ((TimeDatum)datum).asChars(TajoConf.getCurrentTimeZone(), 
true).getBytes();
+        length = bytes.length;
+        out.write(bytes);
+        break;
+      case TIMESTAMP:
+        bytes = ((TimestampDatum)datum).asChars(TajoConf.getCurrentTimeZone(), 
true).getBytes();
+        length = bytes.length;
+        out.write(bytes);
+        break;
       case INET6:
       case BLOB:
         bytes = Base64.encodeBase64(datum.asByteArray(), false);
@@ -158,7 +167,7 @@ public class TextSerializerDeserializer implements 
SerializerDeserializer {
         break;
       case TIMESTAMP:
         datum = isNull(bytes, offset, length, nullCharacters) ? NullDatum.get()
-            : DatumFactory.createTimeStamp(new String(bytes, offset, length));
+            : DatumFactory.createTimestamp(new String(bytes, offset, length));
         break;
       case INTERVAL:
         datum = isNull(bytes, offset, length, nullCharacters) ? NullDatum.get()

http://git-wip-us.apache.org/repos/asf/tajo/blob/526dca28/tajo-storage/src/test/java/org/apache/tajo/storage/TestStorages.java
----------------------------------------------------------------------
diff --git 
a/tajo-storage/src/test/java/org/apache/tajo/storage/TestStorages.java 
b/tajo-storage/src/test/java/org/apache/tajo/storage/TestStorages.java
index 0b764cc..944aa5c 100644
--- a/tajo-storage/src/test/java/org/apache/tajo/storage/TestStorages.java
+++ b/tajo-storage/src/test/java/org/apache/tajo/storage/TestStorages.java
@@ -683,7 +683,7 @@ public class TestStorages {
       tuple.put(new Datum[]{
           DatumFactory.createDate("1980-04-01"),
           DatumFactory.createTime("12:34:56"),
-          DatumFactory.createTimeStamp((int) System.currentTimeMillis() / 1000)
+          
DatumFactory.createTimestmpDatumWithUnixTime((int)(System.currentTimeMillis() / 
1000))
       });
       appender.addTuple(tuple);
       appender.flush();

Reply via email to