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

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


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

commit de9b9d6a39978c6e4cd9daf7302aaf826c26780b
Author: feiniaofeiafei <53502832+feiniaofeia...@users.noreply.github.com>
AuthorDate: Mon Aug 5 09:18:18 2024 +0800

    [Fix](nereids) change char(0) to char(1), varchar(0) to varchar(65533) when 
create table (#38427) (#38530)
    
    cherry-pick #38427 to branch-2.1
    
    ---------
    
    Co-authored-by: morrySnow <101034200+morrys...@users.noreply.github.com>
---
 .../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 352c3ec72da..049a0426073 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
@@ -36,6 +36,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;
@@ -163,10 +164,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..724e7e062e1 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