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

Support filtering on aggregated values #1279

Open
sorenbs opened this issue Nov 14, 2017 · 7 comments

Comments

Projects
None yet
4 participants
@sorenbs
Copy link
Member

commented Nov 14, 2017

Support filtering on values aggregated over related nodes.

These filters apply both on top level queries and relation fields.

This syntax is highly experimental. Please provide feedback about the syntax and other aggregation functions you might need.

Supported aggregate functions

  • avg
  • count
  • min
  • max
  • sum

Examples

# students where friends older than 25 have an average age less than 50
allStudents(where: { friends_agg: { filter: { age_gt: 25 },  condition: { age_avg_lt: 50 } } })

# students whose friends combined are less than 100 years old
allStudents(where: { friends_agg: { condition: { age_sum_lt: 100 } })

# combination of above
allStudents(where: { friends_agg: { AND: [
  { filter: { age_gt: 25 },  condition: { age_avg_lt: 50 } }
  { condition: { age_sum_lt: 100 } }
]}})

Considerations

We can probably support the same filters for scalar lists. See https://github.com/graphcool/framework/issues/1275

Other related issues

@sorenbs sorenbs added this to the 1.0-beta3 milestone Nov 14, 2017

@sorenbs sorenbs self-assigned this Nov 14, 2017

@nikolasburk nikolasburk referenced this issue Nov 14, 2017

Open

[Prisma 1.0] Specifications #353

28 of 32 tasks complete
@kbrandwijk

This comment has been minimized.

Copy link
Contributor

commented Nov 14, 2017

I don't really understand how the examples relate to aggregations. Where are you actually querying the aggregation, or defining what fields to aggregate on? Also see https://github.com/graphcool/framework/issues/70#issuecomment-312384756 (part of an issue that should probably be closed because of this new proposal).

This seems more like 'filtering on relation fields'.

@sorenbs

This comment has been minimized.

Copy link
Member Author

commented Nov 14, 2017

#70 is about returning aggregated values. This issue is about filtering on aggregated values. They are somewhat related, but certainly two separate features. I'll prepare a proposal for returning aggregated values later :-) The proposal for returning aggregated values in in #1312

@kbrandwijk

This comment has been minimized.

Copy link
Contributor

commented Nov 14, 2017

Okay, thank you for explaining. Taking a second look at the examples, I now spot the aggregation fields.
One more suggestion: for aggregation, I think it makes sense to split the aggregation fields into objects. I mention this in every proposal, because a query like this is harder to construct based on a user search form, for example.

So I'd rather have: allStudents(filter: { friends_agg: { condition: { age: { sum: { lt: 100 } } } } })
Although it's a lot more verbose, it's much, much easier to construct using variables:

query ($condition: FieldAggregationCondition) { 
  allStudents(filter: { friends_agg: { condition: { age: $condition } } }) 
}
query ($field: FieldAggregation) { 
  allStudents(filter: { friends_agg: { condition: { $field } } }) 
}
@marktani

This comment has been minimized.

Copy link
Contributor

commented Nov 15, 2017

How does this tie into ordering by aggregation? 🙂

@sorenbs

This comment has been minimized.

Copy link
Member Author

commented Nov 21, 2017

@kbrandwijk I have updated the proposed API to be much simpler.

We still use the combined age_gt fields. If you think this should be changed, please open a separate issue, as this should be consistent across all filters. Now is a good time to raise this as 1.0 introduces breaking changes anyway.

@marktani it does not. Ordering is currently specified by an enum value. We should consider changing that to something more flexible that can support that use case.

@kbrandwijk

This comment has been minimized.

@mavilein mavilein referenced this issue Dec 14, 2017

Merged

[WIP] Prisma #1318

41 of 42 tasks complete

@marktani marktani modified the milestones: 1.0-beta3, 1.1 Dec 15, 2017

@marktani marktani removed this from the 1.1 milestone Jan 22, 2018

@stale

This comment has been minimized.

Copy link

commented Dec 6, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added status/stale and removed status/stale labels Dec 6, 2018

@schickling schickling changed the title filter on aggregated values Support filtering on aggregated values Dec 6, 2018

@stale stale bot added the status/stale label Feb 24, 2019

@prisma prisma deleted a comment from stale bot Feb 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.