[branch-2.1](DDL) check illegal partition exprs (#40158) (#40651)

pick https://github.com/apache/doris/pull/40158
This commit is contained in:
zclllhhjj
2024-09-11 22:37:55 +08:00
committed by GitHub
parent ebe031c019
commit bf156d1665
2 changed files with 23 additions and 0 deletions

View File

@ -28,6 +28,7 @@ import org.apache.doris.analysis.SlotRef;
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;
@ -269,6 +270,14 @@ public class PartitionTableInfo {
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) {

View File

@ -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!"
}
}