mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 16:42:05 +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;
|
SELECT cast(-1, 'UInt8') as uint8;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
``` text
|
``` text
|
||||||
|
┌─uint8─┐
|
||||||
|
│ 255 │
|
||||||
|
└───────┘
|
||||||
```
|
```
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
@ -449,6 +453,8 @@ SELECT accurateCast(-1, 'UInt8') as uint8;
|
|||||||
```
|
```
|
||||||
|
|
||||||
``` text
|
``` 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}
|
## accurateCastOrNull(x, T) {#type_conversion_function-accurate-cast_or_null}
|
||||||
|
@ -219,10 +219,8 @@ struct ConvertImpl
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/// If From Data is Nan or Inf, throw exception
|
/// If From Data is Nan or Inf and we convert to integer type, throw exception
|
||||||
/// TODO: Probably this can be applied to all integers not just big integers
|
if constexpr (std::is_floating_point_v<FromFieldType> && !std::is_floating_point_v<ToFieldType>)
|
||||||
/// https://stackoverflow.com/questions/38795544/is-casting-of-infinity-to-integer-undefined
|
|
||||||
if constexpr (is_big_int_v<ToFieldType>)
|
|
||||||
{
|
{
|
||||||
if (!isFinite(vec_from[i]))
|
if (!isFinite(vec_from[i]))
|
||||||
{
|
{
|
||||||
@ -232,7 +230,7 @@ struct ConvertImpl
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
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