Skip to content

Commit

Permalink
[fix](create-table) wrong judgement about partition column type (#15542)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
morningman committed Dec 31, 2022
1 parent 389e323 commit a50b334
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ public void analyze(List<ColumnDef> columnDefs, Map<String, String> otherPropert
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public PartitionInfo toPartitionInfo(List<Column> schema, Map<String, Long> part
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) {
Expand All @@ -94,10 +98,6 @@ public PartitionInfo toPartitionInfo(List<Column> schema, Map<String, Long> part
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,5 +644,46 @@ public void testCreateTableWithArrayType() throws Exception {
+ ") 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"
+ ");");
});
}
}

0 comments on commit a50b334

Please sign in to comment.