-
Notifications
You must be signed in to change notification settings - Fork 591
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
ignore nulls
in over window function
#17601
Comments
Just document an example of finding the closet index event of the each trade event. For each row in the table
Then we construct the following query:
|
This issue has been open for 60 days with no activity. If you think it is still relevant today, and needs to be done in the near future, you can comment to update the status, or just manually remove the You can also confidently close this issue as not planned to keep our backlog clean. |
Since now we have supported |
Recently a user asked about the following use case: create table raw_data (
ts timestamp,
foo int,
bar int
);
insert into raw_data values (now(), null, 1);
insert into raw_data values (now(), null, 10);
insert into raw_data values (now(), 7, null);
insert into raw_data values (now(), null, 8);
create materialized view mv1 as
select
ts,
last_value(foo ignore nulls) over (order by ts) as foo,
last_value(bar ignore nulls) over (order by ts) as bar
from raw_data;
create materialized view mv2 as
select
ts,
last_value(foo) filter (where foo is not null) over (order by ts) as foo,
last_value(bar) filter (where bar is not null) over (order by ts) as bar
from raw_data;
-- Desired output:
ts | foo | bar
--------------------
... | null | 1
... | null | 10
... | 7 | 10
... | 7 | 8 Each new row inserted into But I found an interesting workaround using SINK INTO TABLE and CHANGELOG, for this specific case: create table raw_data (
ts timestamp,
foo int,
bar int
) append only;
create table latest (
id int,
ts timestamp,
foo int,
bar int,
primary key (id)
) on conflict do update if not null with version column (ts);
create sink s into latest as
select 1 as id, ts, foo, bar from t;
create materialized view changes as
with cl as changelog from latest
select ts, foo, bar from cl where id = 1 and changelog_op = 1 or changelog_op = 3; The |
worth a blog 🤣 #HackOnRisingWave |
Is your feature request related to a problem? Please describe.
For example,
LAST_VALUE (order_id IGNORE NULLS)
is supported in popular DBs such as MySQL, DuckDB, Redshift, Snowflake and Starrocks.It has appeared in four users' use cases that
ignore nulls
is a must for expressing their workload. Otherwise, not only do they need to impose awkward limitations on the application semantics they want to convey, but they also have much worse performance.The use case is similar to the one described in the question: https://stackoverflow.com/questions/37470931/how-to-ignore-nulls-in-postgresql-window-functions-or-return-the-next-non-null:
Describe the solution you'd like
No response
Describe alternatives you've considered
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: