Group By and Aggregated Values #1312
Comments
Hello Soren, |
For the multiple level group, can you please add example data (ungrouped as well as grouped)? I can't quite grasp the concept of multi-level groups. |
@ejoebstl I have added example responses to all queries. This should make the proposed dynamics very clear :-) Looking forward to your feedback. The multi level groups are really very simple. By exploiting the fact that we have a wonderful tree structure to place data into. The more interesting question is wether this is useful or not. |
It's an excellent idea to allow grouping without aggregation by exploiting the three structure. That's a main limitation of SQL. The feature itself is very useful. Until now, when you wanted to group data, you needed to come up with either a relation or do it in your application. Grouping and aggregation is not only incredibly useful for building powerful frontends (think of a search feature for thousands of nodes, where you can filter by fields), but also decreases overhead in the backend by a lot. Even if I just want to gather some statistics about my data using the playground, this makes everything easier. Some considerations:
I'm quite sure the proposal is a good way though. The few points above can most likely be added afterwards without any complication. |
Correct. It's also not possible to use an arbitrary expression. I think this ability might be worth giving up in trade for a simple type-safe API
See proposal #1279
Great idea!
In the future there will be only a single API flavour as described in #353 |
There is no example for a {
postsConnection {
aggregate {
count
}
}
} Please confirm or correct! |
Is it possible to order by aggregated value? I try to do a something like:
I want to query top Course order by daily / weekly / ... views. It will sum all episiodes views between 2 date and order by that sum. |
Why was this issue moved to the graphcool-framework repo? I thought that Group By and Aggregated Values would be implemented in Prisma. The Prisma documentation links to this issue |
As I know Graphcool Framework is a GraphQL backend solution. Still a lot of people using it like me. Prisma is not a replacement. It is an open-source GraphQL query engine can connect to a lot of different database not just Graphcool Framework. It's a standalone version of Graphcool 1.0 and they will go a different way from now. You can read it here: https://www.graph.cool/forum/t/graphcool-framework-and-prisma/2237 I'm still waiting for them to this features, because I think I'll stick with Graphcool Framework. :) Everyone can correct me if I'm wrong. |
@kieusonlam Ok, but that doesn't explain why this feature will not be implemented in Prisma as well. the |
@jvbianchi It's already have this feature. You can check the example here: https://github.com/graphcool/graphql-server-example |
@kieusonlam That is what I just said. count has been implemented. But avg, median, max, min, sum and group by have not. Do you have a example with any of this other aggregated functions? |
@jvbianchi Hmm, yup, that's my bad. It's still missing avg, median, max, min, sum. We may wait for graphcool team to have the right answer. |
shameless bump: begging for this feature ;) |
Any update for this feature? |
Going to bump as well. Not having this feature == lots more work and poor client performance. :) |
Will it be possible to use aggregates in filter query? query activeUsers {
users(where: {
commits: {
date_gte: "THIS_MONTH_DATE",
aggregate: {
count_gte: 5
}
}
}) {
email
}
} |
@sorenbs @schickling This feature is planned for Q3 in 2018. Only 1 month till the end of Q3. Any progress? Will aggregate functions be implemented at once or one by one? I really need |
Q3 2018 is over. Any news? |
I need max, there is any way I can get this functionality? |
@sorenbs Any news on this ? Can the Roadmap label be updated if it's planned for later ? |
Q3 has been over for a while and still no response as to the current status of this. An update would be nice 👍 |
Also looking for an update on the status of this. |
This continues to be an important feature for us. I'll update this issue when we have a concrete timeframe. See also this explanation for why we were unable to ship this feature in Q3 as planned. @FluorescentHallucinogen - we will likely implement a large chunk of this feature in one go as each individual aggregation is comparatively little work. |
Any ETA on this? Very much needed 🙏🏼 |
Waiting for this one to drop, there will be a big use in our project in production! |
At least implement |
any eta?( |
Bump. :) |
@sorenbs The Prisma 2 was released, my congrats 🎉 |
I want to echo @kirgene question. I want to be able to do something similar but looks like there is no way to do this. |
Are we forgotten? |
#70 Was a wide ranging discussion of how to support GroupBy and Aggregations in a type safe GraphQL API. This issue takes the learnings from previous discussions and provides a final API Proposal.
Throughout this proposal the examples will be based on this data schema:
Retrieving all users who live in
Aarhus
:See example return value
Data:
Return value:
Aggregations
Aggregate functions
API
Getting the average age of people living in
Aarhus
is accomplished like this in SQL:With Prisma it would look like this:
See example return value
Data:
Return value:
Limiting the scope of aggregations
The normal
where
,skip
,first
andorderBy
arguments can be used to limit the scope of data included in the aggregations:This will return the average age of the 5 oldest people in
Aarhus
See example return value
Data:
Return value:
Larger example
combining aggregations and data retrieval:
See example return value
Data:
Return value:
Group
In relational databases,
GROUP BY
is most often used together with aggregation functions like thisSELECT city, AVG(age) FROM User GROUP BY city
Because GraphQL returns tree structured data, it is quite compelling to use groupBy without aggregation functions:
See example return value
Data:
Return value:
Or even in multiple levels:
See example return value
Data:
Return value:
Combining groupBy and aggregations
The following query will group by city, return first 5 Users, average age of first 5 users and average age of everyone in city
See example return value
Data:
Return value:
Limitations
Both
groupBy
and aggregations are on single fields only. You can filter the data that goes into the aggregation, but there is no way to use expressions as keys in a group by query.The text was updated successfully, but these errors were encountered: