[fix](Nereids) ctas varchar length should set to max except column from slot (#25003)

This commit is contained in:
morrySnow
2023-09-28 08:32:33 -05:00
committed by GitHub
parent d23bedf170
commit 8eaf0d3a4b

View File

@ -41,6 +41,7 @@ import org.apache.doris.nereids.types.DataType;
import org.apache.doris.nereids.types.DecimalV2Type;
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.ConnectContext;
import org.apache.doris.qe.QueryState.MysqlStateType;
import org.apache.doris.qe.StmtExecutor;
@ -106,6 +107,11 @@ public class CreateTableCommand extends Command implements ForwardWithSync {
dataType = DecimalV2Type.SYSTEM_DEFAULT;
} else if (i == 0 && dataType.isStringType()) {
dataType = VarcharType.createVarcharType(ScalarType.MAX_VARCHAR_LENGTH);
} else if (dataType instanceof CharacterType) {
// if column is not come from column, we should set varchar length to max
if (((CharacterType) dataType).getLen() > 0 && !s.isColumnFromTable()) {
dataType = VarcharType.createVarcharType(ScalarType.MAX_VARCHAR_LENGTH);
}
}
// if the column is an expression, we set it to nullable, otherwise according to the nullable of the slot.
columnsOfQuery.add(new ColumnDefinition(s.getName(), dataType, !s.isColumnFromTable() || s.nullable()));