-
Notifications
You must be signed in to change notification settings - Fork 1
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(pat-5034): include order-by expressions when computing the group-by clause #208
fix(pat-5034): include order-by expressions when computing the group-by clause #208
Conversation
Your org has enabled the Graphite merge queue for merging into mainYou must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link. You can enable merging using labels in your Graphite merge queue settings. |
Current dependencies on/for this PR:
This stack of pull requests is managed by Graphite. |
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.
🚢 once my q is resolved
...(selection ?? []), | ||
...(orderBy ?? []) | ||
.map((x: Ordering) => x[0]) | ||
.filter((x) => !selectionMap.has(x)), |
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.
Can selectionMap.has(x)
ever return true
? Given how value equality works in Sets, which is pretty much like ===
, it's not clear to me that the FieldExpr
s in selection
could ever ===
the FieldExprs
in the array that the filter
is called on here.
Could you add a test that has equivalent, non-aggregateFieldExpr
s in the select and orderby, and see if they get deduped properly in the GroupbyList?
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.
In fact, the test case with avgPrice
as the first order-by expression (see my comment below), results in a true value returned by selectionMap.has
, and the group-by is correctly de-duped. Is there any reason that you think a non-aggregate field in the order-by that matches a selection expression will behave differently?
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.
Ajith's idea: Two derived fields would be unlikely to match.
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.
Good callout here @spencerwilson ! The derived field test did reveal the bug. Fixed it by using the field name in the selectionSet
.
const query = table | ||
.select('id', 'name', price.avg().as('avgPrice')) | ||
.filter(name.like('%bah%').and(createdOn.before(new Date('2023-01-01')))) | ||
.orderBy(['avgPrice', 'DESC'], [createdOn, 'ASC']) // Note that createdOn is not in the seletion. |
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.
@spencerwilson , note the first orderBy
expression. It will be mapped to the selection expression aliased to avgPrice
. The group-by has no dupe for this expression.
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.
In any case, I'll include a non-agg that matches a selection in the orderBy.
… duped in grooup-by
const grouping = expandedSelection.filter( | ||
(fieldExpr) => !(fieldExpr instanceof AggregateFieldExpr) | ||
); | ||
if (grouping) { |
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.
FYI grouping
will always be truthy (though it may have grouping.length === 0
)
Merge activity
|
Merge activity
|
selection set when computing the group-by clause.
Test plan