Repository navigation
Restore SUM(narrow_int + literal) aggregation pushdown - #5827
Conversation
PR Reviewer Guide 🔍(Review updated until commit ed50d6b)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to ed50d6b Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 8f6335d
Suggestions up to commit f61cabd
Suggestions up to commit d9f751b
|
|
Persistent review updated to latest commit f61cabd |
Codecov Report❌ Patch coverage is
❌ Your project check has failed because the head coverage (63.80%) 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 #5827 +/- ##
============================================
+ Coverage 63.66% 63.80% +0.13%
- Complexity 9022 9070 +48
============================================
Files 959 962 +3
Lines 40836 40989 +153
Branches 4635 4660 +25
============================================
+ Hits 26000 26152 +152
+ Misses 13964 13960 -4
- Partials 872 877 +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:
|
PPL widens narrow-integer arithmetic operands (opensearch-project#5603), so sum(x + 1) on a SMALLINT field reaches PPLAggregateConvertRule as CHECKED_LONG_SUM(CAST($x):BIGINT + 1). The rule only matched a bare input ref, so the SUM(x) + k * COUNT(x) rewrite stopped firing and the aggregate fell back to a full scan with coordinator-side aggregation (ClickBench q30). Accept a lossless integer widening cast of an input ref as the field operand and drop the cast in the rewrite. This is type-safe for CHECKED_LONG_SUM, which always returns BIGINT, and lets the rewritten sums dedup with a plain sum(x). Casts are only unwrapped for CHECKED_LONG_SUM. Also assert the explain plan for ClickBench queries that are skipped for execution: q30 was always skipped because GCedMemoryUsage is never initialized in the test JVM, so q30.yaml was never compared. Resolves opensearch-project#5823 Signed-off-by: Kai Huang <[email protected]>
The existing sum-enhancement explain test uses a long field, which is not widened, so it never exercised the CAST path from opensearch-project#5603. Cover an integer field in both pushdown and no-pushdown modes. Signed-off-by: Kai Huang <[email protected]>
f61cabd to
8f6335d
Compare
|
Persistent review updated to latest commit 8f6335d |
Signed-off-by: Kai Huang <[email protected]>
|
Persistent review updated to latest commit ed50d6b |
Description
stats sum(<narrow-int field> + <literal>)lost its aggregation pushdown in 3.8. #5603 widens narrow-integer arithmetic operands, so the aggregate argument became+(CAST($x):BIGINT, k).PPLAggregateConvertRuleonly matched a bareINPUT_REF, so theSUM(x + k) → SUM(x) + k * COUNT(x)rewrite stopped firing. Queries then ran as a full_sourcescan with coordinator-sideEnumerableAggregate(ClickBench q30: 90 such sums, sub-second → timeout).Fix (
PPLAggregateConvertRule)CASTof one (TINYINT ≤ SMALLINT ≤ INTEGER ≤ BIGINT). Narrowing and non-integer casts are still rejected.CHECKED_LONG_SUMalways returns BIGINT, so a cast is only unwrapped when the agg isCHECKED_LONG_SUM. Dropping it also lets every rewritten_SUMdedup with the plainsum(x), so q30 collapses back to two metric aggregations.q30 plan, before → after
PROJECT->[ResolutionWidth]onlyAGGREGATION+LIMIT_sourcescan, nosize"size":0,sum+value_countEnumerableAggregatewith 90CHECKED_LONG_SUMsEnumerableCalconlyTest gaps fixed
PPLAggregateConvertRuleTestonly covered a BIGINT input ref, which is never widened. It now covers a SMALLINT field widened to BIGINT (including dedup with a plainsum(a)) and a narrowing cast that must not match.CalciteExplainIT's only sum-enhancement test (testExplainOnAggregationWithSumEnhancement) usesbalance(long), which Widen narrow integer operands in PPL +/-/* to prevent overflow #5603 doesn't widen, so it never saw the cast. AddedtestExplainOnAggregationWithSumEnhancementOnNarrowIntonage(integer), with pushdown and no-pushdown fixtures. It fails on main in both modes.CalcitePPLClickBenchITnever compared q30's plan.ignored()skips q30 whenGCedMemoryUsage.initialized()is false, and that static is never initialized in the test JVM, so q30 was always skipped, explain assertion included. That is how the regressedq30.yamlwent unnoticed. The IT now checks the plan for every query and skips only execution for ignored ones.q30.yamlis regenerated.Verified:
:core:test,:ppl:test,:opensearch:test,CalcitePPLClickBenchITandCalciteExplainITall pass. The ClickBench IT change fails against the oldq30.yaml.Related Issues
Resolves #5823
Regressed by #5603
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.