[ehancement](planner) Support filter the output of set operation node (#16666)
This commit is contained in:
@ -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
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -364,3 +364,6 @@ hell0
|
||||
2016-07-01
|
||||
2016-07-02
|
||||
|
||||
-- !union36 --
|
||||
1 2
|
||||
|
||||
|
||||
@ -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;"""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user