Skip to content

CASE with NULL branch does not coerce when passed to aggregate function  #11258

@erratic-pattern

Description

@erratic-pattern

Describe the bug

Type coercion doesn't seem to handle NULL in a CASE branch when used inside of an aggregate.

To Reproduce

In Datafusion CLI:

> CREATE TABLE example(data double precision);
0 row(s) fetched.
Elapsed 0.005 seconds.

> SELECT sum(CASE WHEN data is NULL THEN NULL ELSE data + 1 END) FROM example;
Error during planning: Execution error: User-defined coercion failed with Execution("Sum not supported for Null") No function matches the given name and argument types 'sum(Null)'. You might need to add explicit type casts.
        Candidate functions:
        sum(UserDefined)

Expected behavior

NULL type should coerce to the ELSE branch type.

Additional context

No response

Metadata

Metadata

Assignees

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