[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)
|
||||
|
||||
@ -105,7 +105,7 @@ public class RangePartitionPruneTest extends PartitionPruneTestBase {
|
||||
+ "PROPERTIES ('replication_num' = '1');";
|
||||
|
||||
String autoCreatePartitionTable = new String("CREATE TABLE test.test_to_date_trunc(\n"
|
||||
+ " event_day DATETIME\n"
|
||||
+ " event_day DATETIME NOT NULL\n"
|
||||
+ ")\n"
|
||||
+ "DUPLICATE KEY(event_day)\n"
|
||||
+ "AUTO PARTITION BY range date_trunc(event_day, \"day\") (\n"
|
||||
|
||||
@ -82,7 +82,7 @@ public class FrontendServiceImplTest {
|
||||
@Test
|
||||
public void testCreatePartitionRange() throws Exception {
|
||||
String createOlapTblStmt = new String("CREATE TABLE test.partition_range(\n"
|
||||
+ " event_day DATETIME,\n"
|
||||
+ " event_day DATETIME NOT NULL,\n"
|
||||
+ " site_id INT DEFAULT '10',\n"
|
||||
+ " city_code VARCHAR(100)\n"
|
||||
+ ")\n"
|
||||
@ -123,7 +123,7 @@ public class FrontendServiceImplTest {
|
||||
String createOlapTblStmt = new String("CREATE TABLE test.partition_list(\n"
|
||||
+ " event_day DATETIME,\n"
|
||||
+ " site_id INT DEFAULT '10',\n"
|
||||
+ " city_code VARCHAR(100) not null\n"
|
||||
+ " city_code VARCHAR(100) NOT NULL\n"
|
||||
+ ")\n"
|
||||
+ "DUPLICATE KEY(event_day, site_id, city_code)\n"
|
||||
+ "AUTO PARTITION BY list (city_code) (\n"
|
||||
|
||||
Reference in New Issue
Block a user