diff --git a/jdbc-handler/src/main/java/org/apache/hive/storage/jdbc/JdbcSerDe.java b/jdbc-handler/src/main/java/org/apache/hive/storage/jdbc/JdbcSerDe.java index add1a1919b..2bbda35d64 100644 --- a/jdbc-handler/src/main/java/org/apache/hive/storage/jdbc/JdbcSerDe.java +++ b/jdbc-handler/src/main/java/org/apache/hive/storage/jdbc/JdbcSerDe.java @@ -47,11 +47,15 @@ import org.apache.hive.storage.jdbc.conf.JdbcStorageConfig; import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Properties; +import static java.time.ZoneOffset.UTC; + public class JdbcSerDe extends AbstractSerDe { private static final Logger LOGGER = LoggerFactory.getLogger(JdbcSerDe.class); @@ -203,7 +207,7 @@ public Object deserialize(Writable blob) throws SerDeException { if (rowVal instanceof Number) { rowVal = ((Number) value).intValue() != 0; } else { - rowVal = Boolean.valueOf(value.toString()); + rowVal = Boolean.valueOf(rowVal.toString()); } break; case CHAR: @@ -217,16 +221,16 @@ public Object deserialize(Writable blob) throws SerDeException { break; case DATE: if (rowVal instanceof java.sql.Date) { - java.sql.Date dateRowVal = (java.sql.Date) rowVal; - rowVal = Date.ofEpochMilli(dateRowVal.getTime()); + LocalDate localDate = ((java.sql.Date) rowVal).toLocalDate(); + rowVal = Date.of(localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth()); } else { rowVal = Date.valueOf (rowVal.toString()); } break; case TIMESTAMP: if (rowVal instanceof java.sql.Timestamp) { - java.sql.Timestamp timestampRowVal = (java.sql.Timestamp) rowVal; - rowVal = Timestamp.ofEpochMilli(timestampRowVal.getTime(), timestampRowVal.getNanos()); + LocalDateTime localDateTime = ((java.sql.Timestamp) rowVal).toLocalDateTime(); + rowVal = Timestamp.ofEpochSecond(localDateTime.toEpochSecond(UTC), localDateTime.getNano()); } else { rowVal = Timestamp.valueOf (rowVal.toString()); } diff --git a/ql/src/test/results/clientpositive/llap/external_jdbc_table_partition.q.out b/ql/src/test/results/clientpositive/llap/external_jdbc_table_partition.q.out index 4445efa3f1..feb9299aa7 100644 --- a/ql/src/test/results/clientpositive/llap/external_jdbc_table_partition.q.out +++ b/ql/src/test/results/clientpositive/llap/external_jdbc_table_partition.q.out @@ -101,10 +101,10 @@ POSTHOOK: query: SELECT * FROM jdbc_partition_table1 where ikey > 1 POSTHOOK: type: QUERY POSTHOOK: Input: default@jdbc_partition_table1 #### A masked pattern was here #### -3 4000 120.0 25.4 hello 2.718 2017-06-05 2011-11-11 02:00:08 -4 8000 120.4 31.3 ccc NULL 2014-03-04 2018-07-08 18:00:00 -5 9000 NULL 10.0 bbb 2.718 2018-01-01 2010-06-01 21:00:00 -8 3000 180.0 35.8 world 3.142 2014-03-03 2016-07-04 20:00:00 +3 4000 120.0 25.4 hello 2.718 2017-06-05 2011-11-10 18:00:08 +4 8000 120.4 31.3 ccc NULL 2014-03-04 2018-07-08 11:00:00 +5 9000 NULL 10.0 bbb 2.718 2018-01-01 2010-06-01 14:00:00 +8 3000 180.0 35.8 world 3.142 2014-03-03 2016-07-04 13:00:00 PREHOOK: query: CREATE EXTERNAL TABLE jdbc_partition_table2 ( ikey int, @@ -165,11 +165,11 @@ POSTHOOK: query: SELECT * FROM jdbc_partition_table2 POSTHOOK: type: QUERY POSTHOOK: Input: default@jdbc_partition_table2 #### A masked pattern was here #### -5 9000 NULL 10.0 bbb 2.718 2018-01-01 2010-06-01 21:00:00 -3 4000 120.0 25.4 hello 2.718 2017-06-05 2011-11-11 02:00:08 -4 8000 120.4 31.3 ccc NULL 2014-03-04 2018-07-08 18:00:00 -1 1000 20.0 40.0 aaa 3.142 2010-01-01 2018-01-01 20:00:00 -8 3000 180.0 35.8 world 3.142 2014-03-03 2016-07-04 20:00:00 +5 9000 NULL 10.0 bbb 2.718 2018-01-01 2010-06-01 14:00:00 +3 4000 120.0 25.4 hello 2.718 2017-06-05 2011-11-10 18:00:08 +4 8000 120.4 31.3 ccc NULL 2014-03-04 2018-07-08 11:00:00 +1 1000 20.0 40.0 aaa 3.142 2010-01-01 2018-01-01 12:00:00 +8 3000 180.0 35.8 world 3.142 2014-03-03 2016-07-04 13:00:00 PREHOOK: query: CREATE EXTERNAL TABLE jdbc_partition_table3 ( ikey int, @@ -236,11 +236,11 @@ POSTHOOK: query: SELECT * FROM jdbc_partition_table3 POSTHOOK: type: QUERY POSTHOOK: Input: default@jdbc_partition_table3 #### A masked pattern was here #### -1 1000 20.0 40.0 aaa 3.142 2010-01-01 2018-01-01 20:00:00 -5 9000 NULL 10.0 bbb 2.718 2018-01-01 2010-06-01 21:00:00 -3 4000 120.0 25.4 hello 2.718 2017-06-05 2011-11-11 02:00:08 -8 3000 180.0 35.8 world 3.142 2014-03-03 2016-07-04 20:00:00 -4 8000 120.4 31.3 ccc NULL 2014-03-04 2018-07-08 18:00:00 +1 1000 20.0 40.0 aaa 3.142 2010-01-01 2018-01-01 12:00:00 +5 9000 NULL 10.0 bbb 2.718 2018-01-01 2010-06-01 14:00:00 +3 4000 120.0 25.4 hello 2.718 2017-06-05 2011-11-10 18:00:08 +8 3000 180.0 35.8 world 3.142 2014-03-03 2016-07-04 13:00:00 +4 8000 120.4 31.3 ccc NULL 2014-03-04 2018-07-08 11:00:00 PREHOOK: query: SELECT ikey+1 FROM jdbc_partition_table3 PREHOOK: type: QUERY PREHOOK: Input: default@jdbc_partition_table3 diff --git a/ql/src/test/results/clientpositive/llap/external_jdbc_table_typeconversion.q.out b/ql/src/test/results/clientpositive/llap/external_jdbc_table_typeconversion.q.out index 1b790b0fbe..0011922406 100644 --- a/ql/src/test/results/clientpositive/llap/external_jdbc_table_typeconversion.q.out +++ b/ql/src/test/results/clientpositive/llap/external_jdbc_table_typeconversion.q.out @@ -97,11 +97,11 @@ POSTHOOK: query: SELECT * FROM jdbc_type_conversion_table1 POSTHOOK: type: QUERY POSTHOOK: Input: default@jdbc_type_conversion_table1 #### A masked pattern was here #### -1 1000 20.0 40.0 aaa 3.142 2010-01-01 2018-01-01 20:00:00 -5 9000 NULL 10.0 bbb 2.718 2018-01-01 2010-06-01 21:00:00 -3 4000 120.0 25.4 hello 2.718 2017-06-05 2011-11-11 02:00:08 -8 3000 180.0 35.8 world 3.142 2014-03-03 2016-07-04 20:00:00 -4 8000 120.4 31.3 ccc NULL 2014-03-04 2018-07-08 18:00:00 +1 1000 20.0 40.0 aaa 3.142 2010-01-01 2018-01-01 12:00:00 +5 9000 NULL 10.0 bbb 2.718 2018-01-01 2010-06-01 14:00:00 +3 4000 120.0 25.4 hello 2.718 2017-06-05 2011-11-10 18:00:08 +8 3000 180.0 35.8 world 3.142 2014-03-03 2016-07-04 13:00:00 +4 8000 120.4 31.3 ccc NULL 2014-03-04 2018-07-08 11:00:00 PREHOOK: query: FROM src SELECT #### A masked pattern was here ####