Skip to content

Commit b8e786d

Browse files
committed
fix non-stats query
1 parent 5f43ad7 commit b8e786d

File tree

1 file changed

+9
-5
lines changed
  • x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/approximate

1 file changed

+9
-5
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/approximate/Approximate.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import org.apache.logging.log4j.LogManager;
1111
import org.apache.logging.log4j.Logger;
12+
import org.elasticsearch.ExceptionsHelper;
1213
import org.elasticsearch.action.ActionListener;
1314
import org.elasticsearch.common.util.set.Sets;
1415
import org.elasticsearch.compute.data.LongBlock;
@@ -382,11 +383,9 @@ public void onResponse(Result result) {
382383
boolean esStatsQueryExecuted = result.executionInfo() != null
383384
&& result.executionInfo().clusterInfo.values()
384385
.stream()
385-
.noneMatch(
386-
cluster -> cluster.getFailures().stream().anyMatch(e -> e.getCause() instanceof UnsupportedOperationException)
387-
);
386+
.noneMatch(cluster -> cluster.getFailures().stream().anyMatch(Approximate::isCausedByUnsupported));
388387
if (esStatsQueryExecuted) {
389-
logger.debug("not approximating stats query");
388+
logger.debug("stats query succeeded; returning exact result");
390389
listener.onResponse(result);
391390
} else {
392391
result.pages().forEach(Page::close);
@@ -396,15 +395,20 @@ public void onResponse(Result result) {
396395

397396
@Override
398397
public void onFailure(Exception e) {
399-
if (e instanceof UnsupportedOperationException) {
398+
if (isCausedByUnsupported(e)) {
400399
runner.run(toPhysicalPlan.apply(sourceCountPlan()), configuration, foldContext, sourceCountListener(listener));
401400
} else {
401+
logger.debug("stats query failed; returning error", e);
402402
listener.onFailure(e);
403403
}
404404
}
405405
};
406406
}
407407

408+
private static boolean isCausedByUnsupported(Exception ex) {
409+
return ExceptionsHelper.unwrapCausesAndSuppressed(ex, e -> e instanceof UnsupportedOperationException).isPresent();
410+
}
411+
408412
/**
409413
* Plan that counts the number of rows in the source index.
410414
* This is the ES|QL query:

0 commit comments

Comments
 (0)