Merge pull request #55019 from Avogar/fix-bad-cast-to-int128

Fix bad cast to ColumnVector<Int128> in function if
This commit is contained in:
Alexey Milovidov 2023-09-26 21:35:35 +03:00 committed by GitHub
commit d781ee3319
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 8 deletions

View File

@ -1096,22 +1096,25 @@ public:
return res != nullptr;
};
TypeIndex left_id = arg_then.type->getTypeId();
TypeIndex right_id = arg_else.type->getTypeId();
DataTypePtr left_type = arg_then.type;
DataTypePtr right_type = arg_else.type;
if (const auto * left_array = checkAndGetDataType<DataTypeArray>(arg_then.type.get()))
left_id = left_array->getNestedType()->getTypeId();
left_type = left_array->getNestedType();
if (const auto * right_array = checkAndGetDataType<DataTypeArray>(arg_else.type.get()))
right_id = right_array->getNestedType()->getTypeId();
right_type = right_array->getNestedType();
/// 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 (isNativeInteger(left_type) && isUInt64ThatCanBeInt64(right_type))
right_type = std::make_shared<DataTypeInt64>();
else if (isNativeInteger(right_type) && isUInt64ThatCanBeInt64(left_type))
left_type = std::make_shared<DataTypeInt64>();
TypeIndex left_id = left_type->getTypeId();
TypeIndex right_id = right_type->getTypeId();
if (!(callOnBasicTypes<true, true, true, false>(left_id, right_id, call)
|| (res = executeTyped<UUID, UUID>(cond_col, arguments, result_type, input_rows_count))

View File

@ -0,0 +1,24 @@
-9223372036854775808
9223372036854775806
-9223372036854775808
9223372036854775806
-9223372036854775808
9223372036854775806
-9223372036854775808
9223372036854775806
[2,65537,-9223372036854775808]
[9223372036854775806]
[2,65537,-9223372036854775808]
[9223372036854775806]
[2,65537,-9223372036854775808]
[9223372036854775806]
[2,65537,-9223372036854775808]
[9223372036854775806]
[[2,65537,-9223372036854775808]]
[[9223372036854775806]]
[[2,65537,-9223372036854775808]]
[[9223372036854775806]]
[[2,65537,-9223372036854775808]]
[[9223372036854775806]]
[[2,65537,-9223372036854775808]]
[[9223372036854775806]]

View File

@ -0,0 +1,13 @@
SELECT if(number % 2, 9223372036854775806, -9223372036854775808) AS res FROM numbers(2);
SELECT if(number % 2, materialize(9223372036854775806), -9223372036854775808) AS res FROM numbers(2);
SELECT if(number % 2, 9223372036854775806, materialize(-9223372036854775808)) AS res FROM numbers(2);
SELECT if(number % 2, materialize(9223372036854775806), materialize(-9223372036854775808)) AS res FROM numbers(2);
SELECT if(number % 2, [9223372036854775806], [2, 65537, -9223372036854775808]) AS res FROM numbers(2);
SELECT if(number % 2, materialize([9223372036854775806]), [2, 65537, -9223372036854775808]) AS res FROM numbers(2);
SELECT if(number % 2, [9223372036854775806], materialize([2, 65537, -9223372036854775808])) AS res FROM numbers(2);
SELECT if(number % 2, materialize([9223372036854775806]), materialize([2, 65537, -9223372036854775808])) AS res FROM numbers(2);
SELECT if(number % 2, [[9223372036854775806]], [[2, 65537, -9223372036854775808]]) AS res FROM numbers(2);
SELECT if(number % 2, materialize([[9223372036854775806]]), [[2, 65537, -9223372036854775808]]) AS res FROM numbers(2);
SELECT if(number % 2, [[9223372036854775806]], materialize([[2, 65537, -9223372036854775808]])) AS res FROM numbers(2);
SELECT if(number % 2, materialize([[9223372036854775806]]), materialize([[2, 65537, -9223372036854775808]])) AS res FROM numbers(2);