|
34 | 34 | import java.util.List;
|
35 | 35 |
|
36 | 36 | import static org.elasticsearch.common.logging.LoggerMessageFormat.format;
|
| 37 | +import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.FIRST; |
| 38 | +import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND; |
| 39 | +import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isNotNullAndFoldable; |
| 40 | +import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType; |
37 | 41 |
|
38 | 42 | public class Sample extends AggregateFunction implements ToAggregator {
|
39 | 43 | public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "Sample", Sample::new);
|
@@ -105,7 +109,18 @@ protected TypeResolution resolveType() {
|
105 | 109 | if (childrenResolved() == false) {
|
106 | 110 | return new TypeResolution("Unresolved children");
|
107 | 111 | }
|
108 |
| - int limit = (int) limitField().fold(FoldContext.small()); |
| 112 | + var typeResolution = isType( |
| 113 | + field(), |
| 114 | + dt -> dt != DataType.UNSIGNED_LONG, |
| 115 | + sourceText(), |
| 116 | + FIRST, |
| 117 | + "any type except unsigned_long" |
| 118 | + ).and(isNotNullAndFoldable(limitField(), sourceText(), SECOND)) |
| 119 | + .and(isType(limitField(), dt -> dt == DataType.INTEGER, sourceText(), SECOND, "integer")); |
| 120 | + if (typeResolution.unresolved()) { |
| 121 | + return typeResolution; |
| 122 | + } |
| 123 | + int limit = limitValue(); |
109 | 124 | if (limit <= 0) {
|
110 | 125 | return new TypeResolution(format(null, "Limit must be greater than 0 in [{}], found [{}]", sourceText(), limit));
|
111 | 126 | }
|
|
0 commit comments