Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2330,7 +2330,11 @@ private void checkPartitionNullity(List<Column> baseSchema, PartitionDesc partit
private void checkLegalityofPartitionExprs(CreateTableStmt stmt, PartitionDesc partitionDesc)
throws AnalysisException {
for (Expr expr : partitionDesc.getPartitionExprs()) {
if (expr != null && expr instanceof FunctionCallExpr) { // test them
if (expr instanceof FunctionCallExpr) { // test them
if (!partitionDesc.isAutoCreatePartitions() || partitionDesc.getType() != PartitionType.RANGE) {
throw new AnalysisException("only Auto Range Partition support FunctionCallExpr");
}

FunctionCallExpr func = (FunctionCallExpr) expr;
ArrayList<Expr> children = func.getChildren();
Type[] childTypes = new Type[children.size()];
Expand All @@ -2354,6 +2358,12 @@ private void checkLegalityofPartitionExprs(CreateTableStmt stmt, PartitionDesc p
if (fn == null) {
throw new AnalysisException("partition expr " + func.getExprName() + " is illegal!");
}
} else if (expr instanceof SlotRef) {
if (partitionDesc.isAutoCreatePartitions() && partitionDesc.getType() == PartitionType.RANGE) {
throw new AnalysisException("Auto Range Partition need FunctionCallExpr");
}
} else {
throw new AnalysisException("partition expr " + expr.getExprName() + " is illegal!");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,20 @@ suite("test_auto_list_partition") {
result12 = sql "show partitions from stream_load_list_test_table_string_key"
logger.info("${result12}")
assertEquals(result12.size(), 4)

sql "drop table if exists awh_test_list_auto"
test {
sql """
CREATE TABLE awh_test_list_auto (
DATE_ID BIGINT NOT NULL COMMENT 'DATE_ID',
LAST_UPLOAD_TIME DATETIME COMMENT 'LAST_UPLOAD_TIME'
)
AUTO PARTITION BY LIST (sum(DATE_ID))()
DISTRIBUTED BY HASH(DATE_ID) BUCKETS AUTO
PROPERTIES (
"replication_num" = "1"
);
"""
exception "auto create partition only support slotRef in list partitions."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,77 @@ suite("test_auto_range_partition") {
def tmp_result = sql "select count() from isit"
assertEquals(tmp_result[0][0], 1)
qt_sql " select * from isit order by k "

sql "drop table if exists awh_test_range_auto"
test {
sql """
CREATE TABLE awh_test_range_auto (
DATE_ID BIGINT NOT NULL,
LAST_UPLOAD_TIME DATETIME
)
AUTO PARTITION BY RANGE (DATE_ID)()
DISTRIBUTED BY HASH(DATE_ID) BUCKETS AUTO
PROPERTIES (
"replication_num" = "1"
);
"""
exception "Auto Range Partition need FunctionCallExpr"
}
test {
sql """
CREATE TABLE awh_test_range_auto (
DATE_ID BIGINT NOT NULL,
LAST_UPLOAD_TIME DATETIME
)
AUTO PARTITION BY RANGE (date(DATE_ID))()
DISTRIBUTED BY HASH(DATE_ID) BUCKETS AUTO
PROPERTIES (
"replication_num" = "1"
);
"""
exception "auto create partition only support function call expr is"
}
test {
sql """
CREATE TABLE awh_test_range_auto (
DATE_ID BIGINT NOT NULL,
LAST_UPLOAD_TIME DATETIME
)
AUTO PARTITION BY RANGE (date_trunc(DATE_ID))()
DISTRIBUTED BY HASH(DATE_ID) BUCKETS AUTO
PROPERTIES (
"replication_num" = "1"
);
"""
exception "partition expr date_trunc is illegal!"
}
test {
sql """
CREATE TABLE awh_test_range_auto (
DATE_ID BIGINT NOT NULL,
LAST_UPLOAD_TIME DATETIME
)
AUTO PARTITION BY RANGE (date_trunc(DATE_ID, 'year'))()
DISTRIBUTED BY HASH(DATE_ID) BUCKETS AUTO
PROPERTIES (
"replication_num" = "1"
);
"""
exception "partition expr date_trunc is illegal!"
}
sql """
CREATE TABLE awh_test_range_auto (
DATE_ID BIGINT NOT NULL,
LAST_UPLOAD_TIME DATETIME NOT NULL
)
AUTO PARTITION BY RANGE (date_trunc(LAST_UPLOAD_TIME, 'yeear'))()
DISTRIBUTED BY HASH(DATE_ID) BUCKETS AUTO
PROPERTIES (
"replication_num" = "1"
);
"""
test {
sql "insert into awh_test_range_auto values (1,'20201212')"
exception "date_trunc function second param only support argument is"
}
}