Fix insertion of incomplete type into Dynamic during deserialization

This commit is contained in:
avogar 2024-09-05 13:16:43 +00:00
parent a7d0a5991e
commit 92a4f4a02a
3 changed files with 19 additions and 1 deletions

View File

@ -591,12 +591,14 @@ static void deserializeTextImpl(
return;
}
/// We cannot insert value with incomplete type, insert it as String.
variant_type = std::make_shared<DataTypeString>();
/// To be able to deserialize field as String with Quoted escaping rule, it should be quoted.
if (escaping_rule == FormatSettings::EscapingRule::Quoted && (field.size() < 2 || field.front() != '\'' || field.back() != '\''))
field = "'" + field + "'";
}
else if (dynamic_column.addNewVariant(variant_type, variant_type->getName()))
if (dynamic_column.addNewVariant(variant_type, variant_type->getName()))
{
auto discr = variant_info.variant_name_to_discriminator.at(variant_type->getName());
deserializeVariant(dynamic_column.getVariantColumn(), dynamic_column.getVariantSerialization(variant_type), discr, *field_buf, deserialize_variant);

View File

@ -0,0 +1,5 @@
[]
[]
[[]]
[['saw']]
['had',1]

View File

@ -0,0 +1,11 @@
SET allow_experimental_dynamic_type = 1;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (c0 Array(Dynamic)) ENGINE = MergeTree() ORDER BY tuple();
INSERT INTO t1 (c0) VALUES ([]);
INSERT INTO t1 (c0) VALUES ([[]]), (['had', 1]);
INSERT INTO t1 (c0) VALUES ([['saw']]);
INSERT INTO t1 (c0) VALUES ([]);
OPTIMIZE TABLE t1 final;
SELECT * FROM t1 ORDER BY ALL;
DROP TABLE t1;