From 909ffb21ad54e0b38a7751eaa545a5412c78f231 Mon Sep 17 00:00:00 2001 From: xy720 Date: Tue, 22 Sep 2020 14:37:15 +0800 Subject: [PATCH 1/2] save code --- .../org/apache/doris/analysis/AggregateInfo.java | 9 +++++++-- .../main/java/org/apache/doris/analysis/SlotRef.java | 1 - .../java/org/apache/doris/planner/QueryPlanTest.java | 12 ++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AggregateInfo.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AggregateInfo.java index e0d0ac5f350f07..cc483e30c61d15 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AggregateInfo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AggregateInfo.java @@ -662,8 +662,13 @@ public void createSmaps(Analyzer analyzer) { exprs.addAll(aggregateExprs_); for (int i = 0; i < exprs.size(); ++i) { Expr expr = exprs.get(i); - outputTupleSmap_.put(expr.clone(), - new SlotRef(outputTupleDesc_.getSlots().get(i))); + if (expr.isImplicitCast()) { + outputTupleSmap_.put(expr.getChild(0).clone(), + new SlotRef(outputTupleDesc_.getSlots().get(i))); + } else { + outputTupleSmap_.put(expr.clone(), + new SlotRef(outputTupleDesc_.getSlots().get(i))); + } if (!requiresIntermediateTuple()) continue; intermediateTupleSmap_.put(expr.clone(), diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java index ad0606d8dc9a59..16793f259f5fd8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java @@ -93,7 +93,6 @@ public Expr clone() { } public SlotDescriptor getDesc() { - Preconditions.checkState(isAnalyzed); Preconditions.checkNotNull(desc); return desc; } diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java index ffc0860b1f65ec..05f79a63aeff04 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java @@ -906,6 +906,18 @@ public void testConvertCaseWhenToConstant() throws Exception { // 4.2.1 test null in when expr String sql421 = "select case 'a' when null then 'a' else 'other' end as col421"; Assert.assertTrue(StringUtils.containsIgnoreCase(UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "explain " + sql421), "constant exprs: \n 'other'")); + + String sql51 = "select case when 132 then k7 else 'all' end as col51 from test.baseall group by col51"; + Assert.assertTrue(StringUtils.containsIgnoreCase(UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "explain " + sql51), + "OUTPUT EXPRS: CASE WHEN 132 THEN `k7` ELSE 'all' END")); + + String sql52 = "select case when 2 < 1 then 'all' else k7 end as col52 from test.baseall group by col52"; + Assert.assertTrue(StringUtils.containsIgnoreCase(UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "explain " + sql52), + "OUTPUT EXPRS: `k7`")); + + String sql53 = "select case when 2 < 1 then 'all' else k1 end as col53 from test.baseall group by col53"; + Assert.assertTrue(StringUtils.containsIgnoreCase(UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "explain " + sql53), + "OUTPUT EXPRS: `k1`")); } @Test From 9b38e2a90841f6a1e81a7ec3cad41ae220f8c291 Mon Sep 17 00:00:00 2001 From: xy720 Date: Tue, 22 Sep 2020 18:43:58 +0800 Subject: [PATCH 2/2] add comments --- .../src/test/java/org/apache/doris/planner/QueryPlanTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java index 05f79a63aeff04..75720cbc181f8a 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java @@ -907,14 +907,17 @@ public void testConvertCaseWhenToConstant() throws Exception { String sql421 = "select case 'a' when null then 'a' else 'other' end as col421"; Assert.assertTrue(StringUtils.containsIgnoreCase(UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "explain " + sql421), "constant exprs: \n 'other'")); + // 5.1 test same type in then expr and else expr String sql51 = "select case when 132 then k7 else 'all' end as col51 from test.baseall group by col51"; Assert.assertTrue(StringUtils.containsIgnoreCase(UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "explain " + sql51), "OUTPUT EXPRS: CASE WHEN 132 THEN `k7` ELSE 'all' END")); + // 5.2 test same type in then expr and else expr String sql52 = "select case when 2 < 1 then 'all' else k7 end as col52 from test.baseall group by col52"; Assert.assertTrue(StringUtils.containsIgnoreCase(UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "explain " + sql52), "OUTPUT EXPRS: `k7`")); + // 5.3 test different in then expr and else expr, and return CastExpr String sql53 = "select case when 2 < 1 then 'all' else k1 end as col53 from test.baseall group by col53"; Assert.assertTrue(StringUtils.containsIgnoreCase(UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "explain " + sql53), "OUTPUT EXPRS: `k1`"));