-
Notifications
You must be signed in to change notification settings - Fork 10
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
fix: handle group_by identifier more generically #127
Conversation
This comment has been minimized.
This comment has been minimized.
Codecov Report
@@ Coverage Diff @@
## main #127 +/- ##
============================================
+ Coverage 78.88% 78.99% +0.10%
- Complexity 564 566 +2
============================================
Files 92 92
Lines 2770 2794 +24
Branches 268 271 +3
============================================
+ Hits 2185 2207 +22
- Misses 424 426 +2
Partials 161 161
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
.setFilter( | ||
RelationalExpression.of( | ||
IdentifierExpression.of("price"), LTE, ConstantExpression.of(10))) | ||
.addAggregation(IdentifierExpression.of("item")) |
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.
Add group by on price
as well, because it's a part of the selection?
List<SelectionSpec> finalSelectionSpecs = | ||
query.getSelections().stream() | ||
.filter(selectionSpec -> selectionSpec.getExpression().accept(this)) | ||
.filter( | ||
selectionSpec -> { |
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.
Could we keep the lambda definitions small by introducing private method to improve readability?
public Boolean visit(AggregateExpression expression) { | ||
return true; | ||
} | ||
private static class LocalSelectTypeAggregationExpressionSelector |
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.
If this is just returning the instance type, do need a separate visitor hierarchy? Could we just do using instance of?
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.
I think, this is a more readable pattern.
@Override | ||
public Boolean visit(FunctionExpression expression) { | ||
return false; | ||
private static class LocalSelectTypeIdentifierExpressionSelector |
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.
Same here
@Override | ||
public Boolean visit(IdentifierExpression expression) { | ||
return false; | ||
private static class LocalGroupByIdentifierExpressionSelector |
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.
Same
RelationalExpression.of( | ||
IdentifierExpression.of("price"), LTE, ConstantExpression.of(10))) | ||
.addAggregation(IdentifierExpression.of("item")) | ||
.build(); |
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.
Add price aggregation?
String sql = postgresQueryParser.parse(); | ||
|
||
assertEquals( | ||
"SELECT COUNT(DISTINCT document->>'quantity' ) AS \"qty_count\", " |
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 confuses to see where the price
selection is lost!
Then, I remembered the transformation logic. Anyway, that'll come up.
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.
Discussed offline.
The previous fix - #124 for the issue #123, was handling a very specific case.
As part of this PR,
identifier
match with selection clause identifiers.Testing:
Example of handling same in existing mongo impl:
Before transformation:
After transformation:
Mongo Query:
Response: