From 92a4f4a02a0b806d52453740e1cc085beff13ba3 Mon Sep 17 00:00:00 2001 From: avogar Date: Thu, 5 Sep 2024 13:16:43 +0000 Subject: [PATCH] Fix insertion of incomplete type into Dynamic during deserialization --- src/DataTypes/Serializations/SerializationDynamic.cpp | 4 +++- ...03231_dynamic_incomplete_type_insert_bug.reference | 5 +++++ .../03231_dynamic_incomplete_type_insert_bug.sql | 11 +++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/queries/0_stateless/03231_dynamic_incomplete_type_insert_bug.reference create mode 100644 tests/queries/0_stateless/03231_dynamic_incomplete_type_insert_bug.sql diff --git a/src/DataTypes/Serializations/SerializationDynamic.cpp b/src/DataTypes/Serializations/SerializationDynamic.cpp index 32964e17bce..98bfdffca53 100644 --- a/src/DataTypes/Serializations/SerializationDynamic.cpp +++ b/src/DataTypes/Serializations/SerializationDynamic.cpp @@ -591,12 +591,14 @@ static void deserializeTextImpl( return; } + /// We cannot insert value with incomplete type, insert it as String. variant_type = std::make_shared(); /// 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); diff --git a/tests/queries/0_stateless/03231_dynamic_incomplete_type_insert_bug.reference b/tests/queries/0_stateless/03231_dynamic_incomplete_type_insert_bug.reference new file mode 100644 index 00000000000..f368b0ad7f2 --- /dev/null +++ b/tests/queries/0_stateless/03231_dynamic_incomplete_type_insert_bug.reference @@ -0,0 +1,5 @@ +[] +[] +[[]] +[['saw']] +['had',1] diff --git a/tests/queries/0_stateless/03231_dynamic_incomplete_type_insert_bug.sql b/tests/queries/0_stateless/03231_dynamic_incomplete_type_insert_bug.sql new file mode 100644 index 00000000000..a6fc2e66480 --- /dev/null +++ b/tests/queries/0_stateless/03231_dynamic_incomplete_type_insert_bug.sql @@ -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; +