Closed radeusgd closed 1 month ago
Log of my attempts:
The way we did this for Postgres, e.g.
SELECT FIRST_VALUE(X) IGNORE NULLS OVER (ORDER BY Y ASC NULLS FIRST) AS "FOO" FROM TEST123 GROUP BY Z
fails with
[TEST123.X] is not a valid group by expression
The thing is - FIRST_VALUE
in Snowflake is only a Window function, it is not an aggregate function. So it cannot be used as an aggregate directly. It will work if I add X and Y to GROUP BY but that changes query semantics in a way we don't want here.
Technically, the Window function for each group will yield the same result in that group, so I tried the ANY_VALUE
trick:
SELECT ANY_VALUE(FIRST_VALUE(X) IGNORE NULLS OVER (ORDER BY Y ASC NULLS FIRST)) AS "FOO" FROM TEST123 GROUP BY Z
but that also fails with
Window function [FIRST_VALUE(TEST123.X) OVER (ORDER BY TEST123.Y ASC NULLS FIRST)] may not appear inside an aggregate function.
Radosław Waśko reports a new STANDUP for the provided date (2024-08-16):
Progress: Initial work on First/Last in Snowflake - seeing what approaches we can take and how we can integrate it into existing IR. It should be finished by 2024-08-23.
Next Day: Next day I will be working on the #10411 task. Continue, as I did not find a solution yet.
Radosław Waśko reports a new STANDUP for yesterday (2024-08-19):
Progress: Refactoring aggregate logic to allow for more customization needed for First/Last workaround. It should be finished by 2024-08-23.
Next Day: Next day I will be working on the #10411 task. Continue
Radosław Waśko reports a new STANDUP for yesterday (2024-08-20):
Progress: Working on the custom handling for First/Last using row_number. Trying to figure out how to write it in a non-ugly way, but failing. It should be finished by 2024-08-23.
Next Day: Next day I will be working on the same task. Try to implement whatever that works and then see if I can make it a bit cleaner.
Pavel Marek reports a new STANDUP for today (2024-08-21):
Progress: Got it working for Snowflake. SQLite is actually more problematic than I thought, at least if we want to handle ignore_nothing=True
. I'm considering abandoning it, or only implementing the ignore_nothing=False
case It should be finished by 2024-08-23.
Next Day: Next day I will be working on the same task. Experiment with limited SQLite support. Try to clean up the code a bit. Check if more tests are needed
Radosław Waśko reports a new STANDUP for yesterday (2024-08-22):
Progress: Cleaned up the code. It should be finished by 2024-08-23.
Next Day: Next day I will be working on the same task. Try adding limited SQLite support. Adapt tests.
Radosław Waśko reports a new STANDUP for the provided date (2024-08-23):
Progress: Finishing the PR - added SQLite support for partial First/Last and adapted tests. Implemented #10848 refactor and put PR. It should be finished by 2024-08-23.
Next Day: Next day I will be working on the #9875 task. Next tasks.
As part of my work on #9486 I did not manage to easily port our code to support the First and Last aggregations. So I'm creating this ticket to investigate it further.
The first step will be to revert disabling the tests and aggregators: