|
23 | 23 | import org.apache.doris.nereids.trees.expressions.Expression; |
24 | 24 | import org.apache.doris.nereids.trees.expressions.NamedExpression; |
25 | 25 | import org.apache.doris.nereids.trees.expressions.Slot; |
| 26 | +import org.apache.doris.nereids.util.ExpressionUtils; |
26 | 27 | import org.apache.doris.nereids.util.PlanUtils; |
27 | 28 |
|
28 | | -import com.google.common.collect.ImmutableList; |
29 | 29 | import com.google.common.collect.ImmutableMap; |
30 | 30 |
|
31 | 31 | import java.util.Collection; |
@@ -78,22 +78,25 @@ default List<NamedExpression> mergeProjections(Project childProject) { |
78 | 78 | /** |
79 | 79 | * find projects, if not found the slot, then throw AnalysisException |
80 | 80 | */ |
81 | | - static List<NamedExpression> findProject( |
82 | | - Collection<? extends Slot> slotReferences, |
83 | | - List<NamedExpression> projects) throws AnalysisException { |
| 81 | + static List<? extends Expression> findProject( |
| 82 | + Collection<? extends Expression> expressions, |
| 83 | + List<? extends NamedExpression> projects) throws AnalysisException { |
84 | 84 | Map<ExprId, NamedExpression> exprIdToProject = projects.stream() |
85 | | - .collect(ImmutableMap.toImmutableMap(p -> p.getExprId(), p -> p)); |
| 85 | + .collect(ImmutableMap.toImmutableMap(NamedExpression::getExprId, p -> p)); |
86 | 86 |
|
87 | | - return slotReferences.stream() |
88 | | - .map(slot -> { |
89 | | - ExprId exprId = slot.getExprId(); |
90 | | - NamedExpression project = exprIdToProject.get(exprId); |
91 | | - if (project == null) { |
92 | | - throw new AnalysisException("ExprId " + slot.getExprId() + " no exists in " + projects); |
| 87 | + return ExpressionUtils.rewriteDownShortCircuit(expressions, |
| 88 | + expr -> { |
| 89 | + if (expr instanceof Slot) { |
| 90 | + Slot slot = (Slot) expr; |
| 91 | + ExprId exprId = slot.getExprId(); |
| 92 | + NamedExpression project = exprIdToProject.get(exprId); |
| 93 | + if (project == null) { |
| 94 | + throw new AnalysisException("ExprId " + slot.getExprId() + " no exists in " + projects); |
| 95 | + } |
| 96 | + return project; |
93 | 97 | } |
94 | | - return project; |
95 | | - }) |
96 | | - .collect(ImmutableList.toImmutableList()); |
| 98 | + return expr; |
| 99 | + }); |
97 | 100 | } |
98 | 101 | } |
99 | 102 |
|
|
0 commit comments