You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by zy...@apache.org on 2023/06/27 16:19:08 UTC

[doris] branch master updated: [improvement](oracle jdbc)Support for automatically obtaining the precision of the oracle timestamp type (#21252)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new d871df64ca [improvement](oracle jdbc)Support for automatically obtaining the precision of the oracle timestamp type (#21252)
d871df64ca is described below

commit d871df64cab329e882da7e9db973dc5f8f3b2a5c
Author: zy-kkk <zh...@gmail.com>
AuthorDate: Wed Jun 28 00:19:01 2023 +0800

    [improvement](oracle jdbc)Support for automatically obtaining the precision of the oracle timestamp type (#21252)
---
 .../docker-compose/oracle/init/03-create-table.sql      | 11 ++++++-----
 .../docker-compose/oracle/init/04-insert.sql            | 11 ++++++-----
 .../apache/doris/external/jdbc/JdbcOracleClient.java    |  8 ++++++--
 .../data/jdbc_catalog_p0/test_oracle_jdbc_catalog.out   | 17 +++++++++--------
 4 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/docker/thirdparties/docker-compose/oracle/init/03-create-table.sql b/docker/thirdparties/docker-compose/oracle/init/03-create-table.sql
index 03aa1d5114..7d2b292125 100644
--- a/docker/thirdparties/docker-compose/oracle/init/03-create-table.sql
+++ b/docker/thirdparties/docker-compose/oracle/init/03-create-table.sql
@@ -72,11 +72,12 @@ t3 interval day(3) to second(6)
 create table doris_test.test_timestamp(
 id int,
 t1 date,
-t2 timestamp(6),
-t3 timestamp(9),
-t4 timestamp,
-t5 interval year(3) to month,
-t6 interval day(3) to second(6)
+t2 timestamp(3),
+t3 timestamp(6),
+t4 timestamp(9),
+t5 timestamp,
+t6 interval year(3) to month,
+t7 interval day(3) to second(6)
 );
 
 create table doris_test.test_insert(
diff --git a/docker/thirdparties/docker-compose/oracle/init/04-insert.sql b/docker/thirdparties/docker-compose/oracle/init/04-insert.sql
index d4638d0348..a5eb3bd5d1 100644
--- a/docker/thirdparties/docker-compose/oracle/init/04-insert.sql
+++ b/docker/thirdparties/docker-compose/oracle/init/04-insert.sql
@@ -47,12 +47,13 @@ insert into doris_test.test_date (id, t3) values (5, interval '12 10:23:01.12345
 
 insert into doris_test.test_timestamp (id, t1) values (1, to_date('2013-1-21 5:23:01','yyyy-mm-dd hh24:mi:ss'));
 insert into doris_test.test_timestamp (id, t1) values (2, to_date('20131112203256', 'yyyymmddhh24miss'));
-insert into doris_test.test_timestamp (id, t2) values (3, to_timestamp('20191112203357.999997623', 'yyyymmddhh24miss.ff'));
-insert into doris_test.test_timestamp (id, t3) values (4, to_timestamp_tz('20191112203357.999996623', 'yyyymmddhh24miss.ff'));
+insert into doris_test.test_timestamp (id, t2) values (3, to_timestamp('20191112203357.999', 'yyyymmddhh24miss.ff'));
+insert into doris_test.test_timestamp (id, t3) values (4, to_timestamp('20191112203357.999997623', 'yyyymmddhh24miss.ff'));
 insert into doris_test.test_timestamp (id, t4) values (5, to_timestamp_tz('20191112203357.999996623', 'yyyymmddhh24miss.ff'));
-insert into doris_test.test_timestamp (id, t5) values (6, interval '11' year);
-insert into doris_test.test_timestamp (id, t5) values (7, interval '223-9' year(3) to month);
-insert into doris_test.test_timestamp (id, t6) values (8, interval '12 10:23:01.1234568' day to second);
+insert into doris_test.test_timestamp (id, t5) values (6, to_timestamp_tz('20191112203357.999996623', 'yyyymmddhh24miss.ff'));
+insert into doris_test.test_timestamp (id, t6) values (7, interval '11' year);
+insert into doris_test.test_timestamp (id, t6) values (8, interval '223-9' year(3) to month);
+insert into doris_test.test_timestamp (id, t7) values (9, interval '12 10:23:01.1234568' day to second);
 
 insert into doris_test.test_number values (1, 123.45, 12345, 0.0012345);
 insert into doris_test.test_number values (2, 123.45, 12345, 0.0099999);
diff --git a/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcOracleClient.java b/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcOracleClient.java
index 5adfa63b9d..52700dd3f3 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcOracleClient.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcOracleClient.java
@@ -47,11 +47,15 @@ public class JdbcOracleClient extends JdbcClient {
         if (oracleType.startsWith("INTERVAL")) {
             oracleType = oracleType.substring(0, 8);
         } else if (oracleType.startsWith("TIMESTAMP")) {
-            if (oracleType.equals("TIMESTAMPTZ") || oracleType.equals("TIMESTAMPLTZ")) {
+            if (oracleType.contains("TIME ZONE") || oracleType.contains("LOCAL TIME ZONE")) {
                 return Type.UNSUPPORTED;
             }
             // oracle can support nanosecond, will lose precision
-            return ScalarType.createDatetimeV2Type(JDBC_DATETIME_SCALE);
+            int scale = fieldSchema.getDecimalDigits();
+            if (scale > 6) {
+                scale = 6;
+            }
+            return ScalarType.createDatetimeV2Type(scale);
         }
         switch (oracleType) {
             /**
diff --git a/regression-test/data/jdbc_catalog_p0/test_oracle_jdbc_catalog.out b/regression-test/data/jdbc_catalog_p0/test_oracle_jdbc_catalog.out
index 32b7070f17..df7d46628a 100644
--- a/regression-test/data/jdbc_catalog_p0/test_oracle_jdbc_catalog.out
+++ b/regression-test/data/jdbc_catalog_p0/test_oracle_jdbc_catalog.out
@@ -32,14 +32,15 @@
 5	\N	\N	12 10:23:1.123457
 
 -- !test6 --
-1	2013-01-21T05:23:01	\N	\N	\N	\N	\N
-2	2013-11-12T20:32:56	\N	\N	\N	\N	\N
-3	\N	2019-11-12T20:33:57.999998	\N	\N	\N	\N
-4	\N	\N	2019-11-12T20:33:57.999996	\N	\N	\N
-5	\N	\N	\N	2019-11-12T20:33:57.999997	\N	\N
-6	\N	\N	\N	\N	11-0	\N
-7	\N	\N	\N	\N	223-9	\N
-8	\N	\N	\N	\N	\N	12 10:23:1.123457
+1	2013-01-21T05:23:01	\N	\N	\N	\N	\N	\N
+2	2013-11-12T20:32:56	\N	\N	\N	\N	\N	\N
+3	\N	2019-11-12T20:33:57.999	\N	\N	\N	\N	\N
+4	\N	\N	2019-11-12T20:33:57.999998	\N	\N	\N	\N
+5	\N	\N	\N	2019-11-12T20:33:57.999996	\N	\N	\N
+6	\N	\N	\N	\N	2019-11-12T20:33:57.999997	\N	\N
+7	\N	\N	\N	\N	\N	11-0	\N
+8	\N	\N	\N	\N	\N	223-9	\N
+9	\N	\N	\N	\N	\N	\N	12 10:23:1.123457
 
 -- !test7 --
 1	123.45	12300	0.0012345


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org