-
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 : group by on functional expressions in mongo #200
Conversation
"function": 3.0, | ||
"functionCount": 2 | ||
} | ||
] |
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.
Nit: Empty line at the end.
@@ -145,6 +150,20 @@ public static ReturnDocument getReturnDocument(final ReturnDocumentType returnDo | |||
String.format("Unhandled return document type: %s", returnDocumentType))); | |||
} | |||
|
|||
public static boolean isFunctionExpressionSelectionWithGroupBy( |
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.
Utils is only for very specific and common things. Can we move this method out of the utils?
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.
this is used at 2 places at MongoGroupTypeExpressionParser
and MongoSelectTypeExpressionParser
so we'll need to define it at some common place, right?
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 makes sense to put them in a common place, but doesn't feel like "Utils" is the right place. Either we could have a shared class (non-static) or have the definition in one place and access it in another.
final SelectionSpec selectionSpec, final List<String> groupByAliases) { | ||
return selectionSpec.getAlias() != null | ||
&& groupByAliases.contains(selectionSpec.getAlias()) | ||
&& selectionSpec.getExpression().getClass().equals(FunctionExpression.class); |
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.
Please avoid checking class instances like this. Refer classes like IdentifierChecker
, etc.
public static List<String> getGroupByAliases(final List<GroupTypeExpression> expressions) { | ||
return expressions.stream() | ||
.filter(expression -> expression.getClass().equals(IdentifierExpression.class)) | ||
.map(expression -> ((IdentifierExpression) expression).getName()) |
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 you avoid explicit instance of/class equality checks and casting by leveraging the visitor pattern?
functionExpressionSelectionWithGroupBys.stream() | ||
.map(spec -> MongoGroupTypeExpressionParser.parse(parser, spec)) | ||
.reduce( | ||
new LinkedHashMap<>(), |
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.
Any reason for a linked hashmap? Is the order important here?
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.
no reason, i just copy pasted the reduce used below
don't think the order is important
@@ -99,4 +128,15 @@ private Map<String, Object> parse(final GroupTypeExpression expression) { | |||
MongoGroupTypeExpressionParser parser = new MongoGroupTypeExpressionParser(); | |||
return expression.accept(parser); | |||
} | |||
|
|||
private static List<SelectionSpec> getFunctionExpressionSelectionWithGroupBys( |
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.
Where is this getting used?
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.
Line 56 in 93fdf17
getFunctionExpressionSelectionWithGroupBys(selectionSpecs, expressions); |
|
||
@Override | ||
public String visit(FunctionExpression expression) { | ||
return null; |
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.
Better to throw exception instead of null.
Or, alternatively return optional of string to avoid NullPointerExceptions.
.filter(Optional::isPresent) | ||
.map(Optional::get) |
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.
Nit: Can also be simplified to.
.filter(Optional::isPresent) | |
.map(Optional::get) | |
.flatMap(Optional::stream) |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #200 +/- ##
============================================
+ Coverage 79.45% 79.65% +0.20%
- Complexity 1003 1013 +10
============================================
Files 193 194 +1
Lines 4769 4807 +38
Branches 399 402 +3
============================================
+ Hits 3789 3829 +40
+ Misses 698 696 -2
Partials 282 282
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Description
Bug fix for grouping on functional expressions
Testing
Added a test for the same scenario
Checklist:
Documentation
Make sure that you have documented corresponding changes in this repository or hypertrace docs repo if required.