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

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

Closed
erratic-pattern opened this issue Jul 3, 2024 · 2 comments · Fixed by #11542
Closed

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

erratic-pattern opened this issue Jul 3, 2024 · 2 comments · Fixed by #11542
Assignees
Labels
bug Something isn't working

Comments

@erratic-pattern
Copy link
Contributor

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

@erratic-pattern erratic-pattern added the bug Something isn't working label Jul 3, 2024
@jayzhan211
Copy link
Contributor

jayzhan211 commented Jul 4, 2024

I think we should fix CASE expression to get something like int64(0) or float(0) based on the data type of data for null

This does not seem correct for all the case

Expr::Case(case) => case.when_then_expr[0].1.get_type(schema),

@Weijun-H
Copy link
Member

take

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

Successfully merging a pull request may close this issue.

3 participants