|
43 | 43 | import org.elasticsearch.xpack.esql.core.expression.Expression; |
44 | 44 | import org.elasticsearch.xpack.esql.core.expression.Expressions; |
45 | 45 | import org.elasticsearch.xpack.esql.core.expression.FieldAttribute; |
| 46 | +import org.elasticsearch.xpack.esql.core.expression.FoldContext; |
46 | 47 | import org.elasticsearch.xpack.esql.core.expression.Literal; |
47 | 48 | import org.elasticsearch.xpack.esql.core.expression.NamedExpression; |
48 | 49 | import org.elasticsearch.xpack.esql.core.expression.ReferenceAttribute; |
@@ -2053,6 +2054,24 @@ public void testToDateNanosPushDown() { |
2053 | 2054 | assertThat(expected.toString(), is(esQuery.query().toString())); |
2054 | 2055 | } |
2055 | 2056 |
|
| 2057 | + public void testKnnWithoutExplicitLimit() { |
| 2058 | + var query = """ |
| 2059 | + from test |
| 2060 | + | where knn(dense_vector, [0, 1, 2]) |
| 2061 | + """; |
| 2062 | + var analyzer = makeAnalyzer("mapping-all-types.json"); |
| 2063 | + var plan = plannerOptimizer.plan(query, IS_SV_STATS, analyzer); |
| 2064 | + var limitExec = as(plan, LimitExec.class); |
| 2065 | + assertThat(limitExec.limit().fold(FoldContext.small()), is(config.resultTruncationDefaultSize())); |
| 2066 | + var exchangeExec = as(limitExec.child(), ExchangeExec.class); |
| 2067 | + var projectExec = as(exchangeExec.child(), ProjectExec.class); |
| 2068 | + var fieldExtractExec = as(projectExec.child(), FieldExtractExec.class); |
| 2069 | + var queryExec = as(fieldExtractExec.child(), EsQueryExec.class); |
| 2070 | + assertThat(queryExec.limit().fold(FoldContext.small()), is(config.resultTruncationDefaultSize())); |
| 2071 | + var knnQuery = as(queryExec.query(), KnnVectorQueryBuilder.class); |
| 2072 | + assertThat(knnQuery.k(), is(config.resultTruncationDefaultSize())); |
| 2073 | + } |
| 2074 | + |
2056 | 2075 | private boolean isMultiTypeEsField(Expression e) { |
2057 | 2076 | return e instanceof FieldAttribute fa && fa.field() instanceof MultiTypeEsField; |
2058 | 2077 | } |
|
0 commit comments