Skip to content

Commit

Permalink
Merge pull request #60727 from ClickHouse/allow-enums-and-strings
Browse files Browse the repository at this point in the history
Make String a supertype for strings and enums
  • Loading branch information
alexey-milovidov committed Mar 4, 2024
2 parents ce6dec6 + fe50f5d commit 0d3271e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/DataTypes/getLeastSupertype.cpp
Expand Up @@ -474,16 +474,18 @@ DataTypePtr getLeastSupertype(const DataTypes & types)
type_ids.insert(type->getTypeId());

/// For String and FixedString, or for different FixedStrings, the common type is String.
/// No other types are compatible with Strings. TODO Enums?
/// If there are Enums and any type of Strings, the common type is String.
/// No other types are compatible with Strings.
{
size_t have_string = type_ids.count(TypeIndex::String);
size_t have_fixed_string = type_ids.count(TypeIndex::FixedString);
size_t have_enums = type_ids.count(TypeIndex::Enum8) + type_ids.count(TypeIndex::Enum16);

if (have_string || have_fixed_string)
{
bool all_strings = type_ids.size() == (have_string + have_fixed_string);
if (!all_strings)
return throwOrReturn<on_error>(types, "because some of them are String/FixedString and some of them are not", ErrorCodes::NO_COMMON_TYPE);
bool all_compatible_with_string = type_ids.size() == (have_string + have_fixed_string + have_enums);
if (!all_compatible_with_string)
return throwOrReturn<on_error>(types, "because some of them are String/FixedString/Enum and some of them are not", ErrorCodes::NO_COMMON_TYPE);

return std::make_shared<DataTypeString>();
}
Expand Down
@@ -0,0 +1 @@
['Hello','Goodbye','test']
@@ -0,0 +1 @@
WITH 'Hello'::Enum8('Hello', 'World') AS enum1, 'test'::Enum8('test', 'best') AS enum2 SELECT [enum1, 'Goodbye', enum2];

0 comments on commit 0d3271e

Please sign in to comment.