mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-12 17:32:32 +00:00
Merge pull request #72454 from Avogar/fix-empty-variant
Don't allow creating empty Variant
This commit is contained in:
commit
03bc631cf2
@ -43,6 +43,9 @@ DataTypeVariant::DataTypeVariant(const DataTypes & variants_)
|
||||
for (const auto & [_, type] : name_to_type)
|
||||
variants.push_back(type);
|
||||
|
||||
if (variants.empty())
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Variant type should have at least one nested type");
|
||||
|
||||
if (variants.size() > ColumnVariant::MAX_NESTED_COLUMNS)
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Variant type with more than {} nested types is not allowed", ColumnVariant::MAX_NESTED_COLUMNS);
|
||||
}
|
||||
|
@ -4881,6 +4881,14 @@ private:
|
||||
if (const auto * variant_type = typeid_cast<const DataTypeVariant *>(from_type.get()))
|
||||
return createVariantToDynamicWrapper(*variant_type, dynamic_type);
|
||||
|
||||
if (from_type->onlyNull())
|
||||
return [](ColumnsWithTypeAndName &, const DataTypePtr & result_type, const ColumnNullable *, size_t input_rows_count) -> ColumnPtr
|
||||
{
|
||||
auto result = result_type->createColumn();
|
||||
result->insertManyDefaults(input_rows_count);
|
||||
return result;
|
||||
};
|
||||
|
||||
if (context && context->getSettingsRef()[Setting::cast_string_to_dynamic_use_inference] && isStringOrFixedString(removeNullable(removeLowCardinality(from_type))))
|
||||
return createStringToDynamicThroughParsingWrapper();
|
||||
|
||||
|
3
tests/queries/0_stateless/03276_empty_variant_type.sql
Normal file
3
tests/queries/0_stateless/03276_empty_variant_type.sql
Normal file
@ -0,0 +1,3 @@
|
||||
set allow_experimental_variant_type=1;
|
||||
create table test (v Variant()) engine=Variant(); -- {serverError BAD_ARGUMENTS}
|
||||
|
Loading…
Reference in New Issue
Block a user