-
Notifications
You must be signed in to change notification settings - Fork 8.3k
"Unexpected inf or nan to integer conversion" error when using toInt32 and if/isNaN check #34854
Copy link
Copy link
Closed
Labels
unexpected behaviourResult is unexpected, but not entirely wrong at the same time.Result is unexpected, but not entirely wrong at the same time.
Description
Describe the unexpected behaviour
"Unexpected inf or nan to integer conversion" error is thrown when calling toInt32 on the result of an if expression that checks for isNaN and evaulates to NULL.
How to reproduce
-
Which ClickHouse server version to use: 21.12.4 revision 54452 & 22.2.2 revision 54455
-
Which interface to use, if matters: clickhouse-client
-
Non-default settings, if any: none
-
CREATE TABLEstatements for all tables involved
create temporary table tmp_repro_nan_check (
foo Nullable(Int32)
);
- Sample data for all these tables, use [clickhouse-obfuscator]
insert into tmp_repro_nan_check values (nan);
- Queries to run that lead to unexpected result
SELECT toInt32(if(isNaN(foo), NULL, foo))
FROM tmp_repro_nan_check
Expected behavior
Expect the result to be NULL similar to the following:
SELECT toInt32(NULL)
Error message and/or stacktrace
Code: 70. DB::Exception: Received from localhost:9000. DB::Exception: Unexpected inf or nan to integer conversion: while executing 'FUNCTION toInt32(if(isNaN(foo), NULL, foo) :: 3) -> toInt32(if(isNaN(foo), NULL, foo)) Nullable(Int32) : 0'. (CANNOT_CONVERT_TYPE)
Additional context
There seems to be an issues with returning NULL in the truthy/left branch of the condition. Updating the select statement to return 0 does not throw an error
SELECT toInt32(if(isNaN(foo), 0, foo))
FROM tmp_repro_nan_check
Query id: 6f91e2e3-caf2-4aa8-96a0-83bd6755ca37
┌─toInt32(if(isNaN(foo), 0, foo))─┐
│ 0 │
└─────────────────────────────────┘
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
unexpected behaviourResult is unexpected, but not entirely wrong at the same time.Result is unexpected, but not entirely wrong at the same time.