[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+morrySnow@users.noreply.github.com>
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,4 +57,8 @@ public abstract class CharacterType extends PrimitiveType {
|
||||
public int width() {
|
||||
return WIDTH;
|
||||
}
|
||||
|
||||
public boolean isLengthSet() {
|
||||
return len > 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user