Merge pull request #67687 from Avogar/fix-variant-as-common-type

Fix variant as common type in if function with Tuples, Maps and incompatible integers
This commit is contained in:
Alexey Milovidov 2024-08-05 17:48:36 +00:00 committed by GitHub
commit c64f060496
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 39 additions and 0 deletions

View File

@ -1233,6 +1233,12 @@ public:
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column {} of first argument of function {}. "
"Must be ColumnUInt8 or ColumnConstUInt8.", arg_cond.column->getName(), getName());
/// If result is Variant, always use generic implementation.
/// Using typed implementations may lead to incorrect result column type when
/// resulting Variant is created by use_variant_when_no_common_type.
if (isVariant(result_type))
return executeGeneric(cond_col, arguments, input_rows_count, use_variant_when_no_common_type);
auto call = [&](const auto & types) -> bool
{
using Types = std::decay_t<decltype(types)>;

View File

@ -0,0 +1,8 @@
0 Variant(Int64, UInt64)
1 Variant(Int64, UInt64)
0 Variant(Int32, UInt64)
1 Variant(Int32, UInt64)
0 Variant(Int16, UInt64)
1 Variant(Int16, UInt64)
0 Variant(Int8, UInt64)
1 Variant(Int8, UInt64)

View File

@ -0,0 +1,8 @@
set use_variant_as_common_type = 1;
set allow_experimental_variant_type = 1;
SELECT if(number % 2, number::Int64, number::UInt64) as res, toTypeName(res) FROM numbers(2);
SELECT if(number % 2, number::Int32, number::UInt64) as res, toTypeName(res) FROM numbers(2);
SELECT if(number % 2, number::Int16, number::UInt64) as res, toTypeName(res) FROM numbers(2);
SELECT if(number % 2, number::Int8, number::UInt64) as res, toTypeName(res) FROM numbers(2);

View File

@ -0,0 +1,10 @@
('0') Variant(Tuple(String), Tuple(\n number UInt64))
(1) Variant(Tuple(String), Tuple(\n number UInt64))
('2') Variant(Tuple(String), Tuple(\n number UInt64))
(3) Variant(Tuple(String), Tuple(\n number UInt64))
('4') Variant(Tuple(String), Tuple(\n number UInt64))
{'0':'0'} Variant(Map(String, String), Map(UInt64, UInt64))
{1:1} Variant(Map(String, String), Map(UInt64, UInt64))
{'2':'2'} Variant(Map(String, String), Map(UInt64, UInt64))
{3:3} Variant(Map(String, String), Map(UInt64, UInt64))
{'4':'4'} Variant(Map(String, String), Map(UInt64, UInt64))

View File

@ -0,0 +1,7 @@
set use_variant_as_common_type = 1;
set allow_experimental_variant_type = 1;
SELECT if(number % 2, tuple(number), tuple(toString(number))) as res, toTypeName(res) FROM numbers(5);
SELECT if(number % 2, map(number, number), map(toString(number), toString(number))) as res, toTypeName(res) FROM numbers(5);