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

- (negation) with NULL literals does not work: can't be evaluated because the expression's type is Utf8, not signed #1192

Closed
Tracked by #1184 ...
alamb opened this issue Oct 28, 2021 · 11 comments · Fixed by #3771
Assignees
Labels
bug Something isn't working datafusion Changes in the datafusion crate good first issue Good for newcomers

Comments

@alamb
Copy link
Contributor

alamb commented Oct 28, 2021

Reproducer:

> select -null;
Internal("(- 'Literal { value: Utf8(NULL) }') can't be evaluated because the expression's type is Utf8, not signed numeric")

The correct output is null

I think the solution will likely be to teach Expr::Negative about type coercion (as is done in BinaryExpr and function calls) once coercion knows about the null type (and that it can be cast to any other type). See #1184 for more details

@alamb alamb changed the title - (negation) with NULL literals does not work - (negation) with NULL literals does not work: can't be evaluated because the expression's type is Utf8, not signed Oct 28, 2021
@alamb alamb added datafusion Changes in the datafusion crate bug Something isn't working labels Oct 28, 2021
@WinkerDu
Copy link
Contributor

WinkerDu commented Apr 8, 2022

@alamb plz assign to me, thank you.

@xudong963
Copy link
Member

I tested select -null; in mysql and postgres: mysql returned null but

postgres=# select -null;
ERROR:  operator is not unique: - unknown
LINE 1: select -null;
               ^
HINT:  Could not choose a best candidate operator. You might need to add explicit type casts.

Do you need this syntax in iox? @alamb

@WinkerDu
Copy link
Contributor

WinkerDu commented Apr 9, 2022

I tested select -null; in mysql and postgres: mysql returned null but

postgres=# select -null;
ERROR:  operator is not unique: - unknown
LINE 1: select -null;
               ^
HINT:  Could not choose a best candidate operator. You might need to add explicit type casts.

Do you need this syntax in iox? @alamb

@xudong963 Thanks for the test! I agree we can discuss more on it.

@alamb
Copy link
Contributor Author

alamb commented Apr 10, 2022

Do you need this syntax in iox? @alamb

We do not need this syntax in IOx (and if we do I can always add it at that time)

@WinkerDu
Copy link
Contributor

@alamb @xudong963 Maybe we can introduce this syntax, and keep the contract that operators comes out result NULL when accepts NULL.

@liukun4515
Copy link
Contributor

liukun4515 commented Apr 17, 2022

@alamb @xudong963 Maybe we can introduce this syntax, and keep the contract that operators comes out result NULL when accepts NULL.

It's better to make it consistent with PG in SQL dialect.

@WinkerDu
Copy link
Contributor

I feel free to close the pr #2249 since more conservative opinions of introducing -NULL SQL dialect
Thank you @liukun4515 @xudong963

@liukun4515
Copy link
Contributor

liukun4515 commented May 26, 2022

I think this issue can be closed.
@alamb @andygrove

@alamb
Copy link
Contributor Author

alamb commented May 26, 2022

🤔 I just tried the query again, and it now gives a different error:

select -null;
Internal("(- 'Literal { value: NULL }') can't be evaluated because the expression's type is Null, not signed numeric")

I think we are getting closer...

@alamb alamb added the good first issue Good for newcomers label May 26, 2022
@alamb
Copy link
Contributor Author

alamb commented May 26, 2022

I bet this is a fairly straightforward matter of adding a case in the evaluation kernels

@drrtuy
Copy link
Contributor

drrtuy commented Oct 8, 2022

It is indeed an additional condition in expressions/negative.rs. Here is the PR #3771.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working datafusion Changes in the datafusion crate good first issue Good for newcomers
Projects
None yet
5 participants