From 237a81ff8c9ae0f0ef90e05a09e4b36a1a38487d Mon Sep 17 00:00:00 2001 From: avogar Date: Mon, 11 Nov 2024 21:11:31 +0000 Subject: [PATCH] Slightly better JSON type parsing --- src/Formats/JSONExtractTree.cpp | 3 ++- .../03273_better_json_subcolumns_parsing.reference | 3 +++ .../0_stateless/03273_better_json_subcolumns_parsing.sql | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/queries/0_stateless/03273_better_json_subcolumns_parsing.reference create mode 100644 tests/queries/0_stateless/03273_better_json_subcolumns_parsing.sql diff --git a/src/Formats/JSONExtractTree.cpp b/src/Formats/JSONExtractTree.cpp index ae6051823b7..fb078fdb352 100644 --- a/src/Formats/JSONExtractTree.cpp +++ b/src/Formats/JSONExtractTree.cpp @@ -1442,7 +1442,8 @@ public: auto shared_variant_discr = column_dynamic.getSharedVariantDiscriminator(); auto insert_settings_with_no_type_conversion = insert_settings; insert_settings_with_no_type_conversion.allow_type_conversion = false; - for (size_t i = 0; i != variant_info.variant_names.size(); ++i) + auto order = SerializationVariant::getVariantsDeserializeTextOrder(assert_cast(*variant_info.variant_type).getVariants()); + for (size_t i : order) { if (i != shared_variant_discr) { diff --git a/tests/queries/0_stateless/03273_better_json_subcolumns_parsing.reference b/tests/queries/0_stateless/03273_better_json_subcolumns_parsing.reference new file mode 100644 index 00000000000..ce734e472f4 --- /dev/null +++ b/tests/queries/0_stateless/03273_better_json_subcolumns_parsing.reference @@ -0,0 +1,3 @@ +Int64 42 +Float64 42.42 +Int64 43 diff --git a/tests/queries/0_stateless/03273_better_json_subcolumns_parsing.sql b/tests/queries/0_stateless/03273_better_json_subcolumns_parsing.sql new file mode 100644 index 00000000000..0f6b51d8987 --- /dev/null +++ b/tests/queries/0_stateless/03273_better_json_subcolumns_parsing.sql @@ -0,0 +1,8 @@ +set allow_experimental_json_type = 1; +drop table if exists test; +create table test (json JSON) engine=Memory; +insert into test format JSONAsObject {"a" : 42}, {"a" : 42.42}, {"a" : 43}; + +select dynamicType(json.a), json.a from test; +drop table test; +