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 fe18cfa2fb [improvement](pg jdbc)Support for automatically obtaining the precision of the postgresql timestamp type (#20909) fe18cfa2fb is described below commit fe18cfa2fbaff20109e733a3c06ea5cdca54ee4d Author: zy-kkk <zhongy...@gmail.com> AuthorDate: Fri Jun 16 23:41:09 2023 +0800 [improvement](pg jdbc)Support for automatically obtaining the precision of the postgresql timestamp type (#20909) --- .../docker-compose/postgresql/init/02-create-table.sql | 7 ++++++- docker/thirdparties/docker-compose/postgresql/init/04-insert.sql | 9 ++++++++- .../org/apache/doris/external/jdbc/JdbcPostgreSQLClient.java | 7 ++++++- regression-test/data/jdbc_catalog_p0/test_pg_jdbc_catalog.out | 8 +++----- .../suites/jdbc_catalog_p0/test_pg_jdbc_catalog.groovy | 1 + 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/docker/thirdparties/docker-compose/postgresql/init/02-create-table.sql b/docker/thirdparties/docker-compose/postgresql/init/02-create-table.sql index 738582a7cb..d7a66f5395 100644 --- a/docker/thirdparties/docker-compose/postgresql/init/02-create-table.sql +++ b/docker/thirdparties/docker-compose/postgresql/init/02-create-table.sql @@ -160,4 +160,9 @@ CREATE TABLE catalog_pg_test.test_insert ( CREATE TABLE catalog_pg_test.wkb_test ( id SERIAL PRIMARY KEY, location bytea -); \ No newline at end of file +); + +CREATE TABLE catalog_pg_test.dt_test ( + ts_field TIMESTAMP(3), + tzt_field TIMESTAMPTZ(3) +); diff --git a/docker/thirdparties/docker-compose/postgresql/init/04-insert.sql b/docker/thirdparties/docker-compose/postgresql/init/04-insert.sql index 6211db298b..7f59c5d665 100644 --- a/docker/thirdparties/docker-compose/postgresql/init/04-insert.sql +++ b/docker/thirdparties/docker-compose/postgresql/init/04-insert.sql @@ -2656,4 +2656,11 @@ insert into catalog_pg_test.test12 values insert into catalog_pg_test.test12 values (2, '980dd890-f7fe-4fff-999d-873516108b2e'); -INSERT INTO catalog_pg_test.wkb_test (location) SELECT ST_AsBinary(ST_GeomFromText('POLYGON((0 0,0 1,1 1,1 0,0 0))',4326)); \ No newline at end of file +INSERT INTO catalog_pg_test.wkb_test (location) SELECT ST_AsBinary(ST_GeomFromText('POLYGON((0 0,0 1,1 1,1 0,0 0))',4326)); + +INSERT INTO catalog_pg_test.dt_test (ts_field, tzt_field) +VALUES +( + '2023-06-16 12:34:56.123', + '2023-06-16 12:34:56.123+08' +); diff --git a/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcPostgreSQLClient.java b/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcPostgreSQLClient.java index 26eba627f4..36f624372c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcPostgreSQLClient.java +++ b/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcPostgreSQLClient.java @@ -67,7 +67,12 @@ public class JdbcPostgreSQLClient extends JdbcClient { case "timestamp": case "timestamptz": // postgres can support microsecond - return ScalarType.createDatetimeV2Type(JDBC_DATETIME_SCALE); + int scale = fieldSchema.getDecimalDigits(); + if (scale < 6) { + return ScalarType.createDatetimeV2Type(scale); + } else { + return ScalarType.createDatetimeV2Type(JDBC_DATETIME_SCALE); + } case "date": return ScalarType.createDateV2Type(); case "bool": diff --git a/regression-test/data/jdbc_catalog_p0/test_pg_jdbc_catalog.out b/regression-test/data/jdbc_catalog_p0/test_pg_jdbc_catalog.out index b9326d87f9..ac53b8e768 100644 --- a/regression-test/data/jdbc_catalog_p0/test_pg_jdbc_catalog.out +++ b/regression-test/data/jdbc_catalog_p0/test_pg_jdbc_catalog.out @@ -5,11 +5,6 @@ 234 bcd -- !in_tb -- -111 abc -112 abd -113 abe -114 abf -115 abg 123 abc 123 abc 234 bcd @@ -2144,6 +2139,9 @@ true abc def 2022-10-11 1.234 1 2 99 2022-10-22T10:59:59 34.123 -- !wkb_test -- 1 \\x01030000000100000005000000000000000000000000000000000000000000000000000000000000000000f03f000000000000f03f000000000000f03f000000000000f03f000000000000000000000000000000000000000000000000 +-- !dt_test -- +2023-06-16T12:34:56.123 2023-06-16T12:34:56.123 + -- !test_insert1 -- doris1 18 diff --git a/regression-test/suites/jdbc_catalog_p0/test_pg_jdbc_catalog.groovy b/regression-test/suites/jdbc_catalog_p0/test_pg_jdbc_catalog.groovy index 62e30509cc..669eb57d71 100644 --- a/regression-test/suites/jdbc_catalog_p0/test_pg_jdbc_catalog.groovy +++ b/regression-test/suites/jdbc_catalog_p0/test_pg_jdbc_catalog.groovy @@ -70,6 +70,7 @@ suite("test_pg_jdbc_catalog", "p0") { order_qt_test13 """ select * from test11 order by id; """ order_qt_test14 """ select * from test12 order by id; """ order_qt_wkb_test """ select * from wkb_test order by id; """ + order_qt_dt_test """ select * from dt_test order by 1; """ // test insert String uuid1 = UUID.randomUUID().toString(); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org