Skip to content

Commit

Permalink
[Enhancement](DDL) check illegal partition exprs (#40158)
Browse files Browse the repository at this point in the history
before:
```sql
mysql> CREATE TABLE not_auto_expr (
    ->     `TIME_STAMP` date NOT NULL
    -> )
    -> partition by range (date_trunc(`TIME_STAMP`, 'day'))()
    -> DISTRIBUTED BY HASH(`TIME_STAMP`) BUCKETS 10
    -> PROPERTIES (
    ->     "replication_allocation" = "tag.location.default: 1"
    -> );
Query OK, 0 rows affected (0.14 sec)
```
now:
```sql
mysql> CREATE TABLE not_auto_expr (
    ->     `TIME_STAMP` date NOT NULL
    -> )
    -> partition by range (date_trunc(`TIME_STAMP`, 'day'))()
    -> DISTRIBUTED BY HASH(`TIME_STAMP`) BUCKETS 10
    -> PROPERTIES (
    ->     "replication_allocation" = "tag.location.default: 1"
    -> );
ERROR 1105 (HY000): errCode = 2, detailMessage = errCode = 2, detailMessage = Non-auto partition table not support partition expr!
```
  • Loading branch information
zclllyybb committed Sep 11, 2024
1 parent ebe031c commit 9f8f1a8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.doris.analysis.StringLiteral;
import org.apache.doris.catalog.AggregateType;
import org.apache.doris.catalog.PartitionType;
import org.apache.doris.common.DdlException;
import org.apache.doris.nereids.analyzer.UnboundFunction;
import org.apache.doris.nereids.analyzer.UnboundSlot;
import org.apache.doris.nereids.exceptions.AnalysisException;
Expand Down Expand Up @@ -269,6 +270,14 @@ public PartitionDesc convertToPartitionDesc(boolean isExternal) {

try {
ArrayList<Expr> exprs = convertToLegacyAutoPartitionExprs(partitionList);

// only auto partition support partition expr
if (!isAutoPartition) {
if (exprs.stream().anyMatch(expr -> expr instanceof FunctionCallExpr)) {
throw new DdlException("Non-auto partition table not support partition expr!");
}
}

// here we have already extracted identifierPartitionColumns
if (partitionType.equals(PartitionType.RANGE.name())) {
if (isAutoPartition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,18 @@ suite("test_auto_partition_behavior") {
sql """ insert into test_change values ("20001212"); """
part_result = sql " show tablets from test_change "
assertEquals(part_result.size, 52 * replicaNum)

test {
sql """
CREATE TABLE not_auto_expr (
`TIME_STAMP` date NOT NULL
)
partition by range (date_trunc(`TIME_STAMP`, 'day'))()
DISTRIBUTED BY HASH(`TIME_STAMP`) BUCKETS 10
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
);
"""
exception "Non-auto partition table not support partition expr!"
}
}

0 comments on commit 9f8f1a8

Please sign in to comment.