|
34 | 34 | import org.elasticsearch.xpack.esql.common.Failure; |
35 | 35 | import org.elasticsearch.xpack.esql.common.Failures; |
36 | 36 | import org.elasticsearch.xpack.esql.core.expression.Expression; |
37 | | -import org.elasticsearch.xpack.esql.core.expression.FoldContext; |
38 | 37 | import org.elasticsearch.xpack.esql.core.expression.Literal; |
39 | 38 | import org.elasticsearch.xpack.esql.core.tree.NodeInfo; |
40 | 39 | import org.elasticsearch.xpack.esql.core.tree.Source; |
|
48 | 47 | import org.elasticsearch.xpack.esql.planner.PlannerUtils; |
49 | 48 |
|
50 | 49 | import java.io.IOException; |
51 | | -import java.util.ArrayList; |
52 | 50 | import java.util.Arrays; |
53 | 51 | import java.util.List; |
54 | 52 |
|
@@ -147,36 +145,25 @@ public boolean foldable() { |
147 | 145 | return field.foldable() && (order == null || order.foldable()); |
148 | 146 | } |
149 | 147 |
|
150 | | - @Override |
151 | | - public Object fold(FoldContext ctx) { |
152 | | - if (order != null && order instanceof Literal == false) { |
153 | | - // if we are here, we know that order is foldable, so we can safely fold it |
154 | | - Literal newOrder = Literal.of(ctx, order); |
155 | | - List<Expression> newChildren = new ArrayList<>(); |
156 | | - newChildren.add(field); |
157 | | - newChildren.add(newOrder); |
158 | | - return replaceChildren(newChildren).fold(ctx); |
159 | | - } |
160 | | - return super.fold(ctx); |
161 | | - } |
162 | | - |
163 | 148 | @Override |
164 | 149 | public EvalOperator.ExpressionEvaluator.Factory toEvaluator(ToEvaluator toEvaluator) { |
165 | 150 | boolean ordering = true; |
166 | | - if (isValidOrder() == false) { |
167 | | - throw new IllegalArgumentException( |
168 | | - LoggerMessageFormat.format( |
169 | | - null, |
170 | | - INVALID_ORDER_ERROR, |
171 | | - sourceText(), |
172 | | - BytesRefs.toString(ASC.value()), |
173 | | - BytesRefs.toString(DESC.value()), |
174 | | - BytesRefs.toString(order.fold(toEvaluator.foldCtx())) |
175 | | - ) |
176 | | - ); |
177 | | - } |
178 | 151 | if (order != null && order.foldable()) { |
179 | | - ordering = BytesRefs.toString(order.fold(toEvaluator.foldCtx())).equalsIgnoreCase(BytesRefs.toString(ASC.value())); |
| 152 | + String orderValue = BytesRefs.toString(order.fold(toEvaluator.foldCtx())); |
| 153 | + if (orderValue.equalsIgnoreCase(BytesRefs.toString(DESC.value())) == false |
| 154 | + && orderValue.equalsIgnoreCase(BytesRefs.toString(ASC.value())) == false) { |
| 155 | + throw new IllegalArgumentException( |
| 156 | + LoggerMessageFormat.format( |
| 157 | + null, |
| 158 | + INVALID_ORDER_ERROR, |
| 159 | + sourceText(), |
| 160 | + BytesRefs.toString(ASC.value()), |
| 161 | + BytesRefs.toString(DESC.value()), |
| 162 | + orderValue |
| 163 | + ) |
| 164 | + ); |
| 165 | + } |
| 166 | + ordering = orderValue.equalsIgnoreCase(BytesRefs.toString(ASC.value())); |
180 | 167 | } |
181 | 168 |
|
182 | 169 | return switch (PlannerUtils.toElementType(field.dataType())) { |
|
0 commit comments