Closed colinhacks closed 1 year ago
I think it's OK to not have an inline shape for group in query builder. It is sugar for being wrapped in a select
and conceptually it's probably simpler to think of grouping and then shaping the data as separate concerns. So I think that the first option looks fine.
I assume that CUBE
and ROLLUP
would be something like e.group.cube
and e.group.rollup
.
Indeed! Just updated the proposal to include those. I think top-level e.cube
and e.rollup
are ok though. The reason I scoped e.group.set
and e.group.tuple
is because they're not quite the same as regular e.set
and e.tuple
and it would increase implementation difficulty to overload those functions further.
I think it's nice to scope all of them under e.group
because these constructs are exclusively used in group
and nowhere else. They aren't types, they aren't functions, they are "grouping expressions", much like we have "type expressions" and plain "expressions".
Agree with @vpetrovykh re scoping of tools under e.group
. Option 1 seems fine to me, as the loss of immediate shape is easily alleviated by composing a e.select
.
Proposed query builder API for group:
In EdgeQL:
Query builder:
This uses an object literal to simulate the fact that
<grouping-ref>
only accepts pre-defined aliases or simple paths. We need some string value to associate with each grouping-ref. The keys of the object literal correspond to the value ofgrouping
in the final result. We should be able to repurpose some of our existingwith
extraction logic to properly add the necessary clauses to theusing
clause.e.group.set
ande.group.tuple
wrap their input in an object with a single autogenerated key with a known prefix. IntoEdgeQL
, when a key with that prefix is encountered, the contents of the object it points to will be rendered inside curly braces or parens (respectively). The prefixed key itself won't occur anywhere in the resulting EdgeQL.Downsides
group Movie { title } by .release_year
.using
is implicit andby
doesn't appear syntacticallyNaming Considerations
e.group.set
could bee.grouping_set
or juste.set
e.group.tuple
could bee.grouping_list
or juste.tuple
(would require some special handling intoEdgeQL
)e.cube/e.rollup
could be scoped toe.group.cube/e.group.rollup
Alternative:
by
keyThe
by
clause is specified in a special key calledby
. The rest of the object can be used to specify the shape to be applied to theelements
.e.select
anyway.