mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-17 21:24:28 +00:00
Fix function if
This commit is contained in:
parent
e229fd54c9
commit
2e8ac2bdf9
@ -35,6 +35,12 @@ static DataTypePtr createNumericDataType(const ASTPtr & arguments)
|
||||
return std::make_shared<DataTypeNumber<T>>();
|
||||
}
|
||||
|
||||
bool isUInt64ThatCanBeInt64(const DataTypePtr & type)
|
||||
{
|
||||
const DataTypeUInt64 * uint64_type = typeid_cast<const DataTypeUInt64 *>(type.get());
|
||||
return uint64_type && uint64_type->canUnsignedBeSigned();
|
||||
}
|
||||
|
||||
|
||||
void registerDataTypeNumbers(DataTypeFactory & factory)
|
||||
{
|
||||
|
@ -71,4 +71,6 @@ using DataTypeInt128 = DataTypeNumber<Int128>;
|
||||
using DataTypeUInt256 = DataTypeNumber<UInt256>;
|
||||
using DataTypeInt256 = DataTypeNumber<Int256>;
|
||||
|
||||
bool isUInt64ThatCanBeInt64(const DataTypePtr & type);
|
||||
|
||||
}
|
||||
|
@ -1105,6 +1105,14 @@ public:
|
||||
if (const auto * right_array = checkAndGetDataType<DataTypeArray>(arg_else.type.get()))
|
||||
right_id = right_array->getNestedType()->getTypeId();
|
||||
|
||||
/// Special case when one column is Integer and another is UInt64 that can be actually Int64.
|
||||
/// The result type for this case is Int64 and we need to change UInt64 type to Int64
|
||||
/// so the NumberTraits::ResultOfIf will return Int64 instead if Int128.
|
||||
if (isNativeInteger(arg_then.type) && isUInt64ThatCanBeInt64(arg_else.type))
|
||||
right_id = TypeIndex::Int64;
|
||||
else if (isNativeInteger(arg_else.type) && isUInt64ThatCanBeInt64(arg_then.type))
|
||||
left_id = TypeIndex::Int64;
|
||||
|
||||
if (!(callOnBasicTypes<true, true, true, false>(left_id, right_id, call)
|
||||
|| (res = executeTyped<UUID, UUID>(cond_col, arguments, result_type, input_rows_count))
|
||||
|| (res = executeString(cond_col, arguments, result_type))
|
||||
|
@ -6,6 +6,6 @@ SELECT ifNotFinite(nan, 2);
|
||||
SELECT ifNotFinite(-1 / 0, 2);
|
||||
SELECT ifNotFinite(log(0), NULL);
|
||||
SELECT ifNotFinite(sqrt(-1), -42);
|
||||
SELECT ifNotFinite(1234567890123456789, -1234567890123456789); -- { serverError 386 }
|
||||
SELECT ifNotFinite(12345678901234567890, -12345678901234567890); -- { serverError 386 }
|
||||
|
||||
SELECT ifNotFinite(NULL, 1);
|
||||
|
@ -8,3 +8,4 @@
|
||||
[{-4741124612489978151:1,-3236599669630092879:2,5607475129431807682:3},{-1:1}]
|
||||
{1:-4741124612489978151,2:-3236599669630092879,3:5607475129431807682}
|
||||
[{1:-4741124612489978151,2:-3236599669630092879,3:5607475129431807682},{-1:1}]
|
||||
-1234567890123456789
|
||||
|
@ -8,4 +8,4 @@ select map(-4741124612489978151, 1, -3236599669630092879, 2, 5607475129431807682
|
||||
select [map(-4741124612489978151, 1, -3236599669630092879, 2, 5607475129431807682, 3), map(-1, 1)];
|
||||
select map(1, -4741124612489978151, 2, -3236599669630092879, 3, 5607475129431807682);
|
||||
select [map(1, -4741124612489978151, 2, -3236599669630092879, 3, 5607475129431807682), map(-1, 1)];
|
||||
|
||||
select if(materialize(1), -1234567890123456789, 1234567890123456789);
|
||||
|
Loading…
Reference in New Issue
Block a user