[fix](ctas) fix NPE when ctas with old planner and varchar issue (#39744) (#39871)

bp #39744
This commit is contained in:
Mingyu Chen
2024-08-24 09:24:47 +08:00
committed by GitHub
parent b9da934b16
commit de2e8f0ae6
4 changed files with 60 additions and 5 deletions

View File

@ -1307,8 +1307,9 @@ public class InternalCatalog implements CatalogIf<Database> {
if (resultExpr.getSrcSlotRef() != null
&& resultExpr.getSrcSlotRef().getTable() != null
&& !resultExpr.getSrcSlotRef().getTable().isManagedTable()) {
if (createTableStmt.getPartitionDesc().inIdentifierPartitions(
resultExpr.getSrcSlotRef().getColumnName())
if ((createTableStmt.getPartitionDesc() != null
&& createTableStmt.getPartitionDesc().inIdentifierPartitions(
resultExpr.getSrcSlotRef().getColumnName()))
|| (createTableStmt.getDistributionDesc() != null
&& createTableStmt.getDistributionDesc().inDistributionColumns(
resultExpr.getSrcSlotRef().getColumnName()))) {

View File

@ -123,6 +123,8 @@ public class CreateTableCommand extends Command implements ForwardWithSync {
Slot s = slots.get(i);
DataType dataType = s.getDataType().conversion();
if (i == 0 && dataType.isStringType()) {
// first column of olap table can not be string type.
// So change it to varchar type.
dataType = VarcharType.createVarcharType(ScalarType.MAX_VARCHAR_LENGTH);
} else {
dataType = TypeCoercionUtils.replaceSpecifiedType(dataType,
@ -135,13 +137,21 @@ public class CreateTableCommand extends Command implements ForwardWithSync {
if (createTableInfo.getPartitionTableInfo().inIdentifierPartitions(s.getName())
|| (createTableInfo.getDistribution() != null
&& createTableInfo.getDistribution().inDistributionColumns(s.getName()))) {
// String type can not be used in partition/distributed column
// String type can not be used in partition/distributed column,
// so we replace it to varchar
dataType = TypeCoercionUtils.replaceSpecifiedType(dataType,
CharacterType.class, VarcharType.MAX_VARCHAR_TYPE);
} else {
dataType = TypeCoercionUtils.replaceSpecifiedType(dataType,
CharacterType.class, StringType.INSTANCE);
if (i == 0) {
// first column of olap table can not be string type.
// So change it to varchar type.
dataType = TypeCoercionUtils.replaceSpecifiedType(dataType,
CharacterType.class, VarcharType.MAX_VARCHAR_TYPE);
} else {
// change varchar/char column from external table to string type
dataType = TypeCoercionUtils.replaceSpecifiedType(dataType,
CharacterType.class, StringType.INSTANCE);
}
}
}
} else {
@ -212,3 +222,4 @@ public class CreateTableCommand extends Command implements ForwardWithSync {
return createTableInfo;
}
}