From bd49bb6faf2964875b360eb2e7571b7450cf4273 Mon Sep 17 00:00:00 2001 From: 924060929 <924060929@qq.com> Date: Mon, 29 Jul 2024 19:44:37 +0800 Subject: [PATCH] fix WhenClause --- .../apache/doris/monitor/jvm/JvmService.java | 6 +-- ...ctOtherJoinConditionForNestedLoopJoin.java | 5 ++- .../suites/nereids_syntax_p0/join.groovy | 38 +++++++++++++++++++ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/monitor/jvm/JvmService.java b/fe/fe-core/src/main/java/org/apache/doris/monitor/jvm/JvmService.java index a46443925de03c..01184cd3cd3ade 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/monitor/jvm/JvmService.java +++ b/fe/fe-core/src/main/java/org/apache/doris/monitor/jvm/JvmService.java @@ -38,11 +38,8 @@ public class JvmService { private final JvmInfo jvmInfo; - private JvmStats jvmStats; - public JvmService() { this.jvmInfo = JvmInfo.jvmInfo(); - this.jvmStats = JvmStats.jvmStats(); } public JvmInfo info() { @@ -50,8 +47,7 @@ public JvmInfo info() { } public synchronized JvmStats stats() { - jvmStats = JvmStats.jvmStats(); - return jvmStats; + return JvmStats.jvmStats(); } @Override diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ProjectOtherJoinConditionForNestedLoopJoin.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ProjectOtherJoinConditionForNestedLoopJoin.java index 7d28269005c141..bdd279fb7c2f31 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ProjectOtherJoinConditionForNestedLoopJoin.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ProjectOtherJoinConditionForNestedLoopJoin.java @@ -23,6 +23,7 @@ import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.NamedExpression; import org.apache.doris.nereids.trees.expressions.Slot; +import org.apache.doris.nereids.trees.expressions.WhenClause; import org.apache.doris.nereids.trees.expressions.visitor.DefaultExpressionRewriter; import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.logical.LogicalProject; @@ -114,7 +115,9 @@ public Expression visit(Expression expression, ReplacerContext ctx) { if (input.isEmpty() || expression instanceof Slot) { return expression; } - if (ctx.leftSlots.containsAll(input)) { + if (expression instanceof WhenClause) { + return super.visit(expression, ctx); + } else if (ctx.leftSlots.containsAll(input)) { Alias alias = ctx.aliasMap.computeIfAbsent(expression, o -> new Alias(o)); ctx.leftAlias.add(alias); return alias.toSlot(); diff --git a/regression-test/suites/nereids_syntax_p0/join.groovy b/regression-test/suites/nereids_syntax_p0/join.groovy index 4b79f8f52a8353..53887b652074fc 100644 --- a/regression-test/suites/nereids_syntax_p0/join.groovy +++ b/regression-test/suites/nereids_syntax_p0/join.groovy @@ -273,4 +273,42 @@ suite("join") { """ order_qt_test "SELECT * FROM lineorder RIGHT SEMI JOIN supplier ON lineorder.lo_suppkey = supplier.s_suppkey and s_name='Supplier#000000029';" + + 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; + """ }