mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 09:32:01 +00:00
Fix bad cast in monotonicity analysis
This commit is contained in:
parent
d4d0647ccd
commit
e20eb570c5
@ -2147,14 +2147,18 @@ struct ToNumberMonotonicity
|
||||
if constexpr (std::is_floating_point_v<T>)
|
||||
return { .is_monotonic = true, .is_always_monotonic = true };
|
||||
|
||||
/// If converting from Float, for monotonicity, arguments must fit in range of result type.
|
||||
bool is_type_float = false;
|
||||
if (const auto * low_cardinality = typeid_cast<const DataTypeLowCardinality *>(&type))
|
||||
is_type_float = WhichDataType(low_cardinality->getDictionaryType()).isFloat();
|
||||
else
|
||||
is_type_float = WhichDataType(type).isFloat();
|
||||
const auto * low_cardinality = typeid_cast<const DataTypeLowCardinality *>(&type);
|
||||
const IDataType * low_cardinality_dictionary_type = nullptr;
|
||||
if (low_cardinality)
|
||||
low_cardinality_dictionary_type = low_cardinality->getDictionaryType().get();
|
||||
|
||||
if (is_type_float)
|
||||
WhichDataType which_type(type);
|
||||
WhichDataType which_inner_type = low_cardinality
|
||||
? WhichDataType(low_cardinality_dictionary_type)
|
||||
: WhichDataType(type);
|
||||
|
||||
/// If converting from Float, for monotonicity, arguments must fit in range of result type.
|
||||
if (which_inner_type.isFloat())
|
||||
{
|
||||
if (left.isNull() || right.isNull())
|
||||
return {};
|
||||
@ -2180,7 +2184,7 @@ struct ToNumberMonotonicity
|
||||
const size_t size_of_to = sizeof(T);
|
||||
|
||||
/// Do not support 128 bit integers and decimals for now.
|
||||
if (size_of_from > sizeof(Int64))
|
||||
if (size_of_from > sizeof(Int64) || which_inner_type.isDecimal())
|
||||
return {};
|
||||
|
||||
const bool left_in_first_half = left.isNull()
|
||||
|
@ -0,0 +1 @@
|
||||
1.1
|
5
tests/queries/0_stateless/02519_monotonicity_fuzz.sql
Normal file
5
tests/queries/0_stateless/02519_monotonicity_fuzz.sql
Normal file
@ -0,0 +1,5 @@
|
||||
DROP TABLE IF EXISTS t;
|
||||
CREATE TABLE t (x Decimal(18, 3)) ENGINE = MergeTree ORDER BY x;
|
||||
INSERT INTO t VALUES (1.1);
|
||||
SELECT * FROM t WHERE toUInt64(x) = 1;
|
||||
DROP TABLE t;
|
Loading…
Reference in New Issue
Block a user