This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 5219d2aab0 [fix](union)the result exprs of union node should
substitute by child node's smap (#11933)
5219d2aab0 is described below
commit 5219d2aab062d4faf60ba5f516c2528bc488fcc4
Author: starocean999 <[email protected]>
AuthorDate: Wed Aug 24 19:43:40 2022 +0800
[fix](union)the result exprs of union node should substitute by child
node's smap (#11933)
union node's result exprs should be substitued by child node's smap first,
then the following "computePassthrough" method would have correct information
to do its job.
---
.../org/apache/doris/planner/SetOperationNode.java | 12 +++++-
.../data/correctness/test_union_with_subquery.out | 4 ++
.../correctness/test_union_with_subquery.groovy | 49 ++++++++++++++++++++++
3 files changed, 63 insertions(+), 2 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/planner/SetOperationNode.java
b/fe/fe-core/src/main/java/org/apache/doris/planner/SetOperationNode.java
index 6e56f6ffd2..bd130a8957 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/SetOperationNode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/SetOperationNode.java
@@ -144,6 +144,15 @@ public abstract class SetOperationNode extends PlanNode {
@Override
public void finalize(Analyzer analyzer) throws UserException {
super.finalize(analyzer);
+ // the resultExprLists should be substituted by child's output smap
+ // because the result exprs are column A, B, but the child output
exprs are column B, A
+ // after substituted, the next computePassthrough method will get
correct info to do its job
+ List<List<Expr>> substitutedResultExprLists = Lists.newArrayList();
+ for (int i = 0; i < resultExprLists.size(); ++i) {
+ substitutedResultExprLists.add(Expr.substituteList(
+ resultExprLists.get(i), children.get(i).getOutputSmap(),
analyzer, true));
+ }
+ resultExprLists = substitutedResultExprLists;
// In Doris-6380, moved computePassthrough() and the materialized
position of resultExprs/constExprs
// from this.init() to this.finalize(), and will not call
SetOperationNode::init() again at the end
// of createSetOperationNodeFragment().
@@ -179,8 +188,7 @@ public abstract class SetOperationNode extends PlanNode {
newExprList.add(exprList.get(j));
}
}
- materializedResultExprLists.add(
- Expr.substituteList(newExprList,
getChild(i).getOutputSmap(), analyzer, true));
+ materializedResultExprLists.add(newExprList);
}
Preconditions.checkState(
materializedResultExprLists.size() == getChildren().size());
diff --git a/regression-test/data/correctness/test_union_with_subquery.out
b/regression-test/data/correctness/test_union_with_subquery.out
new file mode 100644
index 0000000000..a4cca003b9
--- /dev/null
+++ b/regression-test/data/correctness/test_union_with_subquery.out
@@ -0,0 +1,4 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !sql --
+1 1
+
diff --git a/regression-test/suites/correctness/test_union_with_subquery.groovy
b/regression-test/suites/correctness/test_union_with_subquery.groovy
new file mode 100644
index 0000000000..5362231fda
--- /dev/null
+++ b/regression-test/suites/correctness/test_union_with_subquery.groovy
@@ -0,0 +1,49 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_union_with_subquery") {
+ sql """ DROP TABLE IF EXISTS A_union; """
+ sql """
+ create table A_union ( a int not null, b varchar(10) null )ENGINE=OLAP
+ DISTRIBUTED BY HASH(a) BUCKETS 1
+ PROPERTIES (
+ "replication_allocation" = "tag.location.default: 1",
+ "in_memory" = "false",
+ "storage_format" = "V2"
+ );
+ """
+
+ sql """ insert into A_union values( 1, '1' ); """
+
+ qt_sql """with c AS
+ (SELECT a,
+ b
+ FROM A_union
+ GROUP BY b, a ), d AS
+ (SELECT a,
+ b
+ FROM A_union
+ GROUP BY b, a )
+ SELECT *
+ FROM d
+ UNION
+ SELECT *
+ FROM c;
+ """
+
+ sql """ DROP TABLE IF EXISTS A_union; """
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]