Repository navigation
Conversation
Push ARRAY_AGG down as a top_hits sub-aggregation of the composite aggregation, only when index.max_inner_result_window is at least plugins.query.buckets for every queried index; otherwise it stays in memory, so indices with the default window behave as before. The pushed-down values match the in-memory ARRAY_AGG: the field is read from _source and parsed with its own type, duplicates are kept, a group without values is NULL, and a sort pushed down before the aggregate is applied to the top_hits. A sort on an expression, IGNORE NULLS, and object or geo_point targets are not pushed down. A group with more values than the top_hits size fails with RESOURCE_LIMIT_EXCEEDED rather than return a truncated array. Signed-off-by: Lantao Jin <ltjin@amazon.com>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
Codecov Report❌ Patch coverage is ❌ Your project check has failed because the head coverage (63.89%) is below the target coverage (99.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #5892 +/- ##
============================================
+ Coverage 63.87% 63.89% +0.01%
- Complexity 9091 9119 +28
============================================
Files 962 964 +2
Lines 41033 41173 +140
Branches 4668 4696 +28
============================================
+ Hits 26211 26308 +97
- Misses 13944 13982 +38
- Partials 878 883 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The replacement of closed #5072
Description
This PR pushes down the Calcite
ARRAY_AGGaggregation to OpenSearch as atop_hitssub-aggregation of the composite aggregation. The PPLmvcombinecommand produces this aggregation asARRAY_AGG(x) FILTER (x IS NOT NULL), grouped by every other field. It redoes the closed #5072 on the latestmain. Before this changemvcombinealways ran in memory: the scan read every matching document through a PIT, even when the output was limited.#5072 always pushed down, with a
top_hitssize ofplugins.query.buckets(10000 by default). OpenSearch rejects atop_hitslarger than the index settingindex.max_inner_result_window(default 100). Somvcombinefailed on every index that kept the default, and every IT that ranmvcombineneeded that setting raised. That is why #5072's ITs never all passed. The setting also guards heap: each shard allocates a hit queue ofsizeslots for every bucket of a composite page. This PR changes the approach:ARRAY_AGGis pushed down only whenindex.max_inner_result_windowis at leastplugins.query.bucketsfor every queried index. Otherwise it stays in memory, so the default behaviour is unchanged. The setting is read lazily, and only for aggregates that containARRAY_AGG, by the node client (local and cross-cluster indices) and the REST client. It is cached perOpenSearchIndex._source, filtered to that one field, and parsed with the field's own type, as the scan does. The fields API would format values differently, for example dates as2018-06-23T00:00:00.000Zinstead of2018-06-23 00:00:00. Following the review on Support pushdown array/collect aggregation #5072, the full_sourceis not fetched.null, as in memory.mvcombinekeeps the order of its input. A sort that was pushed down before the aggregate is now carried into thetop_hitssort; the sort digest keeps its sort builders. A sort on an expression prevents the pushdown.top_hitssize, the query fails withRESOURCE_LIMIT_EXCEEDEDand names the settings to raise.OpenSearchExecutionEnginenow surfaces anErrorReportraised while reading results, instead of wrapping it into an opaque error.ARRAY_AGG ... IGNORE NULLS, and object orgeo_pointtargets.Known limitation: if the target holds an array in a document, the pushed-down
mvcombinekeeps the array's first value. In memory, the array is stringified, for example"[x, y]".mvcombinerequires a single-valued target. The docs state both rules.Testing:
AggregateAnalyzerTest,OpenSearchAggregationResponseParserTest, both client tests,OpenSearchIndexTestandOpenSearchExecutionEngineTest.CalciteMvCombineCommandIT: compares every result with pushdown on and off, row for row. It covers duplicates, empty strings, a group without values, a preceding sort, and ip and date targets. It also covers the overflow error, and the fallback when the window is too small.CalciteExplainIT: the pushed plan, the carried sort, and the fallback for an expression sort. The existingmvcombineexplain on a default index is unchanged../gradlew build(unit tests and checks);integTest(7483 tests, 269 skipped);integTestWithSecurity(138);yamlRestTest(256);tracingIntegTest(6);doctest(86).Related Issues
Resolves #5070
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.