From 237a81ff8c9ae0f0ef90e05a09e4b36a1a38487d Mon Sep 17 00:00:00 2001 From: avogar Date: Mon, 11 Nov 2024 21:11:31 +0000 Subject: [PATCH 1/2] 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; + From 3dae5def485d0bdf9b0bdb3444db5eee7358890d Mon Sep 17 00:00:00 2001 From: Pavel Kruglov <48961922+Avogar@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:25:17 +0100 Subject: [PATCH 2/2] Update 01825_new_type_json_12.reference --- tests/queries/0_stateless/01825_new_type_json_12.reference | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/queries/0_stateless/01825_new_type_json_12.reference b/tests/queries/0_stateless/01825_new_type_json_12.reference index 10770498c4a..36f014f0178 100644 --- a/tests/queries/0_stateless/01825_new_type_json_12.reference +++ b/tests/queries/0_stateless/01825_new_type_json_12.reference @@ -9,5 +9,5 @@ ('key_6','String') ('key_7','Float64') ('key_7','Int64') -{"obj":{"id":"1","key_0":[{"key_1":[{"key_3":[{"key_4":"1048576","key_5":0.0001048576,"key_6":25.5,"key_7":"1025"},{"key_6":"","key_7":"2"}]}]},{},{"key_1":[{"key_3":[{"key_5":-1,"key_6":"aqbjfiruu","key_7":-922337203685477600},{"key_4":"","key_6":"","key_7":65537}]},{"key_3":[{"key_4":"ghdqyeiom","key_5":1048575,"key_7":21474836.48}]}]}]}} +{"obj":{"id":"1","key_0":[{"key_1":[{"key_3":[{"key_4":"1048576","key_5":0.0001048576,"key_6":25.5,"key_7":"1025"},{"key_6":"","key_7":"2"}]}]},{},{"key_1":[{"key_3":[{"key_5":-1,"key_6":"aqbjfiruu","key_7":-922337203685477600},{"key_4":"","key_6":"","key_7":"65537"}]},{"key_3":[{"key_4":"ghdqyeiom","key_5":1048575,"key_7":21474836.48}]}]}]}} [[[1048576,NULL]],[],[[NULL,''],['ghdqyeiom']]] [[[0.0001048576,NULL]],[],[[-1,NULL],[1048575]]] [[[25.5,'']],[],[['aqbjfiruu',''],[NULL]]] [[[1025,2]],[],[[-922337203685477600,65537],[21474836.48]]]