| 
42 | 42 | import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.FIRST;  | 
43 | 43 | import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND;  | 
44 | 44 | import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.THIRD;  | 
45 |  | -import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isNotNullAndFoldable;  | 
 | 45 | +import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isNotNull;  | 
46 | 46 | import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isString;  | 
47 | 47 | import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;  | 
48 | 48 | 
 
  | 
@@ -116,8 +116,8 @@ Expression orderField() {  | 
116 | 116 |         return parameters().get(1);  | 
117 | 117 |     }  | 
118 | 118 | 
 
  | 
119 |  | -    private int limitValue() {  | 
120 |  | -        return (int) limitField().fold(FoldContext.small() /* TODO remove me */);  | 
 | 119 | +    private Integer limitValue() {  | 
 | 120 | +        return (Integer) limitField().fold(FoldContext.small() /* TODO remove me */);  | 
121 | 121 |     }  | 
122 | 122 | 
 
  | 
123 | 123 |     private String orderRawValue() {  | 
@@ -148,23 +148,26 @@ protected TypeResolution resolveType() {  | 
148 | 148 |             "ip",  | 
149 | 149 |             "string",  | 
150 | 150 |             "numeric except unsigned_long or counter types"  | 
151 |  | -        ).and(isNotNullAndFoldable(limitField(), sourceText(), SECOND))  | 
 | 151 | +        ).and(isNotNull(limitField(), sourceText(), SECOND))  | 
152 | 152 |             .and(isType(limitField(), dt -> dt == DataType.INTEGER, sourceText(), SECOND, "integer"))  | 
153 |  | -            .and(isNotNullAndFoldable(orderField(), sourceText(), THIRD))  | 
 | 153 | +            .and(isNotNull(orderField(), sourceText(), THIRD))  | 
154 | 154 |             .and(isString(orderField(), sourceText(), THIRD));  | 
155 | 155 | 
 
  | 
156 | 156 |         if (typeResolution.unresolved()) {  | 
157 | 157 |             return typeResolution;  | 
158 | 158 |         }  | 
159 | 159 | 
 
  | 
160 |  | -        var limit = limitValue();  | 
 | 160 | +        Integer limit = limitValue();  | 
161 | 161 |         var order = orderRawValue();  | 
162 | 162 | 
 
  | 
 | 163 | +        if (limit == null) {  | 
 | 164 | +            return new TypeResolution(format(null, "Limit must be a constant integer in [{}], found [{}]", sourceText(), limit));  | 
 | 165 | +        }  | 
163 | 166 |         if (limit <= 0) {  | 
164 | 167 |             return new TypeResolution(format(null, "Limit must be greater than 0 in [{}], found [{}]", sourceText(), limit));  | 
165 | 168 |         }  | 
166 | 169 | 
 
  | 
167 |  | -        if (order.equalsIgnoreCase(ORDER_ASC) == false && order.equalsIgnoreCase(ORDER_DESC) == false) {  | 
 | 170 | +        if (order == null || order.equalsIgnoreCase(ORDER_ASC) == false && order.equalsIgnoreCase(ORDER_DESC) == false) {  | 
168 | 171 |             return new TypeResolution(  | 
169 | 172 |                 format(null, "Invalid order value in [{}], expected [{}, {}] but got [{}]", sourceText(), ORDER_ASC, ORDER_DESC, order)  | 
170 | 173 |             );  | 
 | 
0 commit comments