Skip to content

Commit 2e6d95a

Browse files
authored
Fix assertion error when executing invalid row query with filter (#135761)
1 parent a4d7b9f commit 2e6d95a

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

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

Lines changed: 15 additions & 1 deletion
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;
@@ -150,11 +151,24 @@ public void testRow() {
150151

151152
public void testRowWithFilter() {
152153
long value = randomLongBetween(0, Long.MAX_VALUE);
153-
try (EsqlQueryResponse response = run(syncEsqlQueryRequest().query("row " + value).filter(new BoolQueryBuilder().boost(1.0f)))) {
154+
try (EsqlQueryResponse response = run(syncEsqlQueryRequest().query("ROW " + value).filter(randomQueryFilter()))) {
154155
assertEquals(List.of(List.of(value)), getValuesList(response));
155156
}
156157
}
157158

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

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
@@ -213,6 +213,9 @@ static void updateExecutionInfoWithClustersWithNoMatchingIndices(
213213
IndexResolution indexResolution,
214214
boolean usedFilter
215215
) {
216+
if (executionInfo.clusterInfo.isEmpty()) {
217+
return;
218+
}
216219
// Get the clusters which are still running, and we will check whether they have any matching indices.
217220
// NOTE: we assume that updateExecutionInfoWithUnavailableClusters() was already run and took care of unavailable clusters.
218221
final Set<String> clustersWithNoMatchingIndices = executionInfo.getRunningClusterAliases().collect(toSet());

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
@@ -742,9 +742,7 @@ private void analyzeWithRetry(
742742
if (result.indices.isValid() || requestFilter != null) {
743743
// We won't run this check with no filter and no valid indices since this may lead to false positive - missing index report
744744
// when the resolution result is not valid for a different reason.
745-
if (executionInfo.clusterInfo.isEmpty() == false) {
746-
EsqlCCSUtils.updateExecutionInfoWithClustersWithNoMatchingIndices(executionInfo, result.indices, requestFilter != null);
747-
}
745+
EsqlCCSUtils.updateExecutionInfoWithClustersWithNoMatchingIndices(executionInfo, result.indices, requestFilter != null);
748746
}
749747
LogicalPlan plan = analyzedPlan(parsed, result, executionInfo);
750748
LOGGER.debug("Analyzed plan ({}):\n{}", description, plan);

0 commit comments

Comments
 (0)