Skip to content

Commit b3d68d7

Browse files
Test partial fix for top
1 parent baf4f2f commit b3d68d7

File tree

2 files changed

+12
-9
lines changed
  • x-pack/plugin/esql/src
    • main/java/org/elasticsearch/xpack/esql/expression/function/aggregate
    • test/java/org/elasticsearch/xpack/esql/expression/function/aggregate

2 files changed

+12
-9
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Top.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.FIRST;
4343
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND;
4444
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;
4646
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isString;
4747
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
4848

@@ -116,8 +116,8 @@ Expression orderField() {
116116
return parameters().get(1);
117117
}
118118

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 */);
121121
}
122122

123123
private String orderRawValue() {
@@ -148,23 +148,26 @@ protected TypeResolution resolveType() {
148148
"ip",
149149
"string",
150150
"numeric except unsigned_long or counter types"
151-
).and(isNotNullAndFoldable(limitField(), sourceText(), SECOND))
151+
).and(isNotNull(limitField(), sourceText(), SECOND))
152152
.and(isType(limitField(), dt -> dt == DataType.INTEGER, sourceText(), SECOND, "integer"))
153-
.and(isNotNullAndFoldable(orderField(), sourceText(), THIRD))
153+
.and(isNotNull(orderField(), sourceText(), THIRD))
154154
.and(isString(orderField(), sourceText(), THIRD));
155155

156156
if (typeResolution.unresolved()) {
157157
return typeResolution;
158158
}
159159

160-
var limit = limitValue();
160+
Integer limit = limitValue();
161161
var order = orderRawValue();
162162

163+
if (limit == null) {
164+
return new TypeResolution(format(null, "Limit must be a constant integer in [{}], found [{}]", sourceText(), limit));
165+
}
163166
if (limit <= 0) {
164167
return new TypeResolution(format(null, "Limit must be greater than 0 in [{}], found [{}]", sourceText(), limit));
165168
}
166169

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) {
168171
return new TypeResolution(
169172
format(null, "Invalid order value in [{}], expected [{}, {}] but got [{}]", sourceText(), ORDER_ASC, ORDER_DESC, order)
170173
);

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/TopTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public static Iterable<Object[]> parameters() {
262262
new TestCaseSupplier.TypedData(null, DataType.INTEGER, "limit").forceLiteral(),
263263
new TestCaseSupplier.TypedData(new BytesRef("desc"), DataType.KEYWORD, "order").forceLiteral()
264264
),
265-
"second argument of [source] cannot be null, received [limit]"
265+
"Limit must be a constant integer in [source], found [null]"
266266
)
267267
),
268268
new TestCaseSupplier(
@@ -273,7 +273,7 @@ public static Iterable<Object[]> parameters() {
273273
new TestCaseSupplier.TypedData(1, DataType.INTEGER, "limit").forceLiteral(),
274274
new TestCaseSupplier.TypedData(null, DataType.KEYWORD, "order").forceLiteral()
275275
),
276-
"third argument of [source] cannot be null, received [order]"
276+
"Invalid order value in [source], expected [ASC, DESC] but got [null]"
277277
)
278278
)
279279
)

0 commit comments

Comments
 (0)