-
Notifications
You must be signed in to change notification settings - Fork 5.5k
feat: Add RemoveInsensitiveAggregateDistinct rule #26493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: Add RemoveInsensitiveAggregateDistinct rule #26493
Conversation
Reviewer's GuideIntroduce a new optimizer rule that detects distinct aggregations on functions insensitive to duplicates and rewrites them as non-distinct, integrate it into the planner’s optimization phases, and validate its behavior with comprehensive tests. Sequence diagram for optimizer rule application in planning phasessequenceDiagram
participant "PlanOptimizers"
participant "RemoveInsensitiveAggregateDistinct"
participant "AggregationNode"
"PlanOptimizers"->>"RemoveInsensitiveAggregateDistinct": apply rule during optimization
"RemoveInsensitiveAggregateDistinct"->>"AggregationNode": inspect aggregations
"RemoveInsensitiveAggregateDistinct"->>"AggregationNode": rewrite distinct-insensitive aggregations as non-distinct
"RemoveInsensitiveAggregateDistinct"-->>"PlanOptimizers": return updated AggregationNode
Class diagram for RemoveInsensitiveAggregateDistinct ruleclassDiagram
class RemoveInsensitiveAggregateDistinct {
-FunctionAndTypeManager functionAndTypeManager
+RemoveInsensitiveAggregateDistinct(FunctionAndTypeManager)
+Pattern<AggregationNode> getPattern()
+Result apply(AggregationNode, Captures, Context)
-boolean hasInsensitiveDistinct(AggregationNode)
-boolean isDistinctInsensitiveAggregation(Aggregation)
}
class Rule {
}
RemoveInsensitiveAggregateDistinct --|> Rule
Class diagram for AggregationNode and Aggregation modificationsclassDiagram
class AggregationNode {
+Map<VariableReferenceExpression, Aggregation> getAggregations()
+AggregationNode(...)
}
class Aggregation {
+boolean isDistinct()
+Aggregation(...)
+FunctionHandle getFunctionHandle()
+List<Expression> getArguments()
+Expression getCall()
+Expression getFilter()
+List<SortItem> getOrderBy()
+boolean getMask()
}
AggregationNode "1" o-- "*" Aggregation
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
| public class RemoveInsensitiveAggregateDistinct | ||
| implements Rule<AggregationNode> | ||
| { | ||
| private static final Set<QualifiedObjectName> DISTINCT_INSENSITIVE_AGGREGATION_NAMES = ImmutableSet.<QualifiedObjectName>builder() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to think about how we can put this into the function metadata itself, rather than hardcoding this list.
5cdde81 to
6a04a8b
Compare
6a04a8b to
e830456
Compare
Description
Add an optimizer rule to remove distinct from aggregates that are insensitive to duplicates.
Fixes #26075.
Motivation and Context
Impact
Test Plan
Contributor checklist
Release Notes
Please follow release notes guidelines and fill in the release notes below.