Skip to content
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

Lead/Lag function does not return default value for out of range offset #19003

Closed
xumingming opened this issue Sep 12, 2023 · 2 comments · Fixed by #19015
Closed

Lead/Lag function does not return default value for out of range offset #19003

xumingming opened this issue Sep 12, 2023 · 2 comments · Fixed by #19015
Labels
bug Something isn't working correctness

Comments

@xumingming
Copy link
Contributor

// Trino TestLeadFunction.java
assertWindowQuery("lead(orderkey, null, -1) OVER (PARTITION BY orderstatus ORDER BY orderkey)",
        resultBuilder(TEST_SESSION, INTEGER, VARCHAR, INTEGER)
                .row(3, "F", null)
                .row(5, "F", null)
                .row(6, "F", null)
                .row(33, "F", null)
                .row(1, "O", null)
                .row(2, "O", null)
                .row(4, "O", null)
                .row(7, "O", null)
                .row(32, "O", null)
                .row(34, "O", null)
                .build());

In this test case, the offset is null, default value is specified as -1, but the expected value is null rather than -1, while in the doc([1]), it says that default value should be returned:

If the offset is null or larger than the window, the default_value is returned, or if it is not specified null is returned.

Lag function has similar issue.

[1]. https://trino.io/docs/current/functions/window.html

@xumingming
Copy link
Contributor Author

Related discussion in Velox: facebookincubator/velox#6413

@martint
Copy link
Member

martint commented Sep 12, 2023

The proper behavior is to raise an error if the offset is null, per the SQL specification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctness
Development

Successfully merging a pull request may close this issue.

2 participants