This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push:
new e7d9438 [Bug] Fix analysis error when there are different types in
case-when-then-else with group by clause (#4646)
e7d9438 is described below
commit e7d9438fd90aab9e22d3237c20a036d7388209a9
Author: xy720 <[email protected]>
AuthorDate: Wed Sep 23 11:15:28 2020 +0800
[Bug] Fix analysis error when there are different types in
case-when-then-else with group by clause (#4646)
---
.../java/org/apache/doris/analysis/AggregateInfo.java | 9 +++++++--
.../src/main/java/org/apache/doris/analysis/SlotRef.java | 1 -
.../test/java/org/apache/doris/planner/QueryPlanTest.java | 15 +++++++++++++++
3 files changed, 22 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 e0d0ac5..cc483e3 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 final class AggregateInfo extends AggregateInfoBase
{
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 ad0606d..16793f2 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 class SlotRef extends Expr {
}
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 ffc0860..75720cb 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,21 @@ public class QueryPlanTest {
// 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'"));
+
+ // 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<SlotRef>
+ 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:<slot 0> `k1`"));
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]