git commit: PHOENIX-1043 Add timezone conversion function
Repository: phoenix Updated Branches: refs/heads/4.0 d59c1e56b -> cdf9521c9 PHOENIX-1043 Add timezone conversion function Contributed by Vaclav Loffelmann Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/cdf9521c Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/cdf9521c Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/cdf9521c Branch: refs/heads/4.0 Commit: cdf9521c9847bcb4e88495b1e1dd95459ee3984b Parents: d59c1e5 Author: Gabriel Reid Authored: Sat Jun 14 22:37:34 2014 +0200 Committer: Gabriel Reid Committed: Sat Jun 14 22:53:26 2014 +0200 -- .../end2end/ConvertTimezoneFunctionIT.java | 132 +++ .../phoenix/expression/ExpressionType.java | 2 + .../function/ConvertTimezoneFunction.java | 101 ++ 3 files changed, 235 insertions(+) -- http://git-wip-us.apache.org/repos/asf/phoenix/blob/cdf9521c/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 new file mode 100644 index 000..4cdf6ac --- /dev/null +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConvertTimezoneFunctionIT.java @@ -0,0 +1,132 @@ +/* + * Copyright 2014 Apache Software Foundation. + * + * Licensed 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.phoenix.end2end; + +import static org.junit.Assert.assertEquals; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import org.apache.phoenix.schema.IllegalDataException; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import org.junit.Test; + +/** + * CONVERT_TZ(date, 'from_timezone', 'to_timezone') tests + * + */ +public class ConvertTimezoneFunctionIT extends BaseHBaseManagedTimeIT { + +@Test +public void testConvertTimezoneEurope() throws Exception { +Connection conn = DriverManager.getConnection(getUrl()); +String ddl = "CREATE TABLE IF NOT EXISTS TIMEZONE_OFFSET_TEST (k1 INTEGER NOT NULL, dates DATE CONSTRAINT pk PRIMARY KEY (k1))"; +conn.createStatement().execute(ddl); +String dml = "UPSERT INTO TIMEZONE_OFFSET_TEST (k1, dates) VALUES (1, TO_DATE('2014-03-01 00:00:00'))"; +conn.createStatement().execute(dml); +conn.commit(); + +ResultSet rs = conn.createStatement().executeQuery( +"SELECT k1, dates, CONVERT_TZ(dates, 'UTC', 'Europe/Prague') FROM TIMEZONE_OFFSET_TEST"); + +assertTrue(rs.next()); +assertEquals(139363560L, rs.getDate(3).getTime()); //Sat, 01 Mar 2014 01:00:00 +} + +@Test +public void testConvertTimezoneAmerica() throws Exception { +Connection conn = DriverManager.getConnection(getUrl()); +String ddl = "CREATE TABLE IF NOT EXISTS TIMEZONE_OFFSET_TEST (k1 INTEGER NOT NULL, dates DATE CONSTRAINT pk PRIMARY KEY (k1))"; +conn.createStatement().execute(ddl); +String dml = "UPSERT INTO TIMEZONE_OFFSET_TEST (k1, dates) VALUES (1, TO_DATE('2014-03-01 00:00:00'))"; +conn.createStatement().execute(dml); +conn.commit(); + +ResultSet rs = conn.createStatement().executeQuery( +"SELECT k1, dates, CONVERT_TZ(dates, 'UTC', 'America/Adak') FROM TIMEZONE_OFFSET_TEST"); + +assertTrue(rs.next()); +assertEquals(139359600L, rs.getDate(3).getTime()); //Fri, 28 Feb 2014 14:00:00 +} + +@Test +public void nullInDateParameter() throws Exception { +Connection conn = DriverManager.getConnection(getUrl()); +String ddl = "CREATE TABLE IF NOT EXISTS TIMEZONE_OFFSET_TEST (k1 INTEGER NOT NULL, dates DATE CONSTRAINT pk PRIMARY KEY (k1))"; +conn.createStatement().execute(ddl); +String dml = "UPSERT INTO TIMEZONE_OFFSET_TEST (k1) VALUES (1)"; +conn.createStatement().execute(dml); +conn.commit(); + +ResultSet rs = conn.createStatement().executeQuery( +"SELECT k1, dates, CONVERT_TZ(dates, 'UTC', 'America/Adak') FROM TIMEZONE_OFFSET_TEST"); + +assertTrue(
git commit: PHOENIX-1043 Add timezone conversion function
Repository: phoenix Updated Branches: refs/heads/3.0 d29254079 -> e4218a99c PHOENIX-1043 Add timezone conversion function Contributed by Vaclav Loffelmann Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/e4218a99 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/e4218a99 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/e4218a99 Branch: refs/heads/3.0 Commit: e4218a99c870f50772be51fe94d35f53d414cf63 Parents: d292540 Author: Gabriel Reid Authored: Sat Jun 14 22:37:34 2014 +0200 Committer: Gabriel Reid Committed: Sat Jun 14 22:52:20 2014 +0200 -- .../end2end/ConvertTimezoneFunctionIT.java | 132 +++ .../phoenix/expression/ExpressionType.java | 2 + .../function/ConvertTimezoneFunction.java | 101 ++ 3 files changed, 235 insertions(+) -- http://git-wip-us.apache.org/repos/asf/phoenix/blob/e4218a99/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 new file mode 100644 index 000..4cdf6ac --- /dev/null +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConvertTimezoneFunctionIT.java @@ -0,0 +1,132 @@ +/* + * Copyright 2014 Apache Software Foundation. + * + * Licensed 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.phoenix.end2end; + +import static org.junit.Assert.assertEquals; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import org.apache.phoenix.schema.IllegalDataException; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import org.junit.Test; + +/** + * CONVERT_TZ(date, 'from_timezone', 'to_timezone') tests + * + */ +public class ConvertTimezoneFunctionIT extends BaseHBaseManagedTimeIT { + +@Test +public void testConvertTimezoneEurope() throws Exception { +Connection conn = DriverManager.getConnection(getUrl()); +String ddl = "CREATE TABLE IF NOT EXISTS TIMEZONE_OFFSET_TEST (k1 INTEGER NOT NULL, dates DATE CONSTRAINT pk PRIMARY KEY (k1))"; +conn.createStatement().execute(ddl); +String dml = "UPSERT INTO TIMEZONE_OFFSET_TEST (k1, dates) VALUES (1, TO_DATE('2014-03-01 00:00:00'))"; +conn.createStatement().execute(dml); +conn.commit(); + +ResultSet rs = conn.createStatement().executeQuery( +"SELECT k1, dates, CONVERT_TZ(dates, 'UTC', 'Europe/Prague') FROM TIMEZONE_OFFSET_TEST"); + +assertTrue(rs.next()); +assertEquals(139363560L, rs.getDate(3).getTime()); //Sat, 01 Mar 2014 01:00:00 +} + +@Test +public void testConvertTimezoneAmerica() throws Exception { +Connection conn = DriverManager.getConnection(getUrl()); +String ddl = "CREATE TABLE IF NOT EXISTS TIMEZONE_OFFSET_TEST (k1 INTEGER NOT NULL, dates DATE CONSTRAINT pk PRIMARY KEY (k1))"; +conn.createStatement().execute(ddl); +String dml = "UPSERT INTO TIMEZONE_OFFSET_TEST (k1, dates) VALUES (1, TO_DATE('2014-03-01 00:00:00'))"; +conn.createStatement().execute(dml); +conn.commit(); + +ResultSet rs = conn.createStatement().executeQuery( +"SELECT k1, dates, CONVERT_TZ(dates, 'UTC', 'America/Adak') FROM TIMEZONE_OFFSET_TEST"); + +assertTrue(rs.next()); +assertEquals(139359600L, rs.getDate(3).getTime()); //Fri, 28 Feb 2014 14:00:00 +} + +@Test +public void nullInDateParameter() throws Exception { +Connection conn = DriverManager.getConnection(getUrl()); +String ddl = "CREATE TABLE IF NOT EXISTS TIMEZONE_OFFSET_TEST (k1 INTEGER NOT NULL, dates DATE CONSTRAINT pk PRIMARY KEY (k1))"; +conn.createStatement().execute(ddl); +String dml = "UPSERT INTO TIMEZONE_OFFSET_TEST (k1) VALUES (1)"; +conn.createStatement().execute(dml); +conn.commit(); + +ResultSet rs = conn.createStatement().executeQuery( +"SELECT k1, dates, CONVERT_TZ(dates, 'UTC', 'America/Adak') FROM TIMEZONE_OFFSET_TEST"); + +assertTrue(
git commit: PHOENIX-1043 Add timezone conversion function
Repository: phoenix Updated Branches: refs/heads/master 58b2a79e5 -> 6506dadfe PHOENIX-1043 Add timezone conversion function Contributed by Vaclav Loffelmann Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/6506dadf Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/6506dadf Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/6506dadf Branch: refs/heads/master Commit: 6506dadfea6e19f04e9d83d9313455be2b912377 Parents: 58b2a79 Author: Gabriel Reid Authored: Sat Jun 14 22:37:34 2014 +0200 Committer: Gabriel Reid Committed: Sat Jun 14 22:54:35 2014 +0200 -- .../end2end/ConvertTimezoneFunctionIT.java | 132 +++ .../phoenix/expression/ExpressionType.java | 2 + .../function/ConvertTimezoneFunction.java | 101 ++ 3 files changed, 235 insertions(+) -- http://git-wip-us.apache.org/repos/asf/phoenix/blob/6506dadf/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 new file mode 100644 index 000..4cdf6ac --- /dev/null +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConvertTimezoneFunctionIT.java @@ -0,0 +1,132 @@ +/* + * Copyright 2014 Apache Software Foundation. + * + * Licensed 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.phoenix.end2end; + +import static org.junit.Assert.assertEquals; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import org.apache.phoenix.schema.IllegalDataException; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import org.junit.Test; + +/** + * CONVERT_TZ(date, 'from_timezone', 'to_timezone') tests + * + */ +public class ConvertTimezoneFunctionIT extends BaseHBaseManagedTimeIT { + +@Test +public void testConvertTimezoneEurope() throws Exception { +Connection conn = DriverManager.getConnection(getUrl()); +String ddl = "CREATE TABLE IF NOT EXISTS TIMEZONE_OFFSET_TEST (k1 INTEGER NOT NULL, dates DATE CONSTRAINT pk PRIMARY KEY (k1))"; +conn.createStatement().execute(ddl); +String dml = "UPSERT INTO TIMEZONE_OFFSET_TEST (k1, dates) VALUES (1, TO_DATE('2014-03-01 00:00:00'))"; +conn.createStatement().execute(dml); +conn.commit(); + +ResultSet rs = conn.createStatement().executeQuery( +"SELECT k1, dates, CONVERT_TZ(dates, 'UTC', 'Europe/Prague') FROM TIMEZONE_OFFSET_TEST"); + +assertTrue(rs.next()); +assertEquals(139363560L, rs.getDate(3).getTime()); //Sat, 01 Mar 2014 01:00:00 +} + +@Test +public void testConvertTimezoneAmerica() throws Exception { +Connection conn = DriverManager.getConnection(getUrl()); +String ddl = "CREATE TABLE IF NOT EXISTS TIMEZONE_OFFSET_TEST (k1 INTEGER NOT NULL, dates DATE CONSTRAINT pk PRIMARY KEY (k1))"; +conn.createStatement().execute(ddl); +String dml = "UPSERT INTO TIMEZONE_OFFSET_TEST (k1, dates) VALUES (1, TO_DATE('2014-03-01 00:00:00'))"; +conn.createStatement().execute(dml); +conn.commit(); + +ResultSet rs = conn.createStatement().executeQuery( +"SELECT k1, dates, CONVERT_TZ(dates, 'UTC', 'America/Adak') FROM TIMEZONE_OFFSET_TEST"); + +assertTrue(rs.next()); +assertEquals(139359600L, rs.getDate(3).getTime()); //Fri, 28 Feb 2014 14:00:00 +} + +@Test +public void nullInDateParameter() throws Exception { +Connection conn = DriverManager.getConnection(getUrl()); +String ddl = "CREATE TABLE IF NOT EXISTS TIMEZONE_OFFSET_TEST (k1 INTEGER NOT NULL, dates DATE CONSTRAINT pk PRIMARY KEY (k1))"; +conn.createStatement().execute(ddl); +String dml = "UPSERT INTO TIMEZONE_OFFSET_TEST (k1) VALUES (1)"; +conn.createStatement().execute(dml); +conn.commit(); + +ResultSet rs = conn.createStatement().executeQuery( +"SELECT k1, dates, CONVERT_TZ(dates, 'UTC', 'America/Adak') FROM TIMEZONE_OFFSET_TEST"); + +asser