This is an automated email from the ASF dual-hosted git repository.
daijy 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 e71b096 HIVE-21295: StorageHandler shall convert date to string using
Hive convention (Daniel Dai, reviewed by Jesus Camacho Rodriguez)
e71b096 is described below
commit e71b09677b610c9b77c924105cc624b46e90695c
Author: Daniel Dai <[email protected]>
AuthorDate: Thu Feb 21 10:23:49 2019 -0800
HIVE-21295: StorageHandler shall convert date to string using Hive
convention (Daniel Dai, reviewed by Jesus Camacho Rodriguez)
Signed-off-by: Jesus Camacho Rodriguez <[email protected]>
---
.../org/apache/hive/storage/jdbc/JdbcSerDe.java | 7 +++-
.../queries/clientpositive/external_jdbc_table.q | 17 +++++-----
.../clientpositive/llap/external_jdbc_table.q.out | 38 +++++++++++++++-------
3 files changed, 41 insertions(+), 21 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 87ba682..aabfd7c 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
@@ -37,6 +37,7 @@ import org.apache.hadoop.io.MapWritable;
import org.apache.hadoop.io.ObjectWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
+import org.apache.hive.common.util.DateUtils;
import org.apache.hive.storage.jdbc.conf.JdbcStorageConfigManager;
import org.apache.hive.storage.jdbc.dao.DatabaseAccessor;
import org.apache.hive.storage.jdbc.dao.DatabaseAccessorFactory;
@@ -197,7 +198,11 @@ public class JdbcSerDe extends AbstractSerDe {
case CHAR:
case VARCHAR:
case STRING:
- rowVal = rowVal.toString();
+ if (rowVal instanceof java.sql.Date) {
+ rowVal = DateUtils.getDateFormat().format((java.sql.Date)rowVal);
+ } else {
+ rowVal = rowVal.toString();
+ }
break;
case DATE:
if (rowVal instanceof java.sql.Date) {
diff --git a/ql/src/test/queries/clientpositive/external_jdbc_table.q
b/ql/src/test/queries/clientpositive/external_jdbc_table.q
index 3e629d2..36ed93a 100644
--- a/ql/src/test/queries/clientpositive/external_jdbc_table.q
+++ b/ql/src/test/queries/clientpositive/external_jdbc_table.q
@@ -34,19 +34,19 @@ FROM src
SELECT
dboutput (
'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
-'CREATE TABLE SIMPLE_DERBY_TABLE2 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL,
"dkey" DOUBLE )' ),
+'CREATE TABLE SIMPLE_DERBY_TABLE2 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL,
"dkey" DOUBLE, "datekey" DATE)' ),
dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
-'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey") VALUES
(?,?,?,?)','20','20','20.0','20.0'),
+'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey","datekey")
VALUES (?,?,?,?,?)','20','20','20.0','20.0','1999-02-22'),
dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
-'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey") VALUES
(?,?,?,?)','-20','8','9.0','11.0'),
+'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey","datekey")
VALUES (?,?,?,?,?)','-20','8','9.0','11.0','2000-03-15'),
dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
-'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey") VALUES
(?,?,?,?)','101','-16','66.0','-75.0'),
+'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey","datekey")
VALUES (?,?,?,?,?)','101','-16','66.0','-75.0','2010-04-01'),
dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
-'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey") VALUES
(?,?,?,?)','40','50','-455.4543','330.767')
+'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey","datekey")
VALUES (?,?,?,?,?)','40','50','-455.4543','330.767','2010-04-02')
limit 1;
@@ -75,7 +75,8 @@ CREATE EXTERNAL TABLE ext_simple_derby_table2
ikey int,
bkey bigint,
fkey float,
- dkey double
+ dkey double,
+ datekey string
)
STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
TBLPROPERTIES (
@@ -96,7 +97,7 @@ select dkey,fkey,bkey,ikey from ext_simple_derby_table1;
select bkey+ikey,fkey+dkey from ext_simple_derby_table1;
select abs(dkey),abs(ikey),abs(fkey),abs(bkey) from ext_simple_derby_table1;
-
+select datekey from ext_simple_derby_table2;
--Test aggregation
select count(*) from ext_simple_derby_table1;
@@ -184,4 +185,4 @@ SELECT bkey FROM ext_simple_derby_table2;
---select dkey from ext_simple_derby_table1 order by dkey limit 10 offset 60;
\ No newline at end of file
+--select dkey from ext_simple_derby_table1 order by dkey limit 10 offset 60;
diff --git a/ql/src/test/results/clientpositive/llap/external_jdbc_table.q.out
b/ql/src/test/results/clientpositive/llap/external_jdbc_table.q.out
index 2fa37f5..a3b0ac4 100644
--- a/ql/src/test/results/clientpositive/llap/external_jdbc_table.q.out
+++ b/ql/src/test/results/clientpositive/llap/external_jdbc_table.q.out
@@ -64,19 +64,19 @@ PREHOOK: query: FROM src
SELECT
#### A masked pattern was here ####
-'CREATE TABLE SIMPLE_DERBY_TABLE2 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL,
"dkey" DOUBLE )' ),
+'CREATE TABLE SIMPLE_DERBY_TABLE2 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL,
"dkey" DOUBLE, "datekey" DATE)' ),
#### A masked pattern was here ####
-'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey") VALUES
(?,?,?,?)','20','20','20.0','20.0'),
+'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey","datekey")
VALUES (?,?,?,?,?)','20','20','20.0','20.0','1999-02-22'),
#### A masked pattern was here ####
-'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey") VALUES
(?,?,?,?)','-20','8','9.0','11.0'),
+'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey","datekey")
VALUES (?,?,?,?,?)','-20','8','9.0','11.0','2000-03-15'),
#### A masked pattern was here ####
-'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey") VALUES
(?,?,?,?)','101','-16','66.0','-75.0'),
+'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey","datekey")
VALUES (?,?,?,?,?)','101','-16','66.0','-75.0','2010-04-01'),
#### A masked pattern was here ####
-'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey") VALUES
(?,?,?,?)','40','50','-455.4543','330.767')
+'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey","datekey")
VALUES (?,?,?,?,?)','40','50','-455.4543','330.767','2010-04-02')
limit 1
PREHOOK: type: QUERY
@@ -87,19 +87,19 @@ POSTHOOK: query: FROM src
SELECT
#### A masked pattern was here ####
-'CREATE TABLE SIMPLE_DERBY_TABLE2 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL,
"dkey" DOUBLE )' ),
+'CREATE TABLE SIMPLE_DERBY_TABLE2 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL,
"dkey" DOUBLE, "datekey" DATE)' ),
#### A masked pattern was here ####
-'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey") VALUES
(?,?,?,?)','20','20','20.0','20.0'),
+'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey","datekey")
VALUES (?,?,?,?,?)','20','20','20.0','20.0','1999-02-22'),
#### A masked pattern was here ####
-'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey") VALUES
(?,?,?,?)','-20','8','9.0','11.0'),
+'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey","datekey")
VALUES (?,?,?,?,?)','-20','8','9.0','11.0','2000-03-15'),
#### A masked pattern was here ####
-'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey") VALUES
(?,?,?,?)','101','-16','66.0','-75.0'),
+'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey","datekey")
VALUES (?,?,?,?,?)','101','-16','66.0','-75.0','2010-04-01'),
#### A masked pattern was here ####
-'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey") VALUES
(?,?,?,?)','40','50','-455.4543','330.767')
+'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey","datekey")
VALUES (?,?,?,?,?)','40','50','-455.4543','330.767','2010-04-02')
limit 1
POSTHOOK: type: QUERY
@@ -151,7 +151,8 @@ PREHOOK: query: CREATE EXTERNAL TABLE
ext_simple_derby_table2
ikey int,
bkey bigint,
fkey float,
- dkey double
+ dkey double,
+ datekey string
)
STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
TBLPROPERTIES (
@@ -171,7 +172,8 @@ POSTHOOK: query: CREATE EXTERNAL TABLE
ext_simple_derby_table2
ikey int,
bkey bigint,
fkey float,
- dkey double
+ dkey double,
+ datekey string
)
STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
TBLPROPERTIES (
@@ -234,6 +236,18 @@ POSTHOOK: Input: default@ext_simple_derby_table1
20.0 20 20.0 20
74.0 100 65.0 15
330.76 44 455.4540100097656 53
+PREHOOK: query: select datekey from ext_simple_derby_table2
+PREHOOK: type: QUERY
+PREHOOK: Input: default@ext_simple_derby_table2
+#### A masked pattern was here ####
+POSTHOOK: query: select datekey from ext_simple_derby_table2
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@ext_simple_derby_table2
+#### A masked pattern was here ####
+1999-02-22
+2000-03-15
+2010-04-01
+2010-04-02
PREHOOK: query: select count(*) from ext_simple_derby_table1
PREHOOK: type: QUERY
PREHOOK: Input: default@ext_simple_derby_table1