[fix](create-table) wrong judgement about partition column type (#15542)

The following stmt should be success, but return error: `complex type cannt be partition column:ARRAY<VARCHAR(64)>`

```
create table test_array( 
task_insert_time BIGINT NOT NULL DEFAULT "0" COMMENT "" , 
task_project ARRAY<VARCHAR(64)>  DEFAULT NULL COMMENT "" ,
route_key DATEV2 NOT NULL COMMENT "range分区键"
) 
DUPLICATE KEY(`task_insert_time`)  
 COMMENT ""
PARTITION BY RANGE(route_key) 
(PARTITION `p202209` VALUES LESS THAN ("2022-10-01"),
PARTITION `p202210` VALUES LESS THAN ("2022-11-01"),
PARTITION `p202211` VALUES LESS THAN ("2022-12-01")) 
DISTRIBUTED BY HASH(`task_insert_time` ) BUCKETS 32 
PROPERTIES
(
    "replication_num" = "1",    
    "light_schema_change" = "true"    
);
```

This PR fix this
This commit is contained in:
Mingyu Chen
2022-12-31 13:10:39 +08:00
committed by GitHub
parent c47bdf6606
commit e89adc6e1d
3 changed files with 49 additions and 4 deletions

View File

@ -108,6 +108,10 @@ public class PartitionDesc {
throw new AnalysisException("String Type should not be used in partition column["
+ columnDef.getName() + "].");
}
if (columnDef.getType().isComplexType()) {
throw new AnalysisException("Complex type column can't be partition column: "
+ columnDef.getType().toString());
}
if (!ConnectContext.get().getSessionVariable().isAllowPartitionColumnNullable()
&& columnDef.isAllowNull()) {
throw new AnalysisException("The partition column must be NOT NULL");

View File

@ -84,6 +84,10 @@ public class RangePartitionDesc extends PartitionDesc {
boolean find = false;
for (Column column : schema) {
if (column.getName().equalsIgnoreCase(colName)) {
if (column.getType().isComplexType()) {
throw new DdlException("Complex type column can't be partition column: "
+ column.getType().toString());
}
try {
RangePartitionInfo.checkPartitionColumn(column);
} catch (AnalysisException e) {
@ -94,10 +98,6 @@ public class RangePartitionDesc extends PartitionDesc {
find = true;
break;
}
if (column.getType().isComplexType()) {
throw new DdlException("Complex type column can't be partition column: "
+ column.getType().toString());
}
}
if (!find) {
throw new DdlException("Partition column[" + colName + "] does not found");

View File

@ -644,5 +644,46 @@ public class CreateTableTest {
+ ") distributed by hash(k1) buckets 1\n"
+ "properties(\"replication_num\" = \"1\");");
});
ExceptionChecker.expectThrowsNoException(() -> {
createTable("create table test.test_array( \n"
+ "task_insert_time BIGINT NOT NULL DEFAULT \"0\" COMMENT \"\" , \n"
+ "task_project ARRAY<VARCHAR(64)> DEFAULT NULL COMMENT \"\" ,\n"
+ "route_key DATEV2 NOT NULL COMMENT \"range分区键\"\n"
+ ") \n"
+ "DUPLICATE KEY(`task_insert_time`) \n"
+ " COMMENT \"\"\n"
+ "PARTITION BY RANGE(route_key) \n"
+ "(PARTITION `p202209` VALUES LESS THAN (\"2022-10-01\"),\n"
+ "PARTITION `p202210` VALUES LESS THAN (\"2022-11-01\"),\n"
+ "PARTITION `p202211` VALUES LESS THAN (\"2022-12-01\")) \n"
+ "DISTRIBUTED BY HASH(`task_insert_time` ) BUCKETS 32 \n"
+ "PROPERTIES\n"
+ "(\n"
+ " \"replication_num\" = \"1\", \n"
+ " \"light_schema_change\" = \"true\" \n"
+ ");");
});
ExceptionChecker.expectThrowsWithMsg(AnalysisException.class, "Complex type column can't be partition column",
() -> {
createTable("create table test.test_array2( \n"
+ "task_insert_time BIGINT NOT NULL DEFAULT \"0\" COMMENT \"\" , \n"
+ "task_project ARRAY<VARCHAR(64)> DEFAULT NULL COMMENT \"\" ,\n"
+ "route_key DATEV2 NOT NULL COMMENT \"range分区键\"\n"
+ ") \n"
+ "DUPLICATE KEY(`task_insert_time`) \n"
+ " COMMENT \"\"\n"
+ "PARTITION BY RANGE(task_project) \n"
+ "(PARTITION `p202209` VALUES LESS THAN (\"2022-10-01\"),\n"
+ "PARTITION `p202210` VALUES LESS THAN (\"2022-11-01\"),\n"
+ "PARTITION `p202211` VALUES LESS THAN (\"2022-12-01\")) \n"
+ "DISTRIBUTED BY HASH(`task_insert_time` ) BUCKETS 32 \n"
+ "PROPERTIES\n"
+ "(\n"
+ " \"replication_num\" = \"1\", \n"
+ " \"light_schema_change\" = \"true\" \n"
+ ");");
});
}
}