-
Notifications
You must be signed in to change notification settings - Fork 11
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
Add COUNT DISTINCT Rewriter #20
base: main
Are you sure you want to change the base?
Conversation
private boolean isUsingCountDistinctComparisonToCheckUniqueness(Comparison node) | ||
{ | ||
Optional<AstNode> aggregationFunction = Optional.ofNullable(node.GetFirstChildOfKind(JJTAGGREGATIONFUNCTION)); | ||
return aggregationFunction.isPresent() && aggregationHasCountDistinct((AggregationFunction) aggregationFunction.get()) && secondArgIsLiteralOne(node); |
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.
We need to enhance the AST attributes to remember the operator. It's a TODO(viswanadha) :)
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.
Oops. I forgot I had the correct definition in the doc. So deleting these comments lol
private boolean aggregationHasCountDistinct(AggregationFunction node) | ||
{ | ||
Optional<AstNode> setQuantifier = Optional.ofNullable(node.GetFirstChildOfKind(JJTSETQUANTIFIER)); | ||
return setQuantifier.isPresent() && node.beginToken.image.equalsIgnoreCase("COUNT") && unparse(setQuantifier.get()).equalsIgnoreCase("DISTINCT"); |
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.
setQuantifier is a leaf node so you can just get the image and check. We will redo this to make it an in attribute so we can just check the token.
private boolean isUsingCountDistinctComparisonToCheckUniqueness(Comparison node) | ||
{ | ||
Optional<AstNode> aggregationFunction = Optional.ofNullable(node.GetFirstChildOfKind(JJTAGGREGATIONFUNCTION)); | ||
return aggregationFunction.isPresent() && aggregationHasCountDistinct((AggregationFunction) aggregationFunction.get()) && secondArgIsLiteralOne(node); |
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.
We need to enhance the AST attributes to remember the operator. It's a TODO(viswanadha) :)
Added a rewriter for the following anti-pattern:
-> Uses "COUNT(DISTINCT x) > 1" to check for duplicates