-
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
Add langlib functions for aggregation #1135
Comments
More details. All the functions here are
|
When min/max/first/last/avg have no args, then we want them to return (). We can handle this as part of the special semantics of function calls with arguments that are aggregated variables #1134 (comment). |
Question: what should decimal:avg do on overflow? Possibilities:
Given that decimal addition panics, consensus is 1. People can trap this if they want. Note that decimals can represent values up to 10^6144, so this isn't a likely situation in practice. |
@jclark, do we need to return var input = [{name: "Saman", price: 1}, {name: "Amal", price: 2}, {name: "Saman", price: 3}];
var x = from var {name, price} in input
where name == "No name"
collect min(price); is the value of x If yes, the output of the following query expression should be var x = from var {name, price} in input
where name == "No name"
collect avg(price1) + avg(price2); |
The answer to both questions is yes. But this doesn't change the definition of the langlib functions. Rather it's part of the process by which For the second case, the static type of |
@jclark, based on the above comment, please help me to understand the following points.
var x = from var {name, price} in input
where name == "No name"
collect {average: avg(price)}; Is the output of type Price record {|
decimal p?;
|};
Price[] x = from var {name, price} in [{name: "", price: 2}]
where name == "No name"
group by var _ = true
select {average: avg(price)}; |
No. The static type is T. The expression following var x = from var {name, price} in input
where name == "No name"
collect {average: avg(price)}; The output is Note that you can also do something like type Price record {|
decimal p?;
|};
Price[] x = from var {name, price} in [{name: "", price: 2}]
where name == "No name"
group by var _ = true
select {average: avg(price)};
That's correct. With |
My fix in 5e76414 doesn't handle |
Part of #441.
At least:
avg
(at least to lang.float and lang.decimal); probably int:avg should return a decimal (as in XQuery)count
(probably to lang.value)some
,every
(to lang.boolean)Notes here #441 (comment)
The text was updated successfully, but these errors were encountered: