Skip to content

Commit

Permalink
[Fix](nereids) change char(0) to char(1), varchar(0) to varchar(65533…
Browse files Browse the repository at this point in the history
…) when create table (apache#38427)
  • Loading branch information
feiniaofeiafei committed Jul 30, 2024
1 parent 377d461 commit b3ee564
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
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;
Expand Down Expand Up @@ -163,10 +164,10 @@ private DataType updateCharacterTypeLength(DataType dataType) {
.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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ public DataType defaultConcreteType() {
public int width() {
return WIDTH;
}

public boolean isLengthSet() {
return len > 0;
}
}
8 changes: 8 additions & 0 deletions regression-test/suites/ddl_p0/test_create_table.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
}

0 comments on commit b3ee564

Please sign in to comment.