Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)")
}