From 757f037019fb955994274d5da180fbe232843239 Mon Sep 17 00:00:00 2001 From: hezhao2 Date: Mon, 13 Nov 2023 14:46:09 +0800 Subject: [PATCH 01/13] JDBC driver implements Result#getDate with Calendar --- .../jdbc/hive/KyuubiArrowBasedResultSet.java | 27 ++++++++++++++++++ .../kyuubi/jdbc/hive/KyuubiBaseResultSet.java | 28 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java index ef5008503aa..08af07aca69 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java @@ -23,6 +23,7 @@ import java.math.MathContext; import java.nio.charset.StandardCharsets; import java.sql.*; +import java.util.Calendar; import java.util.List; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.VectorSchemaRoot; @@ -198,6 +199,32 @@ public Date getDate(String columnName) throws SQLException { return getDate(findColumn(columnName)); } + public Date getDate(int columnIndex, Calendar cal) throws SQLException { + Date value = getDate(columnIndex); + if (value == null) { + return null; + } else { + try { + return parseDate(value, cal); + } catch (IllegalArgumentException e) { + throw new KyuubiSQLException("Cannot convert column " + columnIndex + " to date: " + e, e); + } + } + } + + @Override + public Date getDate(String columnLabel, Calendar cal) throws SQLException { + return this.getDate(findColumn(columnLabel), cal); + } + + private Date parseDate(Date value, Calendar cal) { + if (cal == null) { + cal = Calendar.getInstance(); + } + cal.setTime(value); + return new Date(cal.getTimeInMillis()); + } + @Override public double getDouble(int columnIndex) throws SQLException { try { diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java index a9d32e8cafb..c84a297eca9 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java @@ -23,6 +23,7 @@ import java.math.MathContext; import java.nio.charset.StandardCharsets; import java.sql.*; +import java.util.Calendar; import java.util.List; import org.apache.hive.service.rpc.thrift.TTableSchema; import org.apache.hive.service.rpc.thrift.TTypeId; @@ -182,6 +183,33 @@ public Date getDate(String columnName) throws SQLException { return getDate(findColumn(columnName)); } + @Override + public Date getDate(int columnIndex, Calendar cal) throws SQLException { + Date value = getDate(columnIndex); + if (value == null) { + return null; + } else { + try { + return parseDate(value, cal); + } catch (IllegalArgumentException e) { + throw new KyuubiSQLException("Cannot convert column " + columnIndex + " to date: " + e, e); + } + } + } + + @Override + public Date getDate(String columnLabel, Calendar cal) throws SQLException { + return this.getDate(findColumn(columnLabel), cal); + } + + private Date parseDate(Date value, Calendar cal) { + if (cal == null) { + cal = Calendar.getInstance(); + } + cal.setTime(value); + return new Date(cal.getTimeInMillis()); + } + @Override public double getDouble(int columnIndex) throws SQLException { try { From 7623b854ec353c978deb2c796c90e5bb6c59c529 Mon Sep 17 00:00:00 2001 From: hezhao2 Date: Thu, 23 Nov 2023 11:42:53 +0800 Subject: [PATCH 02/13] add Overwrite annotation and remove this method from the parent abstract class --- .../apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java | 3 ++- .../org/apache/kyuubi/jdbc/hive/adapter/SQLResultSet.java | 6 ------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java index 08af07aca69..ba3e22cd74d 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java @@ -198,7 +198,8 @@ public Date getDate(int columnIndex) throws SQLException { public Date getDate(String columnName) throws SQLException { return getDate(findColumn(columnName)); } - + + @Override public Date getDate(int columnIndex, Calendar cal) throws SQLException { Date value = getDate(columnIndex); if (value == null) { diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/adapter/SQLResultSet.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/adapter/SQLResultSet.java index 70c8ff4fe57..d21c956d352 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/adapter/SQLResultSet.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/adapter/SQLResultSet.java @@ -435,12 +435,6 @@ default Clob getClob(String columnLabel) throws SQLException { default Array getArray(String columnLabel) throws SQLException { throw new SQLFeatureNotSupportedException("Method not supported"); } - - @Override - default Date getDate(int columnIndex, Calendar cal) throws SQLException { - throw new SQLFeatureNotSupportedException("Method not supported"); - } - @Override default Date getDate(String columnLabel, Calendar cal) throws SQLException { throw new SQLFeatureNotSupportedException("Method not supported"); From 33e4305e3e2bcd4646fcd89a38e87d00160bdaaa Mon Sep 17 00:00:00 2001 From: hezhao2 Date: Thu, 23 Nov 2023 14:25:48 +0800 Subject: [PATCH 03/13] JDBC driver implements Result#getTimestamp and Result#getTime with Calendar --- .../jdbc/hive/KyuubiArrowBasedResultSet.java | 80 ++++++++++++++++++- .../kyuubi/jdbc/hive/KyuubiBaseResultSet.java | 77 ++++++++++++++++++ .../jdbc/hive/adapter/SQLResultSet.java | 24 ------ 3 files changed, 156 insertions(+), 25 deletions(-) diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java index ba3e22cd74d..a36e3b71ec0 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java @@ -198,7 +198,7 @@ public Date getDate(int columnIndex) throws SQLException { public Date getDate(String columnName) throws SQLException { return getDate(findColumn(columnName)); } - + @Override public Date getDate(int columnIndex, Calendar cal) throws SQLException { Date value = getDate(columnIndex); @@ -434,6 +434,84 @@ public Timestamp getTimestamp(String columnName) throws SQLException { return getTimestamp(findColumn(columnName)); } + @Override + public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { + Timestamp value = getTimestamp(columnIndex); + if (value == null) { + return null; + } else { + try { + return parseTimestamp(value, cal); + } catch (IllegalArgumentException e) { + throw new KyuubiSQLException("Cannot convert column " + columnIndex + " to timestamp: " + e, e); + } + } + } + + @Override + public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException { + return this.getTimestamp(findColumn(columnLabel), cal); + } + + private Timestamp parseTimestamp(Timestamp timestamp, Calendar cal) { + if (cal == null) { + cal = Calendar.getInstance(); + } + long v = timestamp.getTime(); + v -= cal.getTimeZone().getOffset(v); + timestamp = new Timestamp(v); + return timestamp; + } + + @Override + public Time getTime(int columnIndex) throws SQLException { + Object obj = getObject(columnIndex); + if (obj == null) { + return null; + } + if (obj instanceof Time) { + return (Time) obj; + } + if (obj instanceof String) { + return Time.valueOf((String) obj); + } + throw new KyuubiSQLException("Illegal conversion"); + } + + @Override + public Time getTime(String columnLabel) throws SQLException { + return getTime(findColumn(columnLabel)); + } + + @Override + public Time getTime(int columnIndex, Calendar cal) throws SQLException { + Time value = getTime(columnIndex); + if (value == null) { + return null; + } else { + try { + return parseTime(value, cal); + } catch (IllegalArgumentException e) { + throw new KyuubiSQLException("Cannot convert column " + columnIndex + " to time: " + e, e); + } + } + } + + @Override + public Time getTime(String columnLabel, Calendar cal) throws SQLException { + return this.getTime(findColumn(columnLabel), cal); + } + + private Time parseTime(Time date, Calendar cal) { + if (cal == null) { + cal = Calendar.getInstance(); + } + long v = date.getTime(); + v -= cal.getTimeZone().getOffset(v); + date = new Time(v); + return date; + } + @Override public int getType() throws SQLException { return ResultSet.TYPE_FORWARD_ONLY; diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java index c84a297eca9..f2cb04ddf30 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java @@ -439,6 +439,83 @@ public Timestamp getTimestamp(int columnIndex) throws SQLException { public Timestamp getTimestamp(String columnName) throws SQLException { return getTimestamp(findColumn(columnName)); } + @Override + public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { + Timestamp value = getTimestamp(columnIndex); + if (value == null) { + return null; + } else { + try { + return parseTimestamp(value, cal); + } catch (IllegalArgumentException e) { + throw new KyuubiSQLException("Cannot convert column " + columnIndex + " to timestamp: " + e, e); + } + } + } + + @Override + public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException { + return this.getTimestamp(findColumn(columnLabel), cal); + } + + private Timestamp parseTimestamp(Timestamp timestamp, Calendar cal) { + if (cal == null) { + cal = Calendar.getInstance(); + } + long v = timestamp.getTime(); + v -= cal.getTimeZone().getOffset(v); + timestamp = new Timestamp(v); + return timestamp; + } + + @Override + public Time getTime(int columnIndex) throws SQLException { + Object obj = getObject(columnIndex); + if (obj == null) { + return null; + } + if (obj instanceof Time) { + return (Time) obj; + } + if (obj instanceof String) { + return Time.valueOf((String) obj); + } + throw new KyuubiSQLException("Illegal conversion"); + } + + @Override + public Time getTime(String columnLabel) throws SQLException { + return getTime(findColumn(columnLabel)); + } + + @Override + public Time getTime(int columnIndex, Calendar cal) throws SQLException { + Time value = getTime(columnIndex); + if (value == null) { + return null; + } else { + try { + return parseTime(value, cal); + } catch (IllegalArgumentException e) { + throw new KyuubiSQLException("Cannot convert column " + columnIndex + " to time: " + e, e); + } + } + } + + @Override + public Time getTime(String columnLabel, Calendar cal) throws SQLException { + return this.getTime(findColumn(columnLabel), cal); + } + + private Time parseTime(Time date, Calendar cal) { + if (cal == null) { + cal = Calendar.getInstance(); + } + long v = date.getTime(); + v -= cal.getTimeZone().getOffset(v); + date = new Time(v); + return date; + } @Override public int getType() throws SQLException { diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/adapter/SQLResultSet.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/adapter/SQLResultSet.java index d21c956d352..bb5e3d45421 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/adapter/SQLResultSet.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/adapter/SQLResultSet.java @@ -435,30 +435,6 @@ default Clob getClob(String columnLabel) throws SQLException { default Array getArray(String columnLabel) throws SQLException { throw new SQLFeatureNotSupportedException("Method not supported"); } - @Override - default Date getDate(String columnLabel, Calendar cal) throws SQLException { - throw new SQLFeatureNotSupportedException("Method not supported"); - } - - @Override - default Time getTime(int columnIndex, Calendar cal) throws SQLException { - throw new SQLFeatureNotSupportedException("Method not supported"); - } - - @Override - default Time getTime(String columnLabel, Calendar cal) throws SQLException { - throw new SQLFeatureNotSupportedException("Method not supported"); - } - - @Override - default Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { - throw new SQLFeatureNotSupportedException("Method not supported"); - } - - @Override - default Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException { - throw new SQLFeatureNotSupportedException("Method not supported"); - } @Override default URL getURL(int columnIndex) throws SQLException { From 77313c224fb9e85af8f664f0d08e7530047c3b3a Mon Sep 17 00:00:00 2001 From: hezhao2 Date: Thu, 23 Nov 2023 14:49:01 +0800 Subject: [PATCH 04/13] reformat code style --- .../apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java | 3 ++- .../java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java | 4 +++- .../org/apache/kyuubi/jdbc/hive/adapter/SQLResultSet.java | 1 - 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java index a36e3b71ec0..bab9c0216f7 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java @@ -443,7 +443,8 @@ public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException try { return parseTimestamp(value, cal); } catch (IllegalArgumentException e) { - throw new KyuubiSQLException("Cannot convert column " + columnIndex + " to timestamp: " + e, e); + throw new KyuubiSQLException( + "Cannot convert column " + columnIndex + " to timestamp: " + e, e); } } } diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java index f2cb04ddf30..ef46fd2981a 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java @@ -439,6 +439,7 @@ public Timestamp getTimestamp(int columnIndex) throws SQLException { public Timestamp getTimestamp(String columnName) throws SQLException { return getTimestamp(findColumn(columnName)); } + @Override public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { Timestamp value = getTimestamp(columnIndex); @@ -448,7 +449,8 @@ public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException try { return parseTimestamp(value, cal); } catch (IllegalArgumentException e) { - throw new KyuubiSQLException("Cannot convert column " + columnIndex + " to timestamp: " + e, e); + throw new KyuubiSQLException( + "Cannot convert column " + columnIndex + " to timestamp: " + e, e); } } } diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/adapter/SQLResultSet.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/adapter/SQLResultSet.java index bb5e3d45421..32f1c88bc9f 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/adapter/SQLResultSet.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/adapter/SQLResultSet.java @@ -22,7 +22,6 @@ import java.math.BigDecimal; import java.net.URL; import java.sql.*; -import java.util.Calendar; import java.util.Map; @SuppressWarnings("deprecation") From fe60822b583bd938191786b1e4cab210fb0e54ec Mon Sep 17 00:00:00 2001 From: hezhao2 Date: Fri, 24 Nov 2023 11:33:18 +0800 Subject: [PATCH 05/13] add UTs in SparkDataTypeTests --- .../kyuubi/operation/SparkDataTypeTests.scala | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/SparkDataTypeTests.scala b/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/SparkDataTypeTests.scala index 2709bc861f5..57f121ffb08 100644 --- a/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/SparkDataTypeTests.scala +++ b/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/SparkDataTypeTests.scala @@ -18,6 +18,7 @@ package org.apache.kyuubi.operation import java.sql.{Date, Timestamp} +import java.util.{Calendar, TimeZone} import org.apache.kyuubi.util.SparkVersionUtil @@ -160,6 +161,20 @@ trait SparkDataTypeTests extends HiveJDBCTestHelper with SparkVersionUtil { } } + test("execute statement - select date with calendar") { + withJdbcStatement() { statement => + val resultSet = statement.executeQuery("SELECT DATE '2018-11-17' AS col") + assert(resultSet.next()) + assert(resultSet.getDate( + "col", + Calendar.getInstance()) === Date.valueOf("2018-11-17")) + val metaData = resultSet.getMetaData + assert(metaData.getColumnType(1) === java.sql.Types.DATE) + assert(metaData.getPrecision(1) === 10) + assert(metaData.getScale(1) === 0) + } + } + test("execute statement - select timestamp - second") { withJdbcStatement() { statement => val resultSet = statement.executeQuery( @@ -213,6 +228,22 @@ trait SparkDataTypeTests extends HiveJDBCTestHelper with SparkVersionUtil { } } + test("execute statement - select timestamp - second with calendar") { + withJdbcStatement() { statement => + val resultSet = statement.executeQuery( + "SELECT TIMESTAMP '2018-11-17 13:33:33' AS col") + assert(resultSet.next()) + assert(resultSet.getTimestamp( + "col", + Calendar.getInstance(TimeZone.getTimeZone("UTC"))) === Timestamp.valueOf( + "2018-11-17 13:33:33")) + val metaData = resultSet.getMetaData + assert(metaData.getColumnType(1) === java.sql.Types.TIMESTAMP) + assert(metaData.getPrecision(1) === 29) + assert(metaData.getScale(1) === 9) + } + } + test("execute statement - select daytime interval") { assume( resultFormat == "thrift" || From cd2e36f7cdb5cb57a3b0dd151ad4ff1a9e070eae Mon Sep 17 00:00:00 2001 From: hezhao2 Date: Fri, 24 Nov 2023 11:47:16 +0800 Subject: [PATCH 06/13] add UTs in SparkDataTypeTests --- .../org/apache/kyuubi/operation/SparkDataTypeTests.scala | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/SparkDataTypeTests.scala b/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/SparkDataTypeTests.scala index 57f121ffb08..4c5ef384408 100644 --- a/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/SparkDataTypeTests.scala +++ b/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/SparkDataTypeTests.scala @@ -168,6 +168,9 @@ trait SparkDataTypeTests extends HiveJDBCTestHelper with SparkVersionUtil { assert(resultSet.getDate( "col", Calendar.getInstance()) === Date.valueOf("2018-11-17")) + assert(resultSet.getDate( + 1, + Calendar.getInstance()) === Date.valueOf("2018-11-17")) val metaData = resultSet.getMetaData assert(metaData.getColumnType(1) === java.sql.Types.DATE) assert(metaData.getPrecision(1) === 10) @@ -237,6 +240,10 @@ trait SparkDataTypeTests extends HiveJDBCTestHelper with SparkVersionUtil { "col", Calendar.getInstance(TimeZone.getTimeZone("UTC"))) === Timestamp.valueOf( "2018-11-17 13:33:33")) + assert(resultSet.getTimestamp( + 1, + Calendar.getInstance(TimeZone.getTimeZone("UTC"))) === Timestamp.valueOf( + "2018-11-17 13:33:33")) val metaData = resultSet.getMetaData assert(metaData.getColumnType(1) === java.sql.Types.TIMESTAMP) assert(metaData.getPrecision(1) === 29) From 36710d0b1d83f3563f6255ae2251bec71357d944 Mon Sep 17 00:00:00 2001 From: hezhao2 Date: Mon, 27 Nov 2023 17:55:37 +0800 Subject: [PATCH 07/13] refactor --- .../org/apache/kyuubi/operation/SparkDataTypeTests.scala | 6 +++--- .../kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java | 8 ++++---- .../org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/SparkDataTypeTests.scala b/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/SparkDataTypeTests.scala index 4c5ef384408..49f6b85d89f 100644 --- a/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/SparkDataTypeTests.scala +++ b/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/SparkDataTypeTests.scala @@ -18,7 +18,7 @@ package org.apache.kyuubi.operation import java.sql.{Date, Timestamp} -import java.util.{Calendar, TimeZone} +import java.util.Calendar import org.apache.kyuubi.util.SparkVersionUtil @@ -238,11 +238,11 @@ trait SparkDataTypeTests extends HiveJDBCTestHelper with SparkVersionUtil { assert(resultSet.next()) assert(resultSet.getTimestamp( "col", - Calendar.getInstance(TimeZone.getTimeZone("UTC"))) === Timestamp.valueOf( + Calendar.getInstance()) === Timestamp.valueOf( "2018-11-17 13:33:33")) assert(resultSet.getTimestamp( 1, - Calendar.getInstance(TimeZone.getTimeZone("UTC"))) === Timestamp.valueOf( + Calendar.getInstance()) === Timestamp.valueOf( "2018-11-17 13:33:33")) val metaData = resultSet.getMetaData assert(metaData.getColumnType(1) === java.sql.Types.TIMESTAMP) diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java index bab9c0216f7..4c595788e30 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java @@ -459,8 +459,8 @@ private Timestamp parseTimestamp(Timestamp timestamp, Calendar cal) { cal = Calendar.getInstance(); } long v = timestamp.getTime(); - v -= cal.getTimeZone().getOffset(v); - timestamp = new Timestamp(v); + cal.setTimeInMillis(v); + timestamp = new Timestamp(cal.getTime().getTime()); return timestamp; } @@ -508,8 +508,8 @@ private Time parseTime(Time date, Calendar cal) { cal = Calendar.getInstance(); } long v = date.getTime(); - v -= cal.getTimeZone().getOffset(v); - date = new Time(v); + cal.setTimeInMillis(v); + date = new Time(cal.getTime().getTime()); return date; } diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java index ef46fd2981a..bdc08a2325a 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java @@ -465,8 +465,8 @@ private Timestamp parseTimestamp(Timestamp timestamp, Calendar cal) { cal = Calendar.getInstance(); } long v = timestamp.getTime(); - v -= cal.getTimeZone().getOffset(v); - timestamp = new Timestamp(v); + cal.setTimeInMillis(v); + timestamp = new Timestamp(cal.getTime().getTime()); return timestamp; } @@ -514,8 +514,8 @@ private Time parseTime(Time date, Calendar cal) { cal = Calendar.getInstance(); } long v = date.getTime(); - v -= cal.getTimeZone().getOffset(v); - date = new Time(v); + cal.setTimeInMillis(v); + date = new Time(cal.getTime().getTime()); return date; } From e1a36d3e8709c05cbb390a2c4d1b96549ecfebbe Mon Sep 17 00:00:00 2001 From: Cheng Pan Date: Tue, 5 Dec 2023 14:13:06 +0800 Subject: [PATCH 08/13] Update kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java --- .../apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java index bdc08a2325a..a0eb8c12135 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java @@ -495,12 +495,11 @@ public Time getTime(int columnIndex, Calendar cal) throws SQLException { Time value = getTime(columnIndex); if (value == null) { return null; - } else { - try { - return parseTime(value, cal); - } catch (IllegalArgumentException e) { - throw new KyuubiSQLException("Cannot convert column " + columnIndex + " to time: " + e, e); - } + } + try { + return parseTime(value, cal); + } catch (IllegalArgumentException e) { + throw new KyuubiSQLException("Cannot convert column " + columnIndex + " to time: " + e, e); } } From dbc1e1ea70fb8cd77967ce48c96c518e38974052 Mon Sep 17 00:00:00 2001 From: Cheng Pan Date: Tue, 5 Dec 2023 14:13:14 +0800 Subject: [PATCH 09/13] Update kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java --- .../kyuubi/jdbc/hive/KyuubiBaseResultSet.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java index a0eb8c12135..ecebf615dac 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java @@ -445,13 +445,12 @@ public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException Timestamp value = getTimestamp(columnIndex); if (value == null) { return null; - } else { - try { - return parseTimestamp(value, cal); - } catch (IllegalArgumentException e) { - throw new KyuubiSQLException( - "Cannot convert column " + columnIndex + " to timestamp: " + e, e); - } + } + try { + return parseTimestamp(value, cal); + } catch (IllegalArgumentException e) { + throw new KyuubiSQLException( + "Cannot convert column " + columnIndex + " to timestamp: " + e, e); } } From 190c6b0513d673e2571aceed2d90a21a0ab8306c Mon Sep 17 00:00:00 2001 From: Cheng Pan Date: Tue, 5 Dec 2023 14:13:23 +0800 Subject: [PATCH 10/13] Update kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java --- .../apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java index ecebf615dac..7386fc7dd88 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java @@ -188,12 +188,11 @@ public Date getDate(int columnIndex, Calendar cal) throws SQLException { Date value = getDate(columnIndex); if (value == null) { return null; - } else { - try { - return parseDate(value, cal); - } catch (IllegalArgumentException e) { - throw new KyuubiSQLException("Cannot convert column " + columnIndex + " to date: " + e, e); - } + } + try { + return parseDate(value, cal); + } catch (IllegalArgumentException e) { + throw new KyuubiSQLException("Cannot convert column " + columnIndex + " to date: " + e, e); } } From 8b386f15136ce2f7372c0e096c5850363ee32e23 Mon Sep 17 00:00:00 2001 From: Cheng Pan Date: Tue, 5 Dec 2023 14:13:30 +0800 Subject: [PATCH 11/13] Update kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java --- .../kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java index 4c595788e30..fca1d6b5a8e 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java @@ -489,12 +489,11 @@ public Time getTime(int columnIndex, Calendar cal) throws SQLException { Time value = getTime(columnIndex); if (value == null) { return null; - } else { - try { - return parseTime(value, cal); - } catch (IllegalArgumentException e) { - throw new KyuubiSQLException("Cannot convert column " + columnIndex + " to time: " + e, e); - } + } + try { + return parseTime(value, cal); + } catch (IllegalArgumentException e) { + throw new KyuubiSQLException("Cannot convert column " + columnIndex + " to time: " + e, e); } } From 595226d04006b8874aa8ab234633647a6fecace3 Mon Sep 17 00:00:00 2001 From: Cheng Pan Date: Tue, 5 Dec 2023 14:13:37 +0800 Subject: [PATCH 12/13] Update kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java --- .../kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java index fca1d6b5a8e..4a7647cc3c0 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java @@ -439,13 +439,12 @@ public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException Timestamp value = getTimestamp(columnIndex); if (value == null) { return null; - } else { - try { - return parseTimestamp(value, cal); - } catch (IllegalArgumentException e) { - throw new KyuubiSQLException( - "Cannot convert column " + columnIndex + " to timestamp: " + e, e); - } + } + try { + return parseTimestamp(value, cal); + } catch (IllegalArgumentException e) { + throw new KyuubiSQLException( + "Cannot convert column " + columnIndex + " to timestamp: " + e, e); } } From ddff6a7aae311117f2c14f8e885d5258296b99c5 Mon Sep 17 00:00:00 2001 From: Cheng Pan Date: Tue, 5 Dec 2023 14:13:44 +0800 Subject: [PATCH 13/13] Update kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java --- .../kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java index 4a7647cc3c0..e38eb2b926f 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiArrowBasedResultSet.java @@ -204,12 +204,11 @@ public Date getDate(int columnIndex, Calendar cal) throws SQLException { Date value = getDate(columnIndex); if (value == null) { return null; - } else { - try { - return parseDate(value, cal); - } catch (IllegalArgumentException e) { - throw new KyuubiSQLException("Cannot convert column " + columnIndex + " to date: " + e, e); - } + } + try { + return parseDate(value, cal); + } catch (IllegalArgumentException e) { + throw new KyuubiSQLException("Cannot convert column " + columnIndex + " to date: " + e, e); } }