From d17ec3a7f2257f66d2901e2e183da4217b7f6ffa Mon Sep 17 00:00:00 2001 From: seawinde Date: Fri, 24 Nov 2023 08:14:20 +0800 Subject: [PATCH] fix varchar(0) correctly --- .../src/main/java/org/apache/doris/catalog/ScalarType.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java b/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java index 61d855319df2a2..a4972d9ced7002 100644 --- a/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java +++ b/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java @@ -1060,6 +1060,11 @@ public static ScalarType getAssignmentCompatibleType( if (t1.type == PrimitiveType.STRING || t2.type == PrimitiveType.STRING) { return createStringType(); } + int minLength = Math.min(t1.len, t2.len); + if (minLength < 0) { + // If < 0 which means max length, use firstly + return createVarcharType(minLength); + } int length = Math.max(t1.len, t2.len); return createVarcharType(length == 0 ? MAX_VARCHAR_LENGTH : length); }