[fix](Nereids) add logical project to prevent extra wrong column (#30459)

Issue Number: close #30264
This commit is contained in:
zzwwhh
2024-02-01 14:39:11 +08:00
committed by yiguolei
parent d024d65384
commit b86bd2672f
4 changed files with 28 additions and 9 deletions

View File

@ -45,6 +45,7 @@ import org.apache.doris.nereids.rules.analysis.ReplaceExpressionByChildOutput;
import org.apache.doris.nereids.rules.analysis.ResolveOrdinalInOrderByAndGroupBy;
import org.apache.doris.nereids.rules.analysis.SubqueryToApply;
import org.apache.doris.nereids.rules.analysis.UserAuthentication;
import org.apache.doris.nereids.rules.rewrite.MergeProjects;
import org.apache.doris.nereids.rules.rewrite.SemiJoinCommute;
import java.util.List;
@ -172,7 +173,8 @@ public class Analyzer extends AbstractBatchJobExecutor {
new CollectJoinConstraint()
),
topDown(new LeadingJoin()),
bottomUp(new SubqueryToApply())
bottomUp(new SubqueryToApply()),
topDown(new MergeProjects())
);
}
}

View File

@ -134,14 +134,8 @@ public class SubqueryToApply implements AnalysisRuleFactory {
}
Set<Expression> conjuncts = ImmutableSet.copyOf(newConjuncts.build());
Plan newFilter = new LogicalFilter<>(conjuncts, applyPlan);
if (conjuncts.stream().flatMap(c -> c.children().stream())
.anyMatch(MarkJoinSlotReference.class::isInstance)) {
return new LogicalProject<>(applyPlan.getOutput().stream()
.filter(s -> !(s instanceof MarkJoinSlotReference))
.collect(ImmutableList.toImmutableList()), newFilter);
} else {
return newFilter;
}
return new LogicalProject<>(filter.getOutput().stream().collect(ImmutableList.toImmutableList()),
newFilter);
})
),
RuleType.PROJECT_SUBQUERY_TO_APPLY.build(logicalProject().thenApply(ctx -> {