-
Notifications
You must be signed in to change notification settings - Fork 55
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
Allow query frames to create aggregated variables #1144
Comments
Note that a |
Need to think about what happens when you try to aggregate an already aggregated variable, which can happen when there is more than one |
This part
is problematic. Not clear whether:
evaluates to
or
? |
The only way I see so far to make this work coherently is to allow a reference to an aggregated variable only as the entire expression in an arg-list or list-member-list (i.e. in a place where So to get the first case in the previous comment, you would have to write
|
One could maybe allow something like
I think that is going to become too hard to understand. |
If we completely get rid of the aggregated variable magic, then simple things become harder e.g. instead of
users would have to do
which isn't much different from
Or for group by, currently we have
which would turn into
So I think our current magic is still worthwhile. |
@jclark, should we allow the following cases, const ALLOWANCE = 12.1;
decimal wage = from var { salary } in persons
collect sum(salary + ALLOWANCE); In this case, a constant is added to the aggregated variable. decimal maxWage = from var { salary, bonus } in persons
collect sum(salary + max(bonus)); In this case, a result of an aggregated function is added to the aggregated variable. |
@jclark, in the parser level we have to represent both
|
In the current version of the specification, the semantics of the Additionally, there was a point when the select clause was referred to as the final clause. Hence, another alternative could be to label both of them as |
The spec currently uses the terminology I'm not all that keen on output-clause. Although the select-clause can be thought of as outputting values, I don't think that's the right model for something when you add collect clauses; the query-expression as a whole does not have output; it has a result (like other expressions). So we should think of a select/collect clause as constructing the query-expression result from the sequence of values emitted by the pipeline. I would therefore suggest |
Fixed by 5e76414 |
It turned out that I didn't need a production for result-clause. Since a query-construct-type and an on-conflict clause make sense with select but not with collect, I made query-expr be query-select-expr|query-collect-expr, instead of introducing a result-clause as select-clause|collect-clause. |
This is part of #441.
The new
group by
#1134 andcollect
#1137 query clauses can cause frames to have aggregated variables. When the binding of a variablex
is aggregated, the value ofx
is an list of values, but references tox
are treated specially. Each value of the variable in the list comes from a frame that has been aggregated with other frames.When a variable
x
is aggregated, it is similar to each reference tox
being treated as...x
, except that:For example:
Here
sum
will be resolved todecimal:sum
.The expression
salary + bonus
will be evaluated once for each index (they are guaranteed to have the same length). So it is equivalent to:which is in turn equivalent to
If you want to get at the value of an aggregated variable as a list, you can do
[x]
, which will work the same as[...x]
when x is array.Originally posted by @jclark in #1134 (comment)
The text was updated successfully, but these errors were encountered: