[enhance](auto-partition) forbid null column for auto partition (#29749)
This commit is contained in:
@ -190,9 +190,14 @@ public class PartitionDesc {
|
||||
throw new AnalysisException("Complex type column can't be partition column: "
|
||||
+ columnDef.getType().toString());
|
||||
}
|
||||
// prohibit to create auto partition with null column anyhow
|
||||
if (this.isAutoCreatePartitions && columnDef.isAllowNull()) {
|
||||
throw new AnalysisException("The auto partition column must be NOT NULL");
|
||||
}
|
||||
if (!ConnectContext.get().getSessionVariable().isAllowPartitionColumnNullable()
|
||||
&& columnDef.isAllowNull()) {
|
||||
throw new AnalysisException("The partition column must be NOT NULL");
|
||||
throw new AnalysisException(
|
||||
"The partition column must be NOT NULL with allow_partition_column_nullable OFF");
|
||||
}
|
||||
if (this instanceof ListPartitionDesc && columnDef.isAllowNull()) {
|
||||
throw new AnalysisException("The list partition column must be NOT NULL");
|
||||
|
||||
@ -138,6 +138,7 @@ public class CreateTableInfo {
|
||||
this.autoPartitionExprs = autoPartitionExprs;
|
||||
this.partitionType = partitionType;
|
||||
this.partitionColumns = partitionColumns;
|
||||
appendColumnFromExprs();
|
||||
this.partitions = partitions;
|
||||
this.distribution = distribution;
|
||||
this.rollups = Utils.copyRequiredList(rollups);
|
||||
@ -173,6 +174,7 @@ public class CreateTableInfo {
|
||||
this.autoPartitionExprs = autoPartitionExprs;
|
||||
this.partitionType = partitionType;
|
||||
this.partitionColumns = partitionColumns;
|
||||
appendColumnFromExprs();
|
||||
this.partitions = partitions;
|
||||
this.distribution = distribution;
|
||||
this.rollups = Utils.copyRequiredList(rollups);
|
||||
@ -650,8 +652,13 @@ public class CreateTableInfo {
|
||||
throw new AnalysisException("Complex type column can't be partition column: "
|
||||
+ column.getType().toString());
|
||||
}
|
||||
// prohibit to create auto partition with null column anyhow
|
||||
if (this.isAutoPartition && column.isNullable()) {
|
||||
throw new AnalysisException("The auto partition column must be NOT NULL");
|
||||
}
|
||||
if (!ctx.getSessionVariable().isAllowPartitionColumnNullable() && column.isNullable()) {
|
||||
throw new AnalysisException("The partition column must be NOT NULL");
|
||||
throw new AnalysisException(
|
||||
"The partition column must be NOT NULL with allow_partition_column_nullable OFF");
|
||||
}
|
||||
if (partitionType.equalsIgnoreCase(PartitionType.LIST.name()) && column.isNullable()) {
|
||||
throw new AnalysisException("The list partition column must be NOT NULL");
|
||||
@ -882,4 +889,14 @@ public class CreateTableInfo {
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void appendColumnFromExprs() {
|
||||
for (Expression autoExpr : autoPartitionExprs) {
|
||||
for (Expression child : autoExpr.children()) {
|
||||
if (child instanceof UnboundSlot) {
|
||||
partitionColumns.add(((UnboundSlot) child).getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -767,7 +767,11 @@ public class SessionVariable implements Serializable, Writable {
|
||||
@VariableMgr.VarAttr(name = SHOW_HIDDEN_COLUMNS, flag = VariableMgr.SESSION_ONLY)
|
||||
public boolean showHiddenColumns = false;
|
||||
|
||||
@VariableMgr.VarAttr(name = ALLOW_PARTITION_COLUMN_NULLABLE)
|
||||
@VariableMgr.VarAttr(name = ALLOW_PARTITION_COLUMN_NULLABLE, description = {
|
||||
"是否允许 NULLABLE 列作为 PARTITION 列。开启后,RANGE PARTITION 允许 NULLABLE PARTITION 列"
|
||||
+ "(LIST PARTITION当前不支持)。默认开。",
|
||||
"Whether to allow NULLABLE columns as PARTITION columns. When ON, RANGE PARTITION allows "
|
||||
+ "NULLABLE PARTITION columns (LIST PARTITION is not supported currently). ON by default." })
|
||||
public boolean allowPartitionColumnNullable = true;
|
||||
|
||||
@VariableMgr.VarAttr(name = DELETE_WITHOUT_PARTITION, needForward = true)
|
||||
|
||||
Reference in New Issue
Block a user