From b0788652bd568365693992b416032c75e61c877e Mon Sep 17 00:00:00 2001 From: Guangdong Liu Date: Tue, 7 Nov 2023 17:16:07 +0800 Subject: [PATCH] [bugfix](clickhouse) fix datetime convert error. (#26128) --- .../jdbc/client/JdbcClickHouseClient.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcClickHouseClient.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcClickHouseClient.java index 292dea760efd15..b68ec481d3d2ec 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcClickHouseClient.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/jdbc/client/JdbcClickHouseClient.java @@ -58,25 +58,26 @@ protected Type jdbcTypeToDoris(JdbcFieldSchema fieldSchema) { return createDecimalOrStringType(precision, scale); } - if ("String".contains(ckType) || ckType.startsWith("Enum") - || ckType.startsWith("IPv") || "UUID".contains(ckType) + if ("String".contains(ckType) + || ckType.startsWith("Enum") + || ckType.startsWith("IPv") + || "UUID".contains(ckType) || ckType.startsWith("FixedString")) { return ScalarType.createStringType(); } if (ckType.startsWith("DateTime")) { // DateTime with second precision - if (ckType.equals("DateTime")) { + if (ckType.startsWith("DateTime(") || ckType.equals("DateTime")) { return ScalarType.createDatetimeV2Type(0); } else { - // DateTime64 with [0~9] precision int indexStart = ckType.indexOf('('); int indexEnd = ckType.indexOf(')'); if (indexStart != -1 && indexEnd != -1) { String scaleStr = ckType.substring(indexStart + 1, indexEnd); int scale = Integer.parseInt(scaleStr); - if (scale > 6) { - scale = 6; + if (scale > JDBC_DATETIME_SCALE) { + scale = JDBC_DATETIME_SCALE; } // return with the actual scale return ScalarType.createDatetimeV2Type(scale);