diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java index 6e3382aa8a155b..56f835eda85a14 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java @@ -2330,7 +2330,11 @@ private void checkPartitionNullity(List 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 children = func.getChildren(); Type[] childTypes = new Type[children.size()]; @@ -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!"); } } } diff --git a/regression-test/suites/partition_p0/auto_partition/test_auto_list_partition.groovy b/regression-test/suites/partition_p0/auto_partition/test_auto_list_partition.groovy index 7868f1ffb9a514..5855ecc06e1085 100644 --- a/regression-test/suites/partition_p0/auto_partition/test_auto_list_partition.groovy +++ b/regression-test/suites/partition_p0/auto_partition/test_auto_list_partition.groovy @@ -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." + } } diff --git a/regression-test/suites/partition_p0/auto_partition/test_auto_range_partition.groovy b/regression-test/suites/partition_p0/auto_partition/test_auto_range_partition.groovy index 1102ba8f393b88..eadbcff4107459 100644 --- a/regression-test/suites/partition_p0/auto_partition/test_auto_range_partition.groovy +++ b/regression-test/suites/partition_p0/auto_partition/test_auto_range_partition.groovy @@ -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" + } }