Skip to content
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 support for ordering on $select clauses in aggregations #393

Merged
merged 32 commits into from
Jun 18, 2024

Conversation

bryantpark04
Copy link
Member

Opening draft PR while I start writing tests

@bryantpark04 bryantpark04 self-assigned this Jun 13, 2024
@bryantpark04 bryantpark04 linked an issue Jun 13, 2024 that may be closed by this pull request
import type { GroupByClause } from "../query/aggregations/GroupByClause.js";

export type AggregateOptsThatErrorsAndDisallowsOrderingWithMultipleGroupBy<
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried a few different approaches for enforcing the "can't order on $select if there are multiple $groupBy clauses" restriction in the type system, and this method of adding another wrapped type layer around the AggregateOptsThatErrors type just to check this restriction was the easiest way to do it.

@ericanderson was this an okay approach?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to check out the repo to play with the types/intellisense but this seems like a reasonable solution.

The issue the comment was describing was fixed in f1ca1e1.
@bryantpark04 bryantpark04 marked this pull request as ready for review June 14, 2024 20:22
return [
{
type: metric as StringAggregateOption | NumericAggregateOption,
name: `${property}.${metric}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth checking, could probably just reuse k/propAndMetric here. The existing name was just an arbitrary choice by me that I knew we could split on later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the property.metric string is what gets sent to the wire as part of the request body, so the reformatting from property:metric to property.metric is necessary

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is whats in the request body, but the backend doesn't care what this value is. It will simply return a result that matches that value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can leave as is for now

import type { GroupByClause } from "../query/aggregations/GroupByClause.js";

export type AggregateOptsThatErrorsAndDisallowsOrderingWithMultipleGroupBy<
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to check out the repo to play with the types/intellisense but this seems like a reasonable solution.

Copy link
Member

@ericanderson ericanderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have my blessing if you have Saurav's blessing

Copy link
Contributor

@ssanjay1 ssanjay1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, couple of unblocking comments

@bryantpark04
Copy link
Member Author

bryantpark04 commented Jun 18, 2024

Approved, couple of unblocking comments

What kind of cruel joke is this

image

@bryantpark04 bryantpark04 merged commit 02c65c5 into main Jun 18, 2024
6 checks passed
@bryantpark04 bryantpark04 deleted the bryantp/aggregation-order-by branch June 18, 2024 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add orderBy for aggregations
3 participants