[fix](nereids)FillUpMissingSlots rule didn't process standalone having clause correctly (#29143)
This commit is contained in:
@ -157,6 +157,25 @@ public class FillUpMissingSlots implements AnalysisRuleFactory {
|
||||
})
|
||||
),
|
||||
// Convert having to filter
|
||||
RuleType.FILL_UP_HAVING_PROJECT.build(
|
||||
logicalHaving(logicalProject()).then(having -> {
|
||||
LogicalProject<Plan> project = having.child();
|
||||
Set<Slot> projectOutputSet = project.getOutputSet();
|
||||
Set<Slot> notExistedInProject = having.getExpressions().stream()
|
||||
.map(Expression::getInputSlots)
|
||||
.flatMap(Set::stream)
|
||||
.filter(s -> !projectOutputSet.contains(s))
|
||||
.collect(Collectors.toSet());
|
||||
if (notExistedInProject.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
List<NamedExpression> projects = ImmutableList.<NamedExpression>builder()
|
||||
.addAll(project.getProjects()).addAll(notExistedInProject).build();
|
||||
return new LogicalProject<>(ImmutableList.copyOf(project.getOutput()),
|
||||
having.withChildren(new LogicalProject<>(projects, project.child())));
|
||||
})
|
||||
),
|
||||
// Convert having to filter
|
||||
RuleType.FILL_UP_HAVING_PROJECT.build(
|
||||
logicalHaving().then(having -> new LogicalFilter<>(having.getConjuncts(), having.child()))
|
||||
)
|
||||
|
||||
@ -329,10 +329,12 @@ public class ReorderJoin extends OneRewriteRuleFactory {
|
||||
Set<Expression> joinFilter, Set<Integer> usedPlansIndex, Map<Plan, JoinHintType> planToHintType) {
|
||||
List<Expression> otherJoinConditions = Lists.newArrayList();
|
||||
Set<ExprId> leftOutputExprIdSet = left.getOutputExprIdSet();
|
||||
int candidateIndex = 0;
|
||||
for (int i = 0; i < candidates.size(); i++) {
|
||||
if (usedPlansIndex.contains(i)) {
|
||||
continue;
|
||||
}
|
||||
candidateIndex = i;
|
||||
|
||||
Plan candidate = candidates.get(i);
|
||||
Set<ExprId> rightOutputExprIdSet = candidate.getOutputExprIdSet();
|
||||
@ -362,21 +364,14 @@ public class ReorderJoin extends OneRewriteRuleFactory {
|
||||
}
|
||||
// All { left -> one in [candidates] } is CrossJoin
|
||||
// Generate a CrossJoin
|
||||
for (int i = 0; i < candidates.size(); i++) {
|
||||
if (usedPlansIndex.contains(i)) {
|
||||
continue;
|
||||
}
|
||||
usedPlansIndex.add(i);
|
||||
Plan right = candidates.get(i);
|
||||
return new LogicalJoin<>(JoinType.CROSS_JOIN,
|
||||
ExpressionUtils.EMPTY_CONDITION,
|
||||
otherJoinConditions,
|
||||
JoinHint.fromRightPlanHintType(planToHintType.getOrDefault(right, JoinHintType.NONE)),
|
||||
Optional.empty(),
|
||||
left, right);
|
||||
}
|
||||
|
||||
throw new RuntimeException("findInnerJoin: can't reach here");
|
||||
usedPlansIndex.add(candidateIndex);
|
||||
Plan right = candidates.get(candidateIndex);
|
||||
return new LogicalJoin<>(JoinType.CROSS_JOIN,
|
||||
ExpressionUtils.EMPTY_CONDITION,
|
||||
otherJoinConditions,
|
||||
JoinHint.fromRightPlanHintType(planToHintType.getOrDefault(right, JoinHintType.NONE)),
|
||||
Optional.empty(),
|
||||
left, right);
|
||||
}
|
||||
|
||||
private boolean nonJoinAndNonFilter(Plan plan) {
|
||||
|
||||
Reference in New Issue
Block a user