…and Visualization tabs (#13273)
* feat(explore): stream a stats query without a by clause on the Statistics and Visualization tabs
The SQL plugin can report a running result for a pushed-down aggregation
without grouping (opensearch-project/sql#5978): while the search runs,
each poll carries the aggregation of the shards that have answered so far,
and the next one replaces it. The Statistics and Visualization tabs always
ran their query on the standard path, so they showed nothing until it
finished.
When streaming is on and the tab query ends in a `stats` without `by`,
the tab query now runs as an async job like the logs table, with the same
time filter and no default sort, and falls back to the standard path when
the engine cannot stream. Every other aggregation stays on the standard
path: its buckets arrive whole either way, and that path cancels the query
on the cluster when stopped, which releasing an async job does not yet do
(opensearch-project/sql#6004).
While a streamed tab query has no row yet, the tab keeps its loading state
instead of rendering "No items found", and the query panel's progress bar
and screen reader announcement follow the active tab's streamed query, so
they describe the aggregation the tab shows rather than the logs query.
Signed-off-by: Justin Kim <jungkm@amazon.com>
* fix(explore): mark a running aggregation and clear it when stopped
A running aggregation's values are recomputed on every poll and can be
far from the final ones: in a test run the sum read 938,641,603 at 83%
against a final 2,252,427,317. Unlike streamed log rows, they are not
part of the answer.
- The Statistics and Visualization tabs show a callout while their query
streams a running result.
- A stopped or failed run clears the running values instead of leaving
them on screen and in a CSV export, and a run that cannot finish
re-runs on the standard path instead of ending "Incomplete".
- A lone `stats count()` stays on the standard path: the engine answers
it as a hit count, so streaming it shows nothing sooner and gives up
cancelling it on Stop.
Signed-off-by: Justin Kim <jungkm@amazon.com>
* fix(explore): show the final aggregation in an expanded row and clear the chart when stopped
The Statistics tab kept the expanded row's JSON from the row it was opened
on, so it still showed the running values after the final row arrived. It
now remembers which rows are expanded and renders the JSON from the current
row.
After Stop, the Visualization tab kept drawing the last running point
because the visualization builder caches its data. The container now draws
nothing once the results are cleared.
Signed-off-by: Justin Kim <jungkm@amazon.com>
* fix(explore): show the running-result callout only for a streamed aggregation
For a query without an aggregation, the Statistics and Visualization tabs
read the same results as the logs table. While those rows streamed, the tabs
showed the "Running result" callout above rows that are final.
A streamed aggregation now marks its streaming status as a running result,
and the callout shows only for that.
Signed-off-by: Justin Kim <jungkm@amazon.com>
---------
Signed-off-by: Justin Kim <jungkm@amazon.com>
Description
An async PPL query whose result is a pushed-down aggregation now returns a running result: while the search runs, each
RUNNINGresponse (submit andGET /_plugins/_async_query/{id}) holds the aggregation of the shards that have answered so far, and a later response replaces it. The final result still comes from the normal search response, unchanged.{"status": "RUNNING", "progress": {"fraction_done": 0.4}, "schema": [{"name": "m", "type": "bigint"}, {"name": "s", "type": "bigint"}], "datarows": [[39999, 581482687]], "total": 1, "size": 1}Why a setting is needed
OpenSearch merges shard results in batches of
min(batched_reduce_size, shard count), andbatched_reduce_sizedefaults to 512. Below 512 shards the batch is every shard, so the only merge happens when the last shard answers, right before the response. A running result therefore needs a smallerbatched_reduce_sizeon the request.plugins.query.async.batched_reduce_size(dynamic, default5; below2turns this off) sets it, only on async queries that qualify. Sync queries and other async queries are untouched. A smaller batch means more merges on the coordinator, but each merge also frees the shard results it consumed.How it works
flowchart LR subgraph search["Search (coordinator)"] S["Shard results"] -->|"every N results"| M["Partial merge"] M -->|"onPartialReduce / onFinalReduce"| L["ShardListener"] end L -->|"if a reader asked: final reduce,<br/>same parser, same row conversion"| PA["PartialAggregation<br/>(latest built rows)"] C["Client"] -->|"submit / GET while RUNNING"| PR["PartialRows.snapshot()"] PR -->|"no rows yet: interim"| PA PA -->|"latest rows, no work on read"| CCalciteEnumerableIndexScanwith a pushed-down aggregation that is not composite (statswithoutby, and bucket aggregations that come back in one response).scanAsRootregisters aPartialAggregationonly in that case, so a step computed by Calcite above the aggregation means no running result.timewrapis excluded.SourceProgress.ShardListener, already on the search task since [Feature][PPL] Report progress for asynchronous Calcite queries #5910, now also handlesonPartialReduce/onFinalReduce. In that callback,PartialAggregationfinishes the merge with a final reduce (a partial merge skips steps such as trimmingtermsbuckets to size) and converts it. The conversion goes throughOpenSearchQueryRequest.reducedResponse(the same parser and value factory as the final response), the enumerator's cell conversion, andResultRows(the same Calcite-to-ExprValueconversion asbuildResultSet).search.max_bucketsis skipped.PARTIAL_RESULTwarning the final response does ("N of M shards did not return data"), so a running aggregation is never shown as complete.snapshot()returns the latest built rows and asks for the next build. It never blocks, whichQueryRunner.currentResult()requires; it runs on the wait-timeout timer thread and on GET handlers.PartialRows: gains an interim view, shown only until the first final row arrives. It is read under the same lock as the rows, so a response never shows interim rows after final ones.discard()(failure or fallback) drops it too.ResultRows:processValueandbuildColumnsmoved out ofOpenSearchExecutionEngineso that both paths share them.buildResultSetbehavior is unchanged.Not covered
stats count()alone is pushed down as a hit count with no aggregation, and OpenSearch does not merge early without aggregations or hits, so it has no running result. The docs say so.eval x = n * 2 | stats sum(x)becomessum(n) * 2in anEnumerableCalc.stats ... bykeeps the page-by-page rows from [Feature][PPL] Publish partial rows for asynchronous Calcite queries #5920.ccs_minimize_roundtripsmerge remotely, so they produce no early merge.Open questions for review
5: I believe Elasticsearch's async search uses the same default for the same reason. Should it stay on by default?search.max_bucketsbut is not charged to the request circuit breaker.ScriptServicein that reduce: PPL pushes down no pipeline or scripted-metric aggregations, which are the only ones whose reduce needs scripts. If a reduce fails, the poll returns no rows and the query is unaffected.Tests
AsyncPPLPartialAggregationIT(new): a 40-shard index returns a running result that matches the final schema, with a sum at most the final one; the final rows equal sync; with the setting at0, no rows until doneAsyncPPLPartialRowsIT,AsyncPPLProgressIT,AsyncPPLQueryLifecycleIT,AsyncPPLRetainedJobLimitITPartialAggregationTest(new): builds a merge with the root row type; builds only after a reader asked, and a read does no work; finishes a partial merge (3termsbuckets trimmed to 2) but uses a final one as is; skips a merge over the bucket limit; a failure or empty result gives no rowsSourceProgressTest: sets the batch size and keeps merges only for a single aggregation search; plain, PIT and composite searches keep the defaultPartialRowsTest: interim until the first row, kept acrossopen, dropped bydiscardOpenSearchQueryRequestReducedResponseTest(new): a merge gives the same rows as the response:opensearch:test,:core:test,:common:test, plugin tests,spotlessCheckRemoving
setBatchedReduceSizemakesAsyncPPLPartialAggregationITfail. The IT uses a pushed-down script filter and disables the request cache on its index, so that each run is slow enough to poll mid-run.Related Issues
Resolves #5799
Part of #5765
Check List
--signoffor-s.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.