phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [3/7] phoenix git commit: PHOENIX-32451 Support DATE and TIMESTAMP in CONVERT_TZ()
Date Mon, 26 Dec 2016 03:22:44 GMT
PHOENIX-32451 Support DATE and TIMESTAMP in CONVERT_TZ()


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/b477e541
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/b477e541
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/b477e541

Branch: refs/heads/4.x-HBase-0.98
Commit: b477e5410e7ea9ffc79908e3d7368ca84462e497
Parents: 54b7c21
Author: Josh Elser <elserj@apache.org>
Authored: Wed Nov 9 13:30:15 2016 -0500
Committer: Josh Elser <elserj@apache.org>
Committed: Sun Dec 25 21:53:22 2016 -0500

----------------------------------------------------------------------
 .../end2end/ConvertTimezoneFunctionIT.java      | 22 +++++++++++++++++++-
 .../function/ConvertTimezoneFunction.java       |  5 +++--
 2 files changed, 24 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/b477e541/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConvertTimezoneFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConvertTimezoneFunctionIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConvertTimezoneFunctionIT.java
index 229e705..a51b6c9 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConvertTimezoneFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConvertTimezoneFunctionIT.java
@@ -39,7 +39,7 @@ import org.junit.Test;
 public class ConvertTimezoneFunctionIT extends ParallelStatsDisabledIT {
 
     @Test
-    public void testConvertTimezoneEurope() throws Exception {
+    public void testDateConvertTimezoneEurope() throws Exception {
         Connection conn = DriverManager.getConnection(getUrl());
         String timezone_offset_test = generateUniqueName();
         String ddl = "CREATE TABLE IF NOT EXISTS " + timezone_offset_test
@@ -59,6 +59,26 @@ public class ConvertTimezoneFunctionIT extends ParallelStatsDisabledIT
{
     }
 
     @Test
+    public void testTimestampConvertTimezoneEurope() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        String timezone_offset_test = generateUniqueName();
+        String ddl = "CREATE TABLE IF NOT EXISTS " + timezone_offset_test
+            + " (k1 INTEGER NOT NULL, timestamps TIMESTAMP CONSTRAINT pk PRIMARY KEY (k1))";
+        conn.createStatement().execute(ddl);
+        String dml = "UPSERT INTO " + timezone_offset_test
+            + " (k1, timestamps) VALUES (1, TO_TIMESTAMP('2014-03-01 00:00:00'))";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery(
+            "SELECT k1, timestamps, CONVERT_TZ(timestamps, 'UTC', 'Europe/Prague') FROM "
+                + timezone_offset_test);
+
+        assertTrue(rs.next());
+        assertEquals(1393635600000L, rs.getDate(3).getTime()); //Sat, 01 Mar 2014 01:00:00
+    }
+
+    @Test
     public void testConvertTimezoneAmerica() throws Exception {
         Connection conn = DriverManager.getConnection(getUrl());
         String timezone_offset_test = generateUniqueName();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b477e541/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ConvertTimezoneFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ConvertTimezoneFunction.java
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ConvertTimezoneFunction.java
index f06ddbc..8d13ab6 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ConvertTimezoneFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ConvertTimezoneFunction.java
@@ -23,10 +23,11 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.cache.JodaTimezoneCache;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.parse.FunctionParseNode;
+import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PTimestamp;
 import org.apache.phoenix.schema.types.PVarchar;
-import org.apache.phoenix.schema.tuple.Tuple;
 import org.joda.time.DateTimeZone;
 
 /**
@@ -35,7 +36,7 @@ import org.joda.time.DateTimeZone;
  *
  */
 @FunctionParseNode.BuiltInFunction(name = ConvertTimezoneFunction.NAME, args = {
-    @FunctionParseNode.Argument(allowedTypes = { PDate.class }),
+    @FunctionParseNode.Argument(allowedTypes = { PTimestamp.class }),
     @FunctionParseNode.Argument(allowedTypes = { PVarchar.class }),
     @FunctionParseNode.Argument(allowedTypes = { PVarchar.class })})
 public class ConvertTimezoneFunction extends ScalarFunction {


Mime
View raw message