You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "crepererum (via GitHub)" <gi...@apache.org> on 2024/10/29 15:26:43 UTC
[I] `nullif` and float arguments result in Utf8 [datafusion]
crepererum opened a new issue, #13164:
URL: https://github.com/apache/datafusion/issues/13164
### Describe the bug
`nullif(float_arg, mask)` results in a Utf8 output but should preserve the float type.
### To Reproduce
Use the following sqllogictest (I've adapted the `nullif.slt` file, that's why there are some more columns in that table):
```text
statement ok
CREATE TABLE test(
int_field INT,
bool_field BOOLEAN,
text_field TEXT,
more_ints INT,
float_field FLOAT
) as VALUES
(1, true, 'abc', 2, 1.1),
(2, false, 'def', 2, 2.2),
(3, NULL, 'ghij', 3, 3.3),
(NULL, NULL, NULL, 4, NULL),
(4, false, 'zxc', 5, 4.4),
(NULL, true, NULL, 6, NULL)
;
query R rowsort
SELECT NULLIF(float_field, bool_field) FROM test;
----
1.1
2.2
3.3
4.4
NULL
NULL
```
This will fail with:
```text
External error: query columns mismatch:
[SQL] SELECT NULLIF(float_field, bool_field) FROM test;
[Expected] [R]
[Actual ] [T]
```
which means the output type was coerced to `Utf8`.
You can further test this by adding some floating point operation:
```
query R rowsort
SELECT NULLIF(float_field, bool_field) + 1.0 FROM test;
----
2.1
3.2
4.3
5.4
NULL
NULL
```
which fails with:
```text
External error: query failed: DataFusion error: Error during planning: Cannot coerce arithmetic expression Utf8 + Float64 to valid types
[SQL] SELECT NULLIF(float_field, bool_field) + 1.0 FROM test;
```
### Expected behavior
Both test should pass.
### Additional context
Tested with 444a673682a4823b98695568ecdab1087b5b6a60.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] `nullif` and float arguments result in Utf8 [datafusion]
Posted by "crepererum (via GitHub)" <gi...@apache.org>.
crepererum commented on issue #13164:
URL: https://github.com/apache/datafusion/issues/13164#issuecomment-2444755530
Oh shoot, I misremembered the semantics of `nullif`, I thought "make it null if condition in 2nd arg is met, otherwise return first argument", not "null if equal" (which would have been a better name).
So I think casting both to strings is probably Ok.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] `nullif` and float arguments result in Utf8 [datafusion]
Posted by "crepererum (via GitHub)" <gi...@apache.org>.
crepererum closed issue #13164: `nullif` and float arguments result in Utf8
URL: https://github.com/apache/datafusion/issues/13164
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] `nullif` and float arguments result in Utf8 [datafusion]
Posted by "crepererum (via GitHub)" <gi...@apache.org>.
crepererum commented on issue #13164:
URL: https://github.com/apache/datafusion/issues/13164#issuecomment-2444627452
If someone hits this bug: you can work around this by using a CASE clause, i.e. convert
```SQL
NULLIF(float_field, bool_field)
```
to
```
CASE
WHEN bool_field THEN NULL
ELSE float_field
END
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] `nullif` and float arguments result in Utf8 [datafusion]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on issue #13164:
URL: https://github.com/apache/datafusion/issues/13164#issuecomment-2444675452
FWIW, PostgreSQL doesn't support NULLIF with two different types:
```operator does not exist: double precision = boolean LINE 1: SELECT NULLIF(float_field, bool_field) FROM test ^ HINT: No operator matches the given name and argument types. You might need to add explicit type casts.```
Is the idea here to cast `bool_field` to float?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org