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/70dc3836 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/70dc3836 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/70dc3836 Branch: refs/heads/calcite Commit: 70dc3836ac4d472bb55e79a723a1d2a1d30d75de Parents: e23634a Author: Josh Elser <els...@apache.org> Authored: Wed Nov 9 13:30:15 2016 -0500 Committer: Josh Elser <els...@apache.org> Committed: Sun Dec 25 21:44:03 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/70dc3836/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/70dc3836/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 {