Skip to content

Incorrect NULL handling in lead window function (SQLancer) #12717

@2010YOUY01

Description

@2010YOUY01

Describe the bug

See the reproducer in datafusion-cli (compiled from the latest main, commit 0242767)

> create table t1(v1 int);
0 row(s) fetched.
Elapsed 0.015 seconds.

> insert into t1 values (1);
+-------+
| count |
+-------+
| 1     |
+-------+
1 row(s) fetched.
Elapsed 0.017 seconds.

> SELECT LEAD(NULL, 1, false) OVER () FROM t1;
Arrow error: Cast error: Casting from Boolean to Null not supported

To Reproduce

No response

Expected behavior

This query should be valid, NULL literal can be interpreted as a missing bool value, so 1st and 3rd arg in lead() function have the same type

postgres result:

postgres=# create table t1(v1 int);
iCREATE TABLE
postgres=# insert into t1 values (1);
INSERT 0 1
postgres=# SELECT LEAD(NULL, 1, false) OVER () FROM t1;
 lead 
------
 f
(1 row)

Additional context

Found by SQLancer #11030

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions