-
Notifications
You must be signed in to change notification settings - Fork 222
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
Cast inside aggregation fails with type error #3534
Comments
@max-sixty I've copied your comment over: Thanks, this does indeed look like a bug. For the moment, a workaround is to create the column outside the aggregation (as on the |
This is a symptom of #2723
The compiler is basically saying "so, which one is it? What is the type of |
I don't think I agree. All column expressions are always expressed as if operating on a single value with the understanding that they are implicitly "mapped"/broadcast over all rows.
A column of ints, which can also be seen from the fact that from artists
derive {artist_int = (artist_id | as int)}
aggregate {
total_int = sum artist_int,
# total_fail = sum (artist_id | as int),
} compiles to SELECT
COALESCE(SUM(CAST(artist_id AS int)), 0) AS total_int
FROM
artists
-- Generated by PRQL compiler version:0.10.0 (https://prql-lang.org) So in my mind, the bug report is about why does it work when defined with a separate |
If it a column of ints, then the cast should be Current implementation of the compiler and the type system both stem from my understanding of the language, where |
Totally agree about finishing #2723 , but in the meantime how is this different to any of the other type inference that's going on? What are the types of from invoices
derive {
transaction_fee = 0.8,
income = total - transaction_fee
}
filter income > 5 Assuming
I think that's not how these things are usually understood though. Usually everything is interpreted at a single row / tuple level and the types are rather:
So similarly it should be that |
Yes, I very much agree on your conclusion of what the types should be. Going forward, I would also say that in this query:
So that would answer your question of "why can I cast within derive, but not within aggregate". derive operates row-wise, but aggregate operates column-wise; it applies aggregation to the whole column at once. |
What's up?
What happened?
Cast inside aggregation fails with type error.
PRQL input
SQL output
Expected SQL output
MVCE confirmation
Anything else?
No response
The text was updated successfully, but these errors were encountered: