You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by jc...@apache.org on 2019/11/04 16:28:23 UTC

[hive] branch master updated: HIVE-22433: Hive JDBC Storage Handler: Incorrect results fetched from BOOLEAN and TIMESTAMP DataType From JDBC Data Source (Syed Shameerur Rahman, reviewed by Jesus Camacho Rodriguez)

This is an automated email from the ASF dual-hosted git repository.

jcamacho pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/master by this push:
     new 6af5e6a  HIVE-22433: Hive JDBC Storage Handler: Incorrect results fetched from BOOLEAN and TIMESTAMP DataType From JDBC Data Source (Syed Shameerur Rahman, reviewed by Jesus Camacho Rodriguez)
6af5e6a is described below

commit 6af5e6a01beed8db38d78cc91a22eeca22124ec3
Author: Syed Shameerur Rahman <sr...@qubole.com>
AuthorDate: Mon Nov 4 08:27:00 2019 -0800

    HIVE-22433: Hive JDBC Storage Handler: Incorrect results fetched from BOOLEAN and TIMESTAMP DataType From JDBC Data Source (Syed Shameerur Rahman, reviewed by Jesus Camacho Rodriguez)
    
    Close apache/hive#833
---
 .../org/apache/hive/storage/jdbc/JdbcSerDe.java    | 14 +++++++----
 .../llap/external_jdbc_table_partition.q.out       | 28 +++++++++++-----------
 .../llap/external_jdbc_table_typeconversion.q.out  | 10 ++++----
 3 files changed, 28 insertions(+), 24 deletions(-)

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 a28f2f4..0a1bf2d 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.slf4j.LoggerFactory;
 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);
@@ -215,7 +219,7 @@ public class JdbcSerDe extends AbstractSerDe {
           if (rowVal instanceof Number) {
             rowVal = ((Number) value).intValue() != 0;
           } else {
-            rowVal = Boolean.valueOf(value.toString());
+            rowVal = Boolean.valueOf(rowVal.toString());
           }
           break;
         case CHAR:
@@ -229,16 +233,16 @@ public class JdbcSerDe extends AbstractSerDe {
           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 4445efa..feb9299 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 1b790b0..0011922 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 ####