|
18 | 18 | import java.util.List; |
19 | 19 | import java.util.function.Consumer; |
20 | 20 | import java.util.function.Function; |
| 21 | +import java.util.function.Predicate; |
21 | 22 |
|
22 | 23 | /** |
23 | 24 | * There are two main types of plans, {@code LogicalPlan} and {@code PhysicalPlan} |
@@ -109,22 +110,36 @@ public <E extends Expression> PlanType transformExpressionsOnlyUp(Class<E> typeT |
109 | 110 | return transformPropertiesOnly(Object.class, e -> doTransformExpression(e, exp -> exp.transformUp(typeToken, rule))); |
110 | 111 | } |
111 | 112 |
|
112 | | - public PlanType transformExpressionsDown(Function<Expression, ? extends Expression> rule) { |
113 | | - return transformExpressionsDown(Expression.class, rule); |
114 | | - } |
115 | | - |
116 | 113 | public <E extends Expression> PlanType transformExpressionsDown(Class<E> typeToken, Function<E, ? extends Expression> rule) { |
117 | 114 | return transformPropertiesDown(Object.class, e -> doTransformExpression(e, exp -> exp.transformDown(typeToken, rule))); |
118 | 115 | } |
119 | 116 |
|
120 | | - public PlanType transformExpressionsUp(Function<Expression, ? extends Expression> rule) { |
121 | | - return transformExpressionsUp(Expression.class, rule); |
| 117 | + public <E extends Expression> PlanType transformExpressionsDown( |
| 118 | + Predicate<Node<?>> shouldVisit, |
| 119 | + Class<E> typeToken, |
| 120 | + Function<E, ? extends Expression> rule |
| 121 | + ) { |
| 122 | + return transformDown( |
| 123 | + shouldVisit, |
| 124 | + t -> t.transformNodeProps(Object.class, e -> doTransformExpression(e, exp -> exp.transformDown(typeToken, rule))) |
| 125 | + ); |
122 | 126 | } |
123 | 127 |
|
124 | 128 | public <E extends Expression> PlanType transformExpressionsUp(Class<E> typeToken, Function<E, ? extends Expression> rule) { |
125 | 129 | return transformPropertiesUp(Object.class, e -> doTransformExpression(e, exp -> exp.transformUp(typeToken, rule))); |
126 | 130 | } |
127 | 131 |
|
| 132 | + public <E extends Expression> PlanType transformExpressionsUp( |
| 133 | + Predicate<Node<?>> shouldVisit, |
| 134 | + Class<E> typeToken, |
| 135 | + Function<E, ? extends Expression> rule |
| 136 | + ) { |
| 137 | + return transformUp( |
| 138 | + shouldVisit, |
| 139 | + t -> t.transformNodeProps(Object.class, e -> doTransformExpression(e, exp -> exp.transformUp(typeToken, rule))) |
| 140 | + ); |
| 141 | + } |
| 142 | + |
128 | 143 | @SuppressWarnings("unchecked") |
129 | 144 | private static Object doTransformExpression(Object arg, Function<Expression, ? extends Expression> traversal) { |
130 | 145 | if (arg instanceof Expression exp) { |
@@ -184,18 +199,10 @@ public <E extends Expression> void forEachExpression(Class<E> typeToken, Consume |
184 | 199 | forEachPropertyOnly(Object.class, e -> doForEachExpression(e, exp -> exp.forEachDown(typeToken, rule))); |
185 | 200 | } |
186 | 201 |
|
187 | | - public void forEachExpressionDown(Consumer<? super Expression> rule) { |
188 | | - forEachExpressionDown(Expression.class, rule); |
189 | | - } |
190 | | - |
191 | 202 | public <E extends Expression> void forEachExpressionDown(Class<? extends E> typeToken, Consumer<? super E> rule) { |
192 | 203 | forEachPropertyDown(Object.class, e -> doForEachExpression(e, exp -> exp.forEachDown(typeToken, rule))); |
193 | 204 | } |
194 | 205 |
|
195 | | - public void forEachExpressionUp(Consumer<? super Expression> rule) { |
196 | | - forEachExpressionUp(Expression.class, rule); |
197 | | - } |
198 | | - |
199 | 206 | public <E extends Expression> void forEachExpressionUp(Class<E> typeToken, Consumer<? super E> rule) { |
200 | 207 | forEachPropertyUp(Object.class, e -> doForEachExpression(e, exp -> exp.forEachUp(typeToken, rule))); |
201 | 208 | } |
|
0 commit comments