[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.
This commit is contained in:
starocean999
2022-08-24 19:43:40 +08:00
committed by GitHub
parent 87dd9c6b8b
commit 5219d2aab0
3 changed files with 63 additions and 2 deletions

View File

@ -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());

View File

@ -0,0 +1,4 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
1 1

View File

@ -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; """
}