Skip to content

Commit

Permalink
[enchancement](delete) fix delete stmt return error with fold on be
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangstar333 committed Dec 18, 2023
1 parent a267a7f commit f87408a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,13 @@ void analyzePredicate(Expr predicate, Analyzer analyzer) throws AnalysisExceptio
binaryPredicate.analyze(analyzer);

ExprRewriter exprRewriter = new ExprRewriter(FoldConstantsRule.INSTANCE);
binaryPredicate.setChild(1, exprRewriter.rewrite(binaryPredicate.getChild(1), analyzer, null));
FoldConstantsRule foldConstantsRule = (FoldConstantsRule) exprRewriter.getRules().get(0);
Expr rightChild = binaryPredicate.getChild(1);
Expr rewrittenExpr = foldConstantsRule.apply(rightChild, analyzer, null);
if (rightChild != rewrittenExpr) {
binaryPredicate.setChild(1, rewrittenExpr);
}

Expr leftExpr = binaryPredicate.getChild(0);
if (!(leftExpr instanceof SlotRef)) {
throw new AnalysisException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ public ExprRewriter(ExprRewriteRule rule) {
rules = Lists.newArrayList(rule);
}

public List<ExprRewriteRule> getRules() {
return rules;
}

public void setInfoMVRewriter(Set<TupleId> disableTuplesMVRewriter, ExprSubstitutionMap mvSMap,
ExprSubstitutionMap aliasSMap) {
for (ExprRewriteRule rule : rules) {
Expand Down
17 changes: 17 additions & 0 deletions regression-test/suites/delete_p0/test_delete.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,21 @@ suite("test_delete") {
qt_check_data7 """ select * from every_type_table order by col_1; """
sql "drop table every_type_table"


sql "drop table if exists test2"
sql """
CREATE TABLE `test2`
(
col_1 int,
col_2 decimalv2(10,3)
)ENGINE=OLAP
duplicate KEY(`col_1`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`col_1`) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
);
"""
sql "set enable_fold_constant_by_be = true;"
sql "DELETE FROM test2 WHERE col_2 = cast(123.45 as decimalv2(10,3));"
}

0 comments on commit f87408a

Please sign in to comment.