-
Notifications
You must be signed in to change notification settings - Fork 603
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
feat: grouping sets functionality #550
Comments
This could also capture generic |
PostgreSQL has great docs on the feature: https://www.postgresql.org/docs/current/queries-table-expressions.html#QUERIES-GROUPING-SETS. I'm not entirely sure what the API should look like, but here are a few requirements and considerations for anyone who wants to work on this:
GROUP BY a, CUBE (b, c), GROUPING SETS ((d), (e)) which expands to GROUP BY GROUPING SETS (
(a, b, c, d), (a, b, c, e),
(a, b, d), (a, b, e),
(a, c, d), (a, c, e),
(a, d), (a, e)
) In my mind this rules out a method that exists only on t.group_by(...).cube() doesn't make a whole lot of sense unless we allow There are two viable approaches I see.
import ibis
t = ibis.table([
("a", "string"),
("b", "string"),
("c", "string"),
("d", "string"),
("money", "float64"),
])
t.group_by([
"a",
ibis.cube(("b", "c")),
ibis.grouping_sets([("d",), ("e",)])
]) I prefer this approach because it requires the least number of invasive changes and I believe will not require any hacks.
This is pretty tantalizing, and superficially seems to compose well until you start trying to ... compose these methods: # using t from the previous example, seems nice but see below
t.group_by("a").cube(("b", "c")).grouping_sets([("d",), ("e",)])
# equivalent except for column ordering
t.cube(("b", "c")).group_by("a").grouping_sets([("d",), ("e",)])
# t.cube would need to have a single object that tracks all the grouping set "things"
# to make sure it doesn't generate `GROUP BY` multiple times. Since |
Reopening this, as we'll probably want it for full TPC-DS support (#9447). |
Definite nice to have - was just looking for a way to do this today. :D |
No description provided.
The text was updated successfully, but these errors were encountered: