[phoenix] 30/34: PHOENIX-4822 Ensure the provided timezone is used client-side (Jaanai Zhang)
This is an automated email from the ASF dual-hosted git repository. tdsilva pushed a commit to branch 4.14-HBase-1.4 in repository https://gitbox.apache.org/repos/asf/phoenix.git commit 1777c54eee6bbb21144d91f3d936c968e3af614e Author: Josh Elser AuthorDate: Tue Jul 31 15:53:11 2018 -0400 PHOENIX-4822 Ensure the provided timezone is used client-side (Jaanai Zhang) --- .../org/apache/phoenix/end2end/DateTimeIT.java | 77 ++ .../apache/phoenix/compile/StatementContext.java | 11 ++-- .../org/apache/phoenix/jdbc/PhoenixConnection.java | 8 ++- .../java/org/apache/phoenix/util/DateUtil.java | 22 --- 4 files changed, 101 insertions(+), 17 deletions(-) diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java index c976114..cc7c7a7 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java @@ -54,12 +54,19 @@ import java.text.Format; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.Properties; +import java.util.TimeZone; +import org.apache.commons.lang.time.FastDateFormat; import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp; import org.apache.hadoop.hbase.io.ImmutableBytesWritable; import org.apache.hadoop.hbase.util.Bytes; +import org.apache.phoenix.compile.StatementContext; +import org.apache.phoenix.jdbc.PhoenixConnection; +import org.apache.phoenix.jdbc.PhoenixStatement; import org.apache.phoenix.query.QueryConstants; +import org.apache.phoenix.schema.types.PDataType; import org.apache.phoenix.schema.types.PDate; +import org.apache.phoenix.schema.types.PTime; import org.apache.phoenix.schema.types.PTimestamp; import org.apache.phoenix.util.ByteUtil; import org.apache.phoenix.util.DateUtil; @@ -1880,4 +1887,74 @@ public class DateTimeIT extends ParallelStatsDisabledIT { conn.close(); } } + +@Test +public void testDateFormatTimeZone()throws Exception { +String[] timeZoneIDs = {DateUtil.DEFAULT_TIME_ZONE_ID, "Asia/Yerevan", "Australia/Adelaide", "Asia/Tokyo"}; +for (String timeZoneID : timeZoneIDs) { +testDateFormatTimeZone(timeZoneID); +} +} + +public void testDateFormatTimeZone(String timeZoneId) throws Exception { +Properties props = new Properties(); +props.setProperty("phoenix.query.dateFormatTimeZone", timeZoneId); +Connection conn1 = DriverManager.getConnection(getUrl(), props); + +String tableName = generateUniqueName(); +String ddl = "CREATE TABLE IF NOT EXISTS " + tableName + +" (k1 INTEGER PRIMARY KEY," + +" v_date DATE," + +" v_time TIME," + +" v_timestamp TIMESTAMP)"; +try { +conn1.createStatement().execute(ddl); + +PhoenixConnection pConn = conn1.unwrap(PhoenixConnection.class); +verifyTimeZoneIDWithConn(pConn, PDate.INSTANCE, timeZoneId); +verifyTimeZoneIDWithConn(pConn, PTime.INSTANCE, timeZoneId); +verifyTimeZoneIDWithConn(pConn, PTimestamp.INSTANCE, timeZoneId); + +Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(timeZoneId)); +cal.setTime(date); +String dateStr = DateUtil.getDateFormatter(DateUtil.DEFAULT_MS_DATE_FORMAT).format(date); + +String dml = "UPSERT INTO " + tableName + " VALUES (" + +"1," + +"'" + dateStr + "'," + +"'" + dateStr + "'," + +"'" + dateStr + "'" + +")"; +conn1.createStatement().execute(dml); +conn1.commit(); + +PhoenixStatement stmt = conn1.createStatement().unwrap(PhoenixStatement.class); +ResultSet rs = stmt.executeQuery("SELECT v_date, v_time, v_timestamp FROM " + tableName); + +assertTrue(rs.next()); +assertEquals(rs.getDate(1).toString(), new Date(cal.getTimeInMillis()).toString()); +assertEquals(rs.getTime(2).toString(), new Time(cal.getTimeInMillis()).toString()); +assertEquals(rs.getTimestamp(3).getTime(), cal.getTimeInMillis()); +assertFalse(rs.next()); + +StatementContext stmtContext = stmt.getQueryPlan().getContext(); +verifyTimeZoneIDWithFormatter(stmtContext.getDateFormatter(), timeZoneId); +verifyTimeZoneIDWithFormatter(stmtContext.getTimeFormatter(), timeZoneId); +verifyTimeZoneIDWithFormatter(stmtContext.getTimestampFormatter(), timeZoneId); + +stmt.close(); +} finally { +conn1.close(); +} +} + +private void verifyTimeZoneIDWithConn(PhoenixConnection conn, PDataType dataType, String timeZoneId) { +Format formatter = conn.getFormatter(dataType); +
[phoenix] 30/34: PHOENIX-4822 Ensure the provided timezone is used client-side (Jaanai Zhang)
This is an automated email from the ASF dual-hosted git repository. tdsilva pushed a commit to branch 4.14-HBase-1.2 in repository https://gitbox.apache.org/repos/asf/phoenix.git commit 7a6daf0fcb88214f1273aa3e160f13db84036ffe Author: Josh Elser AuthorDate: Tue Jul 31 15:53:11 2018 -0400 PHOENIX-4822 Ensure the provided timezone is used client-side (Jaanai Zhang) --- .../org/apache/phoenix/end2end/DateTimeIT.java | 77 ++ .../apache/phoenix/compile/StatementContext.java | 11 ++-- .../org/apache/phoenix/jdbc/PhoenixConnection.java | 8 ++- .../java/org/apache/phoenix/util/DateUtil.java | 22 --- 4 files changed, 101 insertions(+), 17 deletions(-) diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java index c976114..cc7c7a7 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java @@ -54,12 +54,19 @@ import java.text.Format; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.Properties; +import java.util.TimeZone; +import org.apache.commons.lang.time.FastDateFormat; import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp; import org.apache.hadoop.hbase.io.ImmutableBytesWritable; import org.apache.hadoop.hbase.util.Bytes; +import org.apache.phoenix.compile.StatementContext; +import org.apache.phoenix.jdbc.PhoenixConnection; +import org.apache.phoenix.jdbc.PhoenixStatement; import org.apache.phoenix.query.QueryConstants; +import org.apache.phoenix.schema.types.PDataType; import org.apache.phoenix.schema.types.PDate; +import org.apache.phoenix.schema.types.PTime; import org.apache.phoenix.schema.types.PTimestamp; import org.apache.phoenix.util.ByteUtil; import org.apache.phoenix.util.DateUtil; @@ -1880,4 +1887,74 @@ public class DateTimeIT extends ParallelStatsDisabledIT { conn.close(); } } + +@Test +public void testDateFormatTimeZone()throws Exception { +String[] timeZoneIDs = {DateUtil.DEFAULT_TIME_ZONE_ID, "Asia/Yerevan", "Australia/Adelaide", "Asia/Tokyo"}; +for (String timeZoneID : timeZoneIDs) { +testDateFormatTimeZone(timeZoneID); +} +} + +public void testDateFormatTimeZone(String timeZoneId) throws Exception { +Properties props = new Properties(); +props.setProperty("phoenix.query.dateFormatTimeZone", timeZoneId); +Connection conn1 = DriverManager.getConnection(getUrl(), props); + +String tableName = generateUniqueName(); +String ddl = "CREATE TABLE IF NOT EXISTS " + tableName + +" (k1 INTEGER PRIMARY KEY," + +" v_date DATE," + +" v_time TIME," + +" v_timestamp TIMESTAMP)"; +try { +conn1.createStatement().execute(ddl); + +PhoenixConnection pConn = conn1.unwrap(PhoenixConnection.class); +verifyTimeZoneIDWithConn(pConn, PDate.INSTANCE, timeZoneId); +verifyTimeZoneIDWithConn(pConn, PTime.INSTANCE, timeZoneId); +verifyTimeZoneIDWithConn(pConn, PTimestamp.INSTANCE, timeZoneId); + +Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(timeZoneId)); +cal.setTime(date); +String dateStr = DateUtil.getDateFormatter(DateUtil.DEFAULT_MS_DATE_FORMAT).format(date); + +String dml = "UPSERT INTO " + tableName + " VALUES (" + +"1," + +"'" + dateStr + "'," + +"'" + dateStr + "'," + +"'" + dateStr + "'" + +")"; +conn1.createStatement().execute(dml); +conn1.commit(); + +PhoenixStatement stmt = conn1.createStatement().unwrap(PhoenixStatement.class); +ResultSet rs = stmt.executeQuery("SELECT v_date, v_time, v_timestamp FROM " + tableName); + +assertTrue(rs.next()); +assertEquals(rs.getDate(1).toString(), new Date(cal.getTimeInMillis()).toString()); +assertEquals(rs.getTime(2).toString(), new Time(cal.getTimeInMillis()).toString()); +assertEquals(rs.getTimestamp(3).getTime(), cal.getTimeInMillis()); +assertFalse(rs.next()); + +StatementContext stmtContext = stmt.getQueryPlan().getContext(); +verifyTimeZoneIDWithFormatter(stmtContext.getDateFormatter(), timeZoneId); +verifyTimeZoneIDWithFormatter(stmtContext.getTimeFormatter(), timeZoneId); +verifyTimeZoneIDWithFormatter(stmtContext.getTimestampFormatter(), timeZoneId); + +stmt.close(); +} finally { +conn1.close(); +} +} + +private void verifyTimeZoneIDWithConn(PhoenixConnection conn, PDataType dataType, String timeZoneId) { +Format formatter = conn.getFormatter(dataType); +
[phoenix] 30/34: PHOENIX-4822 Ensure the provided timezone is used client-side (Jaanai Zhang)
This is an automated email from the ASF dual-hosted git repository. tdsilva pushed a commit to branch 4.14-HBase-1.3 in repository https://gitbox.apache.org/repos/asf/phoenix.git commit 9a153c59bd527de9f857fd6974471cd2d781fd7c Author: Josh Elser AuthorDate: Tue Jul 31 15:53:11 2018 -0400 PHOENIX-4822 Ensure the provided timezone is used client-side (Jaanai Zhang) --- .../org/apache/phoenix/end2end/DateTimeIT.java | 77 ++ .../apache/phoenix/compile/StatementContext.java | 11 ++-- .../org/apache/phoenix/jdbc/PhoenixConnection.java | 8 ++- .../java/org/apache/phoenix/util/DateUtil.java | 22 --- 4 files changed, 101 insertions(+), 17 deletions(-) diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java index c976114..cc7c7a7 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java @@ -54,12 +54,19 @@ import java.text.Format; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.Properties; +import java.util.TimeZone; +import org.apache.commons.lang.time.FastDateFormat; import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp; import org.apache.hadoop.hbase.io.ImmutableBytesWritable; import org.apache.hadoop.hbase.util.Bytes; +import org.apache.phoenix.compile.StatementContext; +import org.apache.phoenix.jdbc.PhoenixConnection; +import org.apache.phoenix.jdbc.PhoenixStatement; import org.apache.phoenix.query.QueryConstants; +import org.apache.phoenix.schema.types.PDataType; import org.apache.phoenix.schema.types.PDate; +import org.apache.phoenix.schema.types.PTime; import org.apache.phoenix.schema.types.PTimestamp; import org.apache.phoenix.util.ByteUtil; import org.apache.phoenix.util.DateUtil; @@ -1880,4 +1887,74 @@ public class DateTimeIT extends ParallelStatsDisabledIT { conn.close(); } } + +@Test +public void testDateFormatTimeZone()throws Exception { +String[] timeZoneIDs = {DateUtil.DEFAULT_TIME_ZONE_ID, "Asia/Yerevan", "Australia/Adelaide", "Asia/Tokyo"}; +for (String timeZoneID : timeZoneIDs) { +testDateFormatTimeZone(timeZoneID); +} +} + +public void testDateFormatTimeZone(String timeZoneId) throws Exception { +Properties props = new Properties(); +props.setProperty("phoenix.query.dateFormatTimeZone", timeZoneId); +Connection conn1 = DriverManager.getConnection(getUrl(), props); + +String tableName = generateUniqueName(); +String ddl = "CREATE TABLE IF NOT EXISTS " + tableName + +" (k1 INTEGER PRIMARY KEY," + +" v_date DATE," + +" v_time TIME," + +" v_timestamp TIMESTAMP)"; +try { +conn1.createStatement().execute(ddl); + +PhoenixConnection pConn = conn1.unwrap(PhoenixConnection.class); +verifyTimeZoneIDWithConn(pConn, PDate.INSTANCE, timeZoneId); +verifyTimeZoneIDWithConn(pConn, PTime.INSTANCE, timeZoneId); +verifyTimeZoneIDWithConn(pConn, PTimestamp.INSTANCE, timeZoneId); + +Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(timeZoneId)); +cal.setTime(date); +String dateStr = DateUtil.getDateFormatter(DateUtil.DEFAULT_MS_DATE_FORMAT).format(date); + +String dml = "UPSERT INTO " + tableName + " VALUES (" + +"1," + +"'" + dateStr + "'," + +"'" + dateStr + "'," + +"'" + dateStr + "'" + +")"; +conn1.createStatement().execute(dml); +conn1.commit(); + +PhoenixStatement stmt = conn1.createStatement().unwrap(PhoenixStatement.class); +ResultSet rs = stmt.executeQuery("SELECT v_date, v_time, v_timestamp FROM " + tableName); + +assertTrue(rs.next()); +assertEquals(rs.getDate(1).toString(), new Date(cal.getTimeInMillis()).toString()); +assertEquals(rs.getTime(2).toString(), new Time(cal.getTimeInMillis()).toString()); +assertEquals(rs.getTimestamp(3).getTime(), cal.getTimeInMillis()); +assertFalse(rs.next()); + +StatementContext stmtContext = stmt.getQueryPlan().getContext(); +verifyTimeZoneIDWithFormatter(stmtContext.getDateFormatter(), timeZoneId); +verifyTimeZoneIDWithFormatter(stmtContext.getTimeFormatter(), timeZoneId); +verifyTimeZoneIDWithFormatter(stmtContext.getTimestampFormatter(), timeZoneId); + +stmt.close(); +} finally { +conn1.close(); +} +} + +private void verifyTimeZoneIDWithConn(PhoenixConnection conn, PDataType dataType, String timeZoneId) { +Format formatter = conn.getFormatter(dataType); +