From 2231f4c1da6ecebc792e70dd8d60b5bc053dbce7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 9 Jan 2025 18:12:49 +0800 Subject: [PATCH] branch-3.0: [fix](jdbc catalog) Use factory methods to return mapped types instead #46623 (#46673) Cherry-picked from #46623 Co-authored-by: zy-kkk --- .../apache/doris/datasource/jdbc/client/JdbcClient.java | 4 ++-- .../doris/datasource/jdbc/client/JdbcDB2Client.java | 9 ++------- .../doris/datasource/jdbc/client/JdbcGbaseClient.java | 6 +----- .../doris/datasource/jdbc/client/JdbcMySQLClient.java | 6 ++---- .../datasource/jdbc/client/JdbcPostgreSQLClient.java | 5 +---- .../doris/datasource/jdbc/client/JdbcSapHanaClient.java | 5 +---- .../doris/datasource/jdbc/client/JdbcTrinoClient.java | 5 +---- .../jdbc/type_test/tvf/test_mysql_all_types_tvf.out | 8 ++++---- 8 files changed, 14 insertions(+), 34 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcClient.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcClient.java index f139dde5af2a2e..a3dfdcda3193d4 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcClient.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcClient.java @@ -369,8 +369,8 @@ public List getJdbcColumnsInfo(String remoteDbName, String remo return tableSchema; } - public List getColumnsFromJdbc(String localDbName, String localTableName) { - List jdbcTableSchema = getJdbcColumnsInfo(localDbName, localTableName); + public List getColumnsFromJdbc(String remoteDbName, String remoteTableName) { + List jdbcTableSchema = getJdbcColumnsInfo(remoteDbName, remoteTableName); List dorisTableSchema = Lists.newArrayListWithCapacity(jdbcTableSchema.size()); for (JdbcFieldSchema field : jdbcTableSchema) { dorisTableSchema.add(new Column(field.getColumnName(), diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcDB2Client.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcDB2Client.java index a353b7ac361353..666b2b0f2a9ded 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcDB2Client.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcDB2Client.java @@ -17,7 +17,6 @@ package org.apache.doris.datasource.jdbc.client; -import org.apache.doris.catalog.PrimitiveType; import org.apache.doris.catalog.ScalarType; import org.apache.doris.catalog.Type; import org.apache.doris.datasource.jdbc.util.JdbcFieldSchema; @@ -84,14 +83,10 @@ protected Type jdbcTypeToDoris(JdbcFieldSchema fieldSchema) { case "REAL": return Type.FLOAT; case "CHAR": - ScalarType charType = ScalarType.createType(PrimitiveType.CHAR); - charType.setLength(fieldSchema.getColumnSize().orElse(0)); - return charType; + return ScalarType.createCharType(fieldSchema.requiredColumnSize()); case "VARCHAR": case "LONG VARCHAR": - ScalarType varcharType = ScalarType.createType(PrimitiveType.VARCHAR); - varcharType.setLength(fieldSchema.getColumnSize().orElse(0)); - return varcharType; + return ScalarType.createVarcharType(fieldSchema.requiredColumnSize()); case "DATE": return ScalarType.createDateV2Type(); case "TIMESTAMP": { diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcGbaseClient.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcGbaseClient.java index 086a8a5f393614..6121ef2dbfc2fb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcGbaseClient.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcGbaseClient.java @@ -17,7 +17,6 @@ package org.apache.doris.datasource.jdbc.client; -import org.apache.doris.catalog.PrimitiveType; import org.apache.doris.catalog.ScalarType; import org.apache.doris.catalog.Type; import org.apache.doris.common.util.Util; @@ -143,10 +142,7 @@ protected Type jdbcTypeToDoris(JdbcFieldSchema fieldSchema) { return ScalarType.createDatetimeV2Type(scale); } case Types.CHAR: - ScalarType charType = ScalarType.createType(PrimitiveType.CHAR); - charType.setLength(fieldSchema.getColumnSize() - .orElseThrow(() -> new IllegalArgumentException("Length not present"))); - return charType; + return ScalarType.createCharType(fieldSchema.requiredColumnSize()); case Types.TIME: case Types.VARCHAR: case Types.LONGVARCHAR: diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcMySQLClient.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcMySQLClient.java index f4c331cf35779c..d69740a9269a8d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcMySQLClient.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcMySQLClient.java @@ -257,11 +257,9 @@ protected Type jdbcTypeToDoris(JdbcFieldSchema fieldSchema) { return createDecimalOrStringType(precision, scale); } case "CHAR": - ScalarType charType = ScalarType.createType(PrimitiveType.CHAR); - charType.setLength(fieldSchema.requiredColumnSize()); - return charType; + return ScalarType.createCharType(fieldSchema.requiredColumnSize()); case "VARCHAR": - return ScalarType.createVarcharType(fieldSchema.getColumnSize().orElse(0)); + return ScalarType.createVarcharType(fieldSchema.requiredColumnSize()); case "BIT": if (fieldSchema.requiredColumnSize() == 1) { return Type.BOOLEAN; 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 49e04893950726..21c16f2dd20ad5 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 @@ -18,7 +18,6 @@ package org.apache.doris.datasource.jdbc.client; import org.apache.doris.catalog.ArrayType; -import org.apache.doris.catalog.PrimitiveType; import org.apache.doris.catalog.ScalarType; import org.apache.doris.catalog.Type; import org.apache.doris.common.util.Util; @@ -115,9 +114,7 @@ protected Type jdbcTypeToDoris(JdbcFieldSchema fieldSchema) { case "float8": return Type.DOUBLE; case "bpchar": - ScalarType charType = ScalarType.createType(PrimitiveType.CHAR); - charType.setLength(fieldSchema.getColumnSize().orElse(0)); - return charType; + return ScalarType.createCharType(fieldSchema.requiredColumnSize()); case "timestamp": case "timestamptz": { // postgres can support microsecond diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcSapHanaClient.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcSapHanaClient.java index f10d082bada355..e89b6268b900f7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcSapHanaClient.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcSapHanaClient.java @@ -17,7 +17,6 @@ package org.apache.doris.datasource.jdbc.client; -import org.apache.doris.catalog.PrimitiveType; import org.apache.doris.catalog.ScalarType; import org.apache.doris.catalog.Type; import org.apache.doris.datasource.jdbc.util.JdbcFieldSchema; @@ -80,9 +79,7 @@ protected Type jdbcTypeToDoris(JdbcFieldSchema fieldSchema) { return Type.BOOLEAN; case "CHAR": case "NCHAR": - ScalarType charType = ScalarType.createType(PrimitiveType.CHAR); - charType.setLength(fieldSchema.getColumnSize().orElse(0)); - return charType; + return ScalarType.createCharType(fieldSchema.requiredColumnSize()); case "TIME": case "VARCHAR": case "NVARCHAR": diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcTrinoClient.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcTrinoClient.java index eac975805743c4..6c818a41cb6aca 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcTrinoClient.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcTrinoClient.java @@ -18,7 +18,6 @@ package org.apache.doris.datasource.jdbc.client; import org.apache.doris.catalog.ArrayType; -import org.apache.doris.catalog.PrimitiveType; import org.apache.doris.catalog.ScalarType; import org.apache.doris.catalog.Type; import org.apache.doris.datasource.jdbc.util.JdbcFieldSchema; @@ -65,9 +64,7 @@ protected Type jdbcTypeToDoris(JdbcFieldSchema fieldSchema) { } if (trinoType.startsWith("char")) { - ScalarType charType = ScalarType.createType(PrimitiveType.CHAR); - charType.setLength(fieldSchema.getColumnSize().orElse(0)); - return charType; + return ScalarType.createCharType(fieldSchema.requiredColumnSize()); } if (trinoType.startsWith("timestamp")) { diff --git a/regression-test/data/external_table_p0/jdbc/type_test/tvf/test_mysql_all_types_tvf.out b/regression-test/data/external_table_p0/jdbc/type_test/tvf/test_mysql_all_types_tvf.out index dacd255426a9b0..33f085b9550b44 100644 --- a/regression-test/data/external_table_p0/jdbc/type_test/tvf/test_mysql_all_types_tvf.out +++ b/regression-test/data/external_table_p0/jdbc/type_test/tvf/test_mysql_all_types_tvf.out @@ -34,12 +34,12 @@ datetime datetime Yes true \N NONE timestamp1 datetime Yes true \N NONE timestamp2 datetime(3) Yes true \N NONE timestamp3 datetime(6) Yes true \N NONE -char char(6) Yes true \N NONE +char char(5) Yes true \N NONE varchar varchar(10) Yes true \N NONE text text Yes true \N NONE blob text Yes true \N NONE json text Yes true \N NONE -set char(6) Yes true \N NONE +set char(23) Yes true \N NONE bit text Yes true \N NONE binary text Yes true \N NONE varbinary text Yes true \N NONE @@ -86,12 +86,12 @@ datetime datetime Yes true \N NONE timestamp1 datetime Yes true \N NONE timestamp2 datetime(3) Yes true \N NONE timestamp3 datetime(6) Yes true \N NONE -char char(6) Yes true \N NONE +char char(5) Yes true \N NONE varchar varchar(10) Yes true \N NONE text text Yes true \N NONE blob text Yes true \N NONE json text Yes true \N NONE -set char(6) Yes true \N NONE +set char(23) Yes true \N NONE bit text Yes true \N NONE binary text Yes true \N NONE varbinary text Yes true \N NONE