This is an automated email from the ASF dual-hosted git repository.

dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new b63227af536 [Fix](nereids) change char(0) to char(1), varchar(0) to 
varchar(65533) when create table (#38427)
b63227af536 is described below

commit b63227af536b0042f922b1b60ff7723b750d2808
Author: feiniaofeiafei <53502832+feiniaofeia...@users.noreply.github.com>
AuthorDate: Tue Jul 30 11:14:56 2024 +0800

    [Fix](nereids) change char(0) to char(1), varchar(0) to varchar(65533) when 
create table (#38427)
---
 .../doris/nereids/trees/plans/commands/info/ColumnDefinition.java | 7 ++++---
 .../org/apache/doris/nereids/types/coercion/CharacterType.java    | 4 ++++
 regression-test/suites/ddl_p0/test_create_table.groovy            | 8 ++++++++
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java
index 8b8a4e0e5e3..a0f936fa6d5 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ColumnDefinition.java
@@ -37,6 +37,7 @@ import org.apache.doris.nereids.types.StructField;
 import org.apache.doris.nereids.types.StructType;
 import org.apache.doris.nereids.types.TinyIntType;
 import org.apache.doris.nereids.types.VarcharType;
+import org.apache.doris.nereids.types.coercion.CharacterType;
 import org.apache.doris.qe.SessionVariable;
 
 import com.google.common.base.Preconditions;
@@ -187,10 +188,10 @@ public class ColumnDefinition {
                     .collect(ImmutableList.toImmutableList());
             return new StructType(structFields);
         } else {
-            if (dataType.isStringLikeType()) {
-                if (dataType instanceof CharType && ((CharType) 
dataType).getLen() == -1) {
+            if (dataType.isStringLikeType() && !((CharacterType) 
dataType).isLengthSet()) {
+                if (dataType instanceof CharType) {
                     return new CharType(1);
-                } else if (dataType instanceof VarcharType && ((VarcharType) 
dataType).getLen() == -1) {
+                } else if (dataType instanceof VarcharType) {
                     return new VarcharType(VarcharType.MAX_VARCHAR_LENGTH);
                 }
             }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/CharacterType.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/CharacterType.java
index da56e71c7b0..c02ea39e39a 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/CharacterType.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/CharacterType.java
@@ -57,4 +57,8 @@ public abstract class CharacterType extends PrimitiveType {
     public int width() {
         return WIDTH;
     }
+
+    public boolean isLengthSet() {
+        return len > 0;
+    }
 }
diff --git a/regression-test/suites/ddl_p0/test_create_table.groovy 
b/regression-test/suites/ddl_p0/test_create_table.groovy
index a022f51e52a..1d3b8409d65 100644
--- a/regression-test/suites/ddl_p0/test_create_table.groovy
+++ b/regression-test/suites/ddl_p0/test_create_table.groovy
@@ -50,4 +50,12 @@ suite("sql_create_time_range_table") {
     assertTrue(result1.size() == 1)
     assertTrue(result1[0].size() == 1)
     assertTrue(result1[0][0] == 0, "Create table should update 0 rows")
+
+    sql "SET enable_nereids_planner=true;"
+    sql "SET enable_fallback_to_original_planner=false;"
+    sql "drop table if exists varchar_0_char_0"
+    sql "create table varchar_0_char_0 (id int, a varchar(0), b char(0)) 
distributed by hash(id) properties(\"replication_num\"=\"1\")\n"
+    def res_show = sql "show create table varchar_0_char_0"
+    mustContain(res_show[0][1], "varchar(65533)")
+    mustContain(res_show[0][1], "char(1)")
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to