mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +00:00
Fix signedness conversion monotonicity
This commit is contained in:
parent
c2f762e20a
commit
654245af3c
@ -1570,25 +1570,15 @@ struct ToNumberMonotonicity
|
||||
if (left.isNull() || right.isNull())
|
||||
return {};
|
||||
|
||||
if (from_is_unsigned == to_is_unsigned)
|
||||
{
|
||||
/// all bits other than that fits, must be same.
|
||||
if (divideByRangeOfType(left.get<UInt64>()) == divideByRangeOfType(right.get<UInt64>()))
|
||||
return {true};
|
||||
|
||||
/// Function cannot be monotonic when left and right are not on the same ranges.
|
||||
if (divideByRangeOfType(left.get<UInt64>()) != divideByRangeOfType(right.get<UInt64>()))
|
||||
return {};
|
||||
}
|
||||
|
||||
if (to_is_unsigned)
|
||||
return {true};
|
||||
else
|
||||
{
|
||||
/// When signedness is changed, it's also required for arguments to be from the same half.
|
||||
/// And they must be in the same half after converting to the result type.
|
||||
if (left_in_first_half == right_in_first_half
|
||||
&& (T(left.get<Int64>()) >= 0) == (T(right.get<Int64>()) >= 0)
|
||||
&& divideByRangeOfType(left.get<UInt64>()) == divideByRangeOfType(right.get<UInt64>()))
|
||||
return {true};
|
||||
|
||||
return {};
|
||||
}
|
||||
// If To is signed, it's possible that the signedness is different after conversion. So we check it explicitly.
|
||||
return {(T(left.get<UInt64>()) >= 0) == (T(right.get<UInt64>()) >= 0)};
|
||||
}
|
||||
|
||||
__builtin_unreachable();
|
||||
|
@ -0,0 +1 @@
|
||||
1
|
@ -0,0 +1,9 @@
|
||||
drop table if exists test1;
|
||||
|
||||
create table test1 (i Int64) engine MergeTree order by i;
|
||||
|
||||
insert into test1 values (53), (1777), (53284);
|
||||
|
||||
select count() from test1 where toInt16(i) = 1777;
|
||||
|
||||
drop table if exists test1;
|
Loading…
Reference in New Issue
Block a user