diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 index 0bfc2d313c..f8acaccb10 100644 --- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 +++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 @@ -121,7 +121,6 @@ partitionSpec // TODO: support analyze external table partition spec https://github.com/apache/doris/pull/24154 // | PARTITIONS LEFT_PAREN ASTERISK RIGHT_PAREN // | PARTITIONS WITH RECENT - LEFT_PAREN referenceSlots+=errorCapturingIdentifier (COMMA referenceSlots+=errorCapturingIdentifier)* RIGHT_PAREN ; dataDesc diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteFromCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteFromCommand.java index f77cdd1cc8..6e9ee4ca01 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteFromCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DeleteFromCommand.java @@ -127,9 +127,13 @@ public class DeleteFromCommand extends Command implements ForwardWithSync { checkPredicate(conjunct); } } catch (Exception e) { - new DeleteFromUsingCommand(nameParts, tableAlias, isTempPart, partitions, - logicalQuery, Optional.empty()).run(ctx, executor); - return; + try { + new DeleteFromUsingCommand(nameParts, tableAlias, isTempPart, partitions, + logicalQuery, Optional.empty()).run(ctx, executor); + return; + } catch (Exception e2) { + throw e; + } } // call delete handler to process @@ -226,56 +230,65 @@ public class DeleteFromCommand extends Command implements ForwardWithSync { } } + private void checkComparisonPredicate(ComparisonPredicate cp) { + if (!(cp.left() instanceof SlotReference)) { + throw new AnalysisException( + "Left expr of binary predicate should be column name, predicate: " + cp.toSql() + + ", left expr type:" + cp.left().getDataType()); + } + if (!(cp.right() instanceof Literal)) { + throw new AnalysisException( + "Right expr of binary predicate should be value, predicate: " + cp.toSql() + + ", right expr type:" + cp.right().getDataType()); + } + } + + private void checkIsNull(IsNull isNull) { + if (!(isNull.child() instanceof SlotReference)) { + throw new AnalysisException( + "Child expr of is_null predicate should be column name, predicate: " + isNull.toSql()); + } + } + + private void checkInPredicate(InPredicate in) { + if (!(in.getCompareExpr() instanceof SlotReference)) { + throw new AnalysisException( + "Left expr of in predicate should be column name, predicate: " + in.toSql() + + ", left expr type:" + in.getCompareExpr().getDataType()); + } + int maxAllowedInElementNumOfDelete = Config.max_allowed_in_element_num_of_delete; + if (in.getOptions().size() > maxAllowedInElementNumOfDelete) { + throw new AnalysisException("Element num of in predicate should not be more than " + + maxAllowedInElementNumOfDelete); + } + for (Expression option : in.getOptions()) { + if (!(option instanceof Literal)) { + throw new AnalysisException("Child of in predicate should be value, but get " + option); + } + } + } + private void checkPredicate(Expression predicate) { if (predicate instanceof And) { checkPredicate(((And) predicate).left()); checkPredicate(((And) predicate).right()); } else if (predicate instanceof ComparisonPredicate) { - ComparisonPredicate cp = (ComparisonPredicate) predicate; - if (!(cp.left() instanceof SlotReference)) { - throw new AnalysisException( - "Left expr of binary predicate should be column name, predicate: " + predicate.toSql() - + ", left expr type:" + cp.left().getDataType()); - } - if (!(cp.right() instanceof Literal)) { - throw new AnalysisException( - "Right expr of binary predicate should be value, predicate: " + predicate.toSql() - + ", right expr type:" + cp.right().getDataType()); - } + checkComparisonPredicate((ComparisonPredicate) predicate); } else if (predicate instanceof IsNull) { - if (!(((IsNull) predicate).child() instanceof SlotReference)) { - throw new AnalysisException( - "Child expr of is_null predicate should be column name, predicate: " + predicate.toSql()); - } + checkIsNull((IsNull) predicate); } else if (predicate instanceof Not) { Expression child = ((Not) predicate).child(); if (child instanceof IsNull) { - if (!(((IsNull) child).child() instanceof SlotReference)) { - throw new AnalysisException( - "Child expr of is_null predicate should be column name, predicate: " + predicate.toSql()); - } + checkIsNull((IsNull) child); + } else if (child instanceof ComparisonPredicate) { + checkComparisonPredicate((ComparisonPredicate) child); } else { throw new AnalysisException("Where clause only supports compound predicate," + " binary predicate, is_null predicate or in predicate. But we meet " + child.toSql()); } } else if (predicate instanceof InPredicate) { - InPredicate in = (InPredicate) predicate; - if (!(in.getCompareExpr() instanceof SlotReference)) { - throw new AnalysisException( - "Left expr of in predicate should be column name, predicate: " + predicate.toSql() - + ", left expr type:" + in.getCompareExpr().getDataType()); - } - int maxAllowedInElementNumOfDelete = Config.max_allowed_in_element_num_of_delete; - if (in.getOptions().size() > maxAllowedInElementNumOfDelete) { - throw new AnalysisException("Element num of in predicate should not be more than " - + maxAllowedInElementNumOfDelete); - } - for (Expression option : in.getOptions()) { - if (!(option instanceof Literal)) { - throw new AnalysisException("Child of in predicate should be value, but get " + option); - } - } + checkInPredicate((InPredicate) predicate); } else { throw new AnalysisException("Where clause only supports compound predicate," + " binary predicate, is_null predicate or in predicate. But we meet "