Fallback to sub-aggregation if composite aggregation doesn't support#4413
Fallback to sub-aggregation if composite aggregation doesn't support#4413yuancu merged 5 commits intoopensearch-project:mainfrom
Conversation
Signed-off-by: Heng Qian <qianheng@amazon.com>
# Conflicts: # integ-test/src/test/resources/expectedOutput/calcite/explain_agg_sort_on_metrics2.json # integ-test/src/test/resources/expectedOutput/calcite/explain_limit_agg_pushdown_bucket_nullable1.json # integ-test/src/test/resources/expectedOutput/calcite/explain_limit_agg_pushdown_bucket_nullable2.json
Signed-off-by: Heng Qian <qianheng@amazon.com>
| final LogicalAggregate aggregate = call.rel(0); | ||
| final LogicalFilter filter = call.rel(1); | ||
| final LogicalProject project = call.rel(2); | ||
| final CalciteLogicalIndexScan scan = call.rel(3); |
There was a problem hiding this comment.
LogicalAggregate
LogicalProject
LogicalFilter(condition=[IS NOT NULL($7)])
Shouldn't be following?
final LogicalAggregate aggregate = call.rel(0);
final LogicalProject project = call.rel(1);
final LogicalFilter filter = call.rel(2);
final CalciteLogicalIndexScan scan = call.rel(3);
There was a problem hiding this comment.
The original plan is
LogicalAggregate
LogicalProject
LogicalFilter(condition=[IS NOT NULL($7)])
LogicalProject
LogicalIndexScan
ProjectFilterTransposeRule and ProjectMergeRule will produce agg-filter-project-scan pattern.
Maybe FilterProjectTransposeRule + ProjectMergeRule may produce agg-project-filter-scan
There was a problem hiding this comment.
The pattern agg-filter-project-scan will make it easier to detect whether the filter is derived from the agg. The other pattern could work as well while we need to do additional transformation since the ref of field has passed through a project operator.
| Config BUCKET_NON_NULL_AGG = | ||
| ImmutableOpenSearchAggregateIndexScanRule.Config.builder() | ||
| .build() | ||
| .withDescription("Agg-Filter-Project-TableScan") |
There was a problem hiding this comment.
why not "Agg-Project-Filter-TableScan"? I think Agg-Project should be treated as a single unit
There was a problem hiding this comment.
But filter(isnotnull) here is also derived from the agg.
| return Pair.of( | ||
| ImmutableList.copyOf(newMetricBuilder.getAggregatorFactories()), | ||
| new CountAsTotalHitsParser(countAggNameList)); | ||
| List.of(), new CountAsTotalHitsParser(countAggNameAndBuilderPair.getLeft())); |
There was a problem hiding this comment.
can you create a named var for countAggNameAndBuilderPair.getLeft()?
| @@ -289,7 +275,7 @@ && isAutoDateSpan(project.getProjects().get(groupList.getFirst()))) { | |||
| * @param countAllOnly remove count() only, or count(FIELD) will be removed. | |||
| * @return a pair of removed ValueCountAggregationBuilder and updated metric builder | |||
| } | ||
| } | ||
|
|
||
| public static class CompositeUnSupportedException extends RuntimeException { |
There was a problem hiding this comment.
can you move it to package org.opensearch.sql.exception?
There was a problem hiding this comment.
This exception only happens here and will be caught internally. It doesn't need to be accessed outside of this file
Signed-off-by: Heng Qian <qianheng@amazon.com>
Signed-off-by: Heng Qian <qianheng@amazon.com>
|
The backport to To backport manually, run these commands in your terminal: # Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/sql/backport-2.19-dev 2.19-dev
# Navigate to the new working tree
pushd ../.worktrees/sql/backport-2.19-dev
# Create a new branch
git switch --create backport/backport-4413-to-2.19-dev
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 abd5bd3337af63892ff8ee762ad3c5902fa87b2a
# Push it to GitHub
git push --set-upstream origin backport/backport-4413-to-2.19-dev
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/sql/backport-2.19-devThen, create a pull request where the |
…pensearch-project#4413) * Fallback to sub-aggregation if composite aggregation doesn't support Signed-off-by: Heng Qian <qianheng@amazon.com> * merging main Signed-off-by: Heng Qian <qianheng@amazon.com> * Address comments Signed-off-by: Heng Qian <qianheng@amazon.com> * Address comments Signed-off-by: Heng Qian <qianheng@amazon.com> --------- Signed-off-by: Heng Qian <qianheng@amazon.com> (cherry picked from commit abd5bd3) Signed-off-by: Heng Qian <qianheng@amazon.com>
…on doesn't support #4413 (#4498) * Fallback to sub-aggregation if composite aggregation doesn't support (#4413) * Fallback to sub-aggregation if composite aggregation doesn't support Signed-off-by: Heng Qian <qianheng@amazon.com> * merging main Signed-off-by: Heng Qian <qianheng@amazon.com> * Address comments Signed-off-by: Heng Qian <qianheng@amazon.com> * Address comments Signed-off-by: Heng Qian <qianheng@amazon.com> --------- Signed-off-by: Heng Qian <qianheng@amazon.com> (cherry picked from commit abd5bd3) Signed-off-by: Heng Qian <qianheng@amazon.com> * fix compiling Signed-off-by: Heng Qian <qianheng@amazon.com> --------- Signed-off-by: Heng Qian <qianheng@amazon.com>
…pensearch-project#4413) * Fallback to sub-aggregation if composite aggregation doesn't support Signed-off-by: Heng Qian <qianheng@amazon.com> * merging main Signed-off-by: Heng Qian <qianheng@amazon.com> * Address comments Signed-off-by: Heng Qian <qianheng@amazon.com> * Address comments Signed-off-by: Heng Qian <qianheng@amazon.com> --------- Signed-off-by: Heng Qian <qianheng@amazon.com> Signed-off-by: Asif Bashar <asif.bashar@gmail.com>
Description
Fallback to sub-aggregation if composite aggregation doesn't support(e.g. auto_span).
As sub-aggregation includes term agg which doesn't include null bucket, so we only fallback to push the aggregation when bucket_nullable=false. Otherwise, the aggregation will fail to push down and executes as a Calcite's Enumerable aggregate operator.
This PR also refact and scale the optimization #4337 for bucket aggregation including single bucket and nested bucket(i.e. sub-agg).
Related Issues
Resolves #4338
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.