Skip to content

Commit

Permalink
[fix](nereids) fix The children format needs to be [WhenClause+, Defa…
Browse files Browse the repository at this point in the history
…ultValue?] (apache#38491)

fix The children format needs to be [WhenClause+, DefaultValue?]

(cherry picked from commit 21a3db6)
  • Loading branch information
924060929 committed Aug 2, 2024
1 parent 5edcbd7 commit ae1ce9f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.doris.nereids.trees.expressions.visitor;

import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.WhenClause;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -33,6 +34,13 @@ public Expression visit(Expression expr, C context) {
return rewrite(this, expr, context);
}

@Override
public Expression visitWhenClause(WhenClause whenClause, C context) {
// should not rewrite when clause to other expression because CaseWhen require WhenClause as children
return rewrite(this, whenClause, context);
}


/** rewrite */
public static final <C> Expression rewrite(ExpressionVisitor<Expression, C> rewriter, Expression expr, C context) {
List<Expression> newChildren = new ArrayList<>();
Expand Down
38 changes: 38 additions & 0 deletions regression-test/suites/nereids_syntax_p0/join.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,42 @@ suite("join") {
where
ref_2.`id` is not NULL
"""

multi_sql """
drop table if exists table_test1;
drop table if exists table_test2;
CREATE TABLE table_test1 (
id VARCHAR(20) NULL,
long1 BIGINT NULL,
long2 BIGINT NULL,
) ENGINE=OLAP
DUPLICATE KEY(id)
COMMENT 'olap'
DISTRIBUTED BY HASH(id) BUCKETS AUTO
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
);
CREATE TABLE table_test2 (
id VARCHAR(20) NULL,
re_long_4 BIGINT NULL,
) ENGINE=OLAP
DUPLICATE KEY(id)
COMMENT 'olap'
DISTRIBUTED BY HASH(id) BUCKETS AUTO
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
);
SELECT 1
from table_test1 b
WHERE (
CASE
WHEN b.long2=(SELECT re_long_4 FROM table_test2 limit 1) THEN (select long1 from table_test1 limit 1 )
WHEN b.long2=(SELECT re_long_4 FROM table_test2 limit 1) THEN (select long1 from table_test1 limit 1)
ELSE b.long2
END
)>0;
"""
}

0 comments on commit ae1ce9f

Please sign in to comment.