Skip to content

Commit f2ca372

Browse files
idegtiarenkoelasticsearchmachine
andauthored
[8.19] Fix assertion error when executing invalid row query with filter (elastic#135761) (elastic#135842)
* Fix assertion error when executing invalid row query with filter (elastic#135761) (cherry picked from commit 2e6d95a) * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]>
1 parent 28e7ef5 commit f2ca372

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/EsqlActionIT.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.elasticsearch.index.mapper.DateFieldMapper;
4040
import org.elasticsearch.index.mapper.extras.MapperExtrasPlugin;
4141
import org.elasticsearch.index.query.BoolQueryBuilder;
42+
import org.elasticsearch.index.query.MatchAllQueryBuilder;
4243
import org.elasticsearch.index.query.QueryBuilder;
4344
import org.elasticsearch.index.query.RangeQueryBuilder;
4445
import org.elasticsearch.index.shard.IndexShard;
@@ -151,13 +152,25 @@ public void testRow() {
151152
public void testRowWithFilter() {
152153
long value = randomLongBetween(0, Long.MAX_VALUE);
153154
EsqlQueryRequest request = syncEsqlQueryRequest();
154-
request.query("row " + value);
155-
request.filter(new BoolQueryBuilder().boost(1.0f));
155+
request.query("ROW " + value);
156+
request.filter(randomQueryFilter());
156157
try (EsqlQueryResponse response = run(request)) {
157158
assertEquals(List.of(List.of(value)), getValuesList(response));
158159
}
159160
}
160161

162+
public void testInvalidRowWithFilter() {
163+
long value = randomLongBetween(0, Long.MAX_VALUE);
164+
EsqlQueryRequest request = syncEsqlQueryRequest();
165+
request.query("ROW " + value + " | EVAL x==NULL");
166+
request.filter(randomQueryFilter());
167+
expectThrows(VerificationException.class, containsString("Unknown column [x]"), () -> run(request));
168+
}
169+
170+
private static QueryBuilder randomQueryFilter() {
171+
return randomFrom(new MatchAllQueryBuilder(), new BoolQueryBuilder().boost(1.0f));
172+
}
173+
161174
public void testFromStatsGroupingAvgWithSort() {
162175
testFromStatsGroupingAvgImpl("from test | stats avg(count) by data | sort data | limit 2", "data", "avg(count)");
163176
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlCCSUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ static void updateExecutionInfoWithClustersWithNoMatchingIndices(
201201
IndexResolution indexResolution,
202202
boolean usedFilter
203203
) {
204+
if (executionInfo.clusterInfo.isEmpty()) {
205+
return;
206+
}
204207
// Get the clusters which are still running, and we will check whether they have any matching indices.
205208
// NOTE: we assume that updateExecutionInfoWithUnavailableClusters() was already run and took care of unavailable clusters.
206209
final Set<String> clustersWithNoMatchingIndices = executionInfo.getClusterStates(Cluster.Status.RUNNING)

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlSession.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,7 @@ private static void analyzeAndMaybeRetry(
568568
if (result.indices.isValid() || requestFilter != null) {
569569
// We won't run this check with no filter and no valid indices since this may lead to false positive - missing index report
570570
// when the resolution result is not valid for a different reason.
571-
if (executionInfo.clusterInfo.isEmpty() == false) {
572-
EsqlCCSUtils.updateExecutionInfoWithClustersWithNoMatchingIndices(executionInfo, result.indices, requestFilter != null);
573-
}
571+
EsqlCCSUtils.updateExecutionInfoWithClustersWithNoMatchingIndices(executionInfo, result.indices, requestFilter != null);
574572
}
575573
plan = analyzeAction.apply(result);
576574
} catch (Exception e) {

0 commit comments

Comments
 (0)