mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
Updated non-finite floating conversion into int
This commit is contained in:
parent
e945821e1f
commit
16a30eb4aa
@ -441,7 +441,11 @@ Example
|
||||
SELECT cast(-1, 'UInt8') as uint8;
|
||||
```
|
||||
|
||||
|
||||
``` text
|
||||
┌─uint8─┐
|
||||
│ 255 │
|
||||
└───────┘
|
||||
```
|
||||
|
||||
```sql
|
||||
@ -449,6 +453,8 @@ SELECT accurateCast(-1, 'UInt8') as uint8;
|
||||
```
|
||||
|
||||
``` text
|
||||
Code: 70. DB::Exception: Received from localhost:9000. DB::Exception: Value in column Int8 cannot be safely converted into type UInt8: While processing accurateCast(-1, 'UInt8') AS uint8.
|
||||
|
||||
```
|
||||
|
||||
## accurateCastOrNull(x, T) {#type_conversion_function-accurate-cast_or_null}
|
||||
|
@ -219,10 +219,8 @@ struct ConvertImpl
|
||||
}
|
||||
else
|
||||
{
|
||||
/// If From Data is Nan or Inf, throw exception
|
||||
/// TODO: Probably this can be applied to all integers not just big integers
|
||||
/// https://stackoverflow.com/questions/38795544/is-casting-of-infinity-to-integer-undefined
|
||||
if constexpr (is_big_int_v<ToFieldType>)
|
||||
/// If From Data is Nan or Inf and we convert to integer type, throw exception
|
||||
if constexpr (std::is_floating_point_v<FromFieldType> && !std::is_floating_point_v<ToFieldType>)
|
||||
{
|
||||
if (!isFinite(vec_from[i]))
|
||||
{
|
||||
@ -232,7 +230,7 @@ struct ConvertImpl
|
||||
continue;
|
||||
}
|
||||
else
|
||||
throw Exception("Unexpected inf or nan to big int conversion", ErrorCodes::NOT_IMPLEMENTED);
|
||||
throw Exception("Unexpected inf or nan to integer conversion", ErrorCodes::CANNOT_CONVERT_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user