This is an automated email from the ASF dual-hosted git repository. morrysnow 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 a95f47ac0a [ehancement](planner) Support filter the output of set operation node (#16666) a95f47ac0a is described below commit a95f47ac0af5d4ff6d667754b6e4d64647fa90a2 Author: AKIRA <33112463+kikyou1...@users.noreply.github.com> AuthorDate: Tue Feb 21 19:22:09 2023 +0800 [ehancement](planner) Support filter the output of set operation node (#16666) --- .../src/main/java/org/apache/doris/analysis/Analyzer.java | 11 +++++++++++ .../src/main/java/org/apache/doris/planner/PlanNode.java | 4 ++++ .../java/org/apache/doris/planner/SingleNodePlanner.java | 13 ++++++++++--- regression-test/data/query_p0/union/test_union.out | 3 +++ regression-test/suites/query_p0/union/test_union.groovy | 2 ++ 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java index 9e198aa152..76aa3bb4dd 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java @@ -397,6 +397,8 @@ public class Analyzer { private final Set<TupleId> markTupleIdsNotProcessed = Sets.newHashSet(); + private final Map<InlineViewRef, Set<Expr>> migrateFailedConjuncts = Maps.newHashMap(); + public GlobalState(Env env, ConnectContext context) { this.env = env; this.context = context; @@ -1204,6 +1206,15 @@ public class Analyzer { } } + public void registerMigrateFailedConjuncts(InlineViewRef ref, Expr e) { + Set<Expr> exprSet = globalState.migrateFailedConjuncts.computeIfAbsent(ref, (k) -> new HashSet<>()); + exprSet.add(e); + } + + public Set<Expr> findMigrateFailedConjuncts(InlineViewRef inlineViewRef) { + return globalState.migrateFailedConjuncts.get(inlineViewRef); + } + /** * register expr id * @param expr diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/PlanNode.java b/fe/fe-core/src/main/java/org/apache/doris/planner/PlanNode.java index 86c0520b27..08f59353af 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/PlanNode.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/PlanNode.java @@ -1134,4 +1134,8 @@ public abstract class PlanNode extends TreeNode<PlanNode> implements PlanStats { public List<SlotId> getOutputSlotIds() { return outputSlotIds; } + + public void setVConjunct(Set<Expr> exprs) { + vconjunct = convertConjunctsToAndCompoundPredicate(new ArrayList<>(exprs)); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java b/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java index 6b7162c54f..44d85396b9 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java @@ -1814,8 +1814,9 @@ public class SingleNodePlanner { newConjuncts = cloneExprs(newConjuncts); } } else { - Preconditions.checkArgument(select.getTableRefs().size() == 1); - viewAnalyzer.registerConjuncts(newConjuncts, select.getTableRefs().get(0).getId()); + for (Expr e : conjuncts) { + viewAnalyzer.registerMigrateFailedConjuncts(inlineViewRef, e); + } } } else { Preconditions.checkArgument(stmt instanceof SetOperationStmt); @@ -2150,7 +2151,13 @@ public class SingleNodePlanner { scanNode = createScanNode(analyzer, tblRef, selectStmt); } if (tblRef instanceof InlineViewRef) { - scanNode = createInlineViewPlan(analyzer, (InlineViewRef) tblRef); + InlineViewRef inlineViewRef = (InlineViewRef) tblRef; + scanNode = createInlineViewPlan(analyzer, inlineViewRef); + Analyzer viewAnalyzer = inlineViewRef.getAnalyzer(); + Set<Expr> exprs = viewAnalyzer.findMigrateFailedConjuncts(inlineViewRef); + if (CollectionUtils.isNotEmpty(exprs)) { + scanNode.setVConjunct(exprs); + } } if (scanNode == null) { throw new UserException("unknown TableRef node"); diff --git a/regression-test/data/query_p0/union/test_union.out b/regression-test/data/query_p0/union/test_union.out index fe0f9c1810..4d398f2f2a 100644 --- a/regression-test/data/query_p0/union/test_union.out +++ b/regression-test/data/query_p0/union/test_union.out @@ -364,3 +364,6 @@ hell0 2016-07-01 2016-07-02 +-- !union36 -- +1 2 + diff --git a/regression-test/suites/query_p0/union/test_union.groovy b/regression-test/suites/query_p0/union/test_union.groovy index cc52be330e..73ad6c013b 100644 --- a/regression-test/suites/query_p0/union/test_union.groovy +++ b/regression-test/suites/query_p0/union/test_union.groovy @@ -277,4 +277,6 @@ suite("test_union") { sql 'set enable_fallback_to_original_planner=false' sql 'set enable_nereids_planner=true' qt_union35 """select cast("2016-07-01" as date) union (select cast("2016-07-02 1:10:0" as date)) order by 1""" + + qt_union36 """SELECT a,2 as a FROM (SELECT '1' as a) b where a=1;""" } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org