mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 00:52:02 +00:00
Function accurateCastOrNull fixed unitialized values for numeric cast
This commit is contained in:
parent
ea0a49ed7a
commit
d712748304
@ -188,7 +188,10 @@ struct ConvertImpl
|
||||
(std::is_same_v<FromFieldType, UInt128> || std::is_same_v<ToFieldType, UInt128>))
|
||||
{
|
||||
if constexpr (std::is_same_v<Additions, AccurateOrNullConvertStrategyAdditions>)
|
||||
{
|
||||
vec_to[i] = 0;
|
||||
(*vec_null_map_to)[i] = true;
|
||||
}
|
||||
else
|
||||
throw Exception("Unexpected UInt128 to big int conversion", ErrorCodes::NOT_IMPLEMENTED);
|
||||
}
|
||||
@ -215,7 +218,10 @@ struct ConvertImpl
|
||||
if (convert_result)
|
||||
vec_to[i] = result;
|
||||
else
|
||||
{
|
||||
vec_to[i] = static_cast<ToFieldType>(0);
|
||||
(*vec_null_map_to)[i] = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -238,6 +244,7 @@ struct ConvertImpl
|
||||
{
|
||||
if constexpr (std::is_same_v<Additions, AccurateOrNullConvertStrategyAdditions>)
|
||||
{
|
||||
vec_to[i] = 0;
|
||||
(*vec_null_map_to)[i] = true;
|
||||
continue;
|
||||
}
|
||||
@ -255,6 +262,7 @@ struct ConvertImpl
|
||||
{
|
||||
if (std::is_same_v<Additions, AccurateOrNullConvertStrategyAdditions>)
|
||||
{
|
||||
vec_to[i] = 0;
|
||||
(*vec_null_map_to)[i] = true;
|
||||
}
|
||||
else
|
||||
|
15
tests/performance/casts.xml
Normal file
15
tests/performance/casts.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<test max_ignored_relative_change="0.2">
|
||||
<settings>
|
||||
<max_memory_usage>15G</max_memory_usage>
|
||||
</settings>
|
||||
|
||||
<create_query>CREATE TABLE t (x UInt64) ENGINE = Memory</create_query>
|
||||
<!-- use less threads to save memory -->
|
||||
<fill_query>INSERT INTO t SELECT number AS x FROM numbers_mt(200000000) SETTINGS max_threads = 8</fill_query>
|
||||
<drop_query>DROP TABLE IF EXISTS t</drop_query>
|
||||
|
||||
<query>SELECT cast(x, 'Int64'), cast(x, 'Int128'), cast(x, 'Int256'), cast(x, 'String'), cast(x, 'Decimal64(8)') FROM t FORMAT Null</query>
|
||||
<query>SELECT accurateCast(x, 'Int64'), accurateCast(x, 'Int128'), accurateCast(x, 'Int256'), accurateCast(x, 'String'), accurateCast(x, 'Decimal64(8)') FROM t FORMAT Null</query>
|
||||
<query>SELECT accurateCastOrNull(x, 'Int64'), accurateCastOrNull(x, 'Int128'), accurateCastOrNull(x, 'Int256'), accurateCastOrNull(x, 'String'), accurateCastOrNull(x, 'Decimal64(8)') FROM t FORMAT Null</query>
|
||||
|
||||
</test>
|
@ -28,3 +28,5 @@
|
||||
\N
|
||||
\N
|
||||
\N
|
||||
127
|
||||
\N
|
||||
|
@ -33,3 +33,5 @@ SELECT accurateCastOrNull(inf, 'UInt64');
|
||||
SELECT accurateCastOrNull(inf, 'UInt256');
|
||||
SELECT accurateCastOrNull(nan, 'UInt64');
|
||||
SELECT accurateCastOrNull(nan, 'UInt256');
|
||||
|
||||
SELECT accurateCastOrNull(number + 127, 'Int8') AS x FROM numbers (2) ORDER BY x;
|
||||
|
Loading…
Reference in New Issue
Block a user