This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.2 by this push:
new 30772b8f043 branch-4.2: [fix](jdbc) Fix PostgreSQL array dimensions
without values (#71026)
30772b8f043 is described below
commit 30772b8f043ed653c565ef08809b05d15797980c
Author: Socrates <[email protected]>
AuthorDate: Thu Nov 26 21:31:03 2026 +0800
branch-4.2: [fix](jdbc) Fix PostgreSQL array dimensions without values
(#71026)
### Background
The release-branch PostgreSQL JDBC client infers array dimensions by
sampling a non-NULL table value. The connector implementation on master
already uses declared dimensions from PostgreSQL system catalogs, while
this branch still uses array_ndims on row data.
### What problem does this PR solve?
Issue Number: None
Related PR: #62183 (contains the metadata lookup in the connector
implementation)
PR Type: Bugfix
Problem Summary:
Backport the PostgreSQL array-dimension metadata lookup to the release
branch's existing JDBC client. Read pg_attribute.attndims through a
prepared query so all-NULL and empty-array columns can be mapped without
requiring a non-empty row. Keep the branch's existing metadata filters
and type mappings and add the original one-/two-dimensional NULL and
empty-array regression fixtures and results.
### Details
- **Frequency:** When an array column has only NULL or empty-array
values at metadata loading time.
- **Root cause:** array_ndims sampling yields no usable dimensions for
these values, leaving the array type unsupported.
- **Why existing tests missed it:** Existing array cases contained
non-empty values; they did not cover entirely NULL or empty
one-/two-dimensional columns.
- **Fix:** Query attndims by schema, table and column using bound
parameters and pass the result through the existing JdbcFieldSchema and
nested-array conversion path.
- **Other paths and branches:** Scalar metadata and all existing
branch-specific filters/type mappings are preserved. The same isolated
fix is being backported to maintained 4.0, 4.1 and 4.2 release branches.
- **Behavior change:** Array metadata uses the declared dimensions even
when table values contain no dimension information.
### Testing
- Passed ./build.sh --fe -j4 on this target branch with macOS ARM64, JDK
17 and Maven 3.9.8. FE source/test-source compilation, Checkstyle for
modified Java sources and output packaging succeeded; optional UI,
JuiceFS, Hive UDF and BE Java-extension builds were disabled locally.
- Static checks verified that exactly five intended files changed, that
the production edit applies the original metadata lookup while retaining
all other branch-specific code, and that the original regression output
sections are preserved byte for byte. No golden output was handwritten
or regenerated.
- Source whitespace checks passed. Original TSV output trailing columns
are retained.
- PostgreSQL external-docker regression was not run because the local
Docker daemon is unavailable. No unit or live regression test execution
is claimed.
- Local-only build environment adjustment: gated the unrelated native
third-party rebuild check on BUILD_BE/BUILD_CLOUD so --fe did not
rebuild BE dependencies. Used a local Thrift 0.24 generator matching the
branch runtime and regenerated stale local sources. The tracked build.sh
was restored before committing; no build-script or generated-code change
is included.
### Release note
Fix PostgreSQL JDBC type mapping for array columns containing only NULL
or empty arrays, including declared two-dimensional arrays.
### Check List (For Author)
- Behavior changed: Yes (see Details).
- Does this need documentation: No.
- Pre-submission status: Partially verified: FE build and static checks
passed; PostgreSQL external-docker regression was not run because the
local Docker daemon is unavailable.
### AI Disclosure
- Tool: Codex (GPT-6).
- Generated: Backport adaptation, validation and this description.
- Human review: Pending.
---
.../postgresql/init/02-create-table.sql | 8 ++++
.../docker-compose/postgresql/init/04-insert.sql | 5 +++
.../jdbc/client/JdbcPostgreSQLClient.java | 51 +++++++++++-----------
.../jdbc/test_pg_jdbc_catalog.out | 12 ++++-
.../jdbc/test_pg_jdbc_catalog.groovy | 4 ++
5 files changed, 53 insertions(+), 27 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 ac35f2847d2..c1eec48dbb7 100644
--- a/docker/thirdparties/docker-compose/postgresql/init/02-create-table.sql
+++ b/docker/thirdparties/docker-compose/postgresql/init/02-create-table.sql
@@ -443,3 +443,11 @@ CREATE TABLE catalog_pg_test.test_array_null (
int_arr int4[] NULL,
varchar_arr varchar[] NULL
);
+
+CREATE TABLE catalog_pg_test.test_array_no_values (
+ id int4 NOT NULL,
+ all_null_1d text[] NULL,
+ empty_1d text[] NULL,
+ all_null_2d text[][] NULL,
+ empty_2d text[][] NULL
+);
diff --git a/docker/thirdparties/docker-compose/postgresql/init/04-insert.sql
b/docker/thirdparties/docker-compose/postgresql/init/04-insert.sql
index c6b4fafe896..43f8a62f0a9 100644
--- a/docker/thirdparties/docker-compose/postgresql/init/04-insert.sql
+++ b/docker/thirdparties/docker-compose/postgresql/init/04-insert.sql
@@ -3031,3 +3031,8 @@ SET TIME ZONE DEFAULT;
INSERT INTO catalog_pg_test.test_array_null VALUES (1, NULL, NULL, NULL);
INSERT INTO catalog_pg_test.test_array_null VALUES (2, ARRAY['hello',
'world'], ARRAY[1, 2, 3], ARRAY['a', 'b']);
INSERT INTO catalog_pg_test.test_array_null VALUES (3, ARRAY['foo', NULL],
ARRAY[NULL, 4], ARRAY[NULL, 'c']);
+
+-- Test array dimension detection when no value carries dimension information.
+INSERT INTO catalog_pg_test.test_array_no_values VALUES
+ (1, NULL, '{}'::text[], NULL, '{}'::text[][]),
+ (2, NULL, '{}'::text[], NULL, '{}'::text[][]);
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcPostgreSQLClient.java
b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcPostgreSQLClient.java
index 5bcf9fcadd7..5642fe70a0b 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcPostgreSQLClient.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcPostgreSQLClient.java
@@ -71,32 +71,8 @@ public class JdbcPostgreSQLClient extends JdbcClient {
int dataType = rs.getInt("DATA_TYPE");
int arrayDimensions = 0;
if (dataType == Types.ARRAY) {
- String columnName = rs.getString("COLUMN_NAME");
- PreparedStatement pstmt = null;
- ResultSet arrayRs = null;
- try {
- pstmt = conn.prepareStatement(
- String.format("SELECT array_ndims(\"%s\") FROM
\"%s\".\"%s\""
- + " WHERE \"%s\" IS NOT NULL
LIMIT 1",
- columnName, remoteDbName,
remoteTableName,
- columnName));
- arrayRs = pstmt.executeQuery();
- if (arrayRs.next()) {
- arrayDimensions = arrayRs.getInt(1);
- }
- } catch (SQLException ex) {
- LOG.warn("Failed to get array dimensions for column
{}: {}",
- columnName, Util.getRootCauseMessage(ex));
- } finally {
- close(arrayRs, null);
- if (pstmt != null) {
- try {
- pstmt.close();
- } catch (SQLException ex) {
- LOG.warn("Failed to close prepared statement:
{}", Util.getRootCauseMessage(ex));
- }
- }
- }
+ arrayDimensions = getArrayDimensions(conn, remoteDbName,
rs.getString("COLUMN_NAME"),
+ remoteTableName);
}
tableSchema.add(new JdbcFieldSchema(rs, arrayDimensions));
}
@@ -109,6 +85,29 @@ public class JdbcPostgreSQLClient extends JdbcClient {
return tableSchema;
}
+ private int getArrayDimensions(Connection conn, String schemaName, String
columnName, String tableName)
+ throws SQLException {
+ String query = "SELECT a.attndims FROM pg_attribute a "
+ + "JOIN pg_class c ON a.attrelid = c.oid "
+ + "JOIN pg_namespace n ON c.relnamespace = n.oid "
+ + "WHERE n.nspname = ? AND c.relname = ? AND a.attname = ?";
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
+ try {
+ pstmt = conn.prepareStatement(query);
+ pstmt.setString(1, schemaName);
+ pstmt.setString(2, tableName);
+ pstmt.setString(3, columnName);
+ rs = pstmt.executeQuery();
+ if (rs.next()) {
+ return rs.getInt("attndims");
+ }
+ } finally {
+ close(rs, pstmt);
+ }
+ return 1;
+ }
+
@Override
protected String[] getTableTypes() {
return new String[] {"TABLE", "PARTITIONED TABLE", "VIEW",
"MATERIALIZED VIEW", "FOREIGN TABLE"};
diff --git
a/regression-test/data/external_table_p0/jdbc/test_pg_jdbc_catalog.out
b/regression-test/data/external_table_p0/jdbc/test_pg_jdbc_catalog.out
index 61e2d18d161..af1d680643b 100644
--- a/regression-test/data/external_table_p0/jdbc/test_pg_jdbc_catalog.out
+++ b/regression-test/data/external_table_p0/jdbc/test_pg_jdbc_catalog.out
@@ -2249,6 +2249,17 @@ varchar_arr array<text> Yes true \N
2 ["hello", "world"] [1, 2, 3] ["a", "b"]
3 ["foo", null] [null, 4] [null, "c"]
+-- !test_array_no_values_desc --
+all_null_1d array<text> Yes true \N
+all_null_2d array<array<text>> Yes true \N
+empty_1d array<text> Yes true \N
+empty_2d array<array<text>> Yes true \N
+id int No true \N
+
+-- !test_array_no_values --
+1 \N [] \N []
+2 \N [] \N []
+
-- !ctas --
1 abc def 2022-10-11 1 2 3
2022-10-22T10:59:59 34.123 false 12.123456 10.16.10.14/32
10.16.10.14 ff:ff:ff:ff:ff:aa 1010101010 01010 1 {"id":
1} (1.0,1.0) {1.0,1.0,1.0} [(1.0,1.0),(2.0,2.0)]
(2.0,2.0),(1.0,1.0) ((1.0,1.0),(2.0,2.0),(2.0,1.0))
((1.0,1.0),(2.0,2.0),(2.0,1.0)) <(0.0,0.0),1.0>
2 \N \N \N \N \N \N \N \N \N
\N \N \N \N \N \N 2 \N \N \N
\N \N \N \N \N
@@ -2309,4 +2320,3 @@ mysql
-- !varbinary_test_after_insert --
1
0x01030000000100000005000000000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000000000000000000000000000000000000000
3 0x0101000000000000000000F03F0000000000000040
-
diff --git
a/regression-test/suites/external_table_p0/jdbc/test_pg_jdbc_catalog.groovy
b/regression-test/suites/external_table_p0/jdbc/test_pg_jdbc_catalog.groovy
index 3aec923647f..92af133bea8 100644
--- a/regression-test/suites/external_table_p0/jdbc/test_pg_jdbc_catalog.groovy
+++ b/regression-test/suites/external_table_p0/jdbc/test_pg_jdbc_catalog.groovy
@@ -159,6 +159,10 @@ suite("test_pg_jdbc_catalog",
"p0,external,pg,external_docker,external_docker_pg
order_qt_test_array_null_desc """desc test_array_null;"""
order_qt_test_array_null """select * from test_array_null order by
id;"""
+ // test arrays whose values are all NULL or empty
+ order_qt_test_array_no_values_desc """desc test_array_no_values;"""
+ order_qt_test_array_no_values """select * from test_array_no_values
order by id;"""
+
// test test ctas
sql """ drop table if exists internal.${internal_db_name}.${test_ctas}
"""
sql """ create table internal.${internal_db_name}.${test_ctas}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]