Merge pull request #73043 from Avogar/fix-json-parsing-format-settings

Use default format settings during JSON parsing to avoid broken deserialization
This commit is contained in:
Pavel Kruglov 2024-12-11 11:07:11 +00:00 committed by GitHub
commit 33b8948a5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 1 deletions

View File

@ -1780,7 +1780,9 @@ private:
paths_and_values_for_shared_data.emplace_back(current_path, ""); paths_and_values_for_shared_data.emplace_back(current_path, "");
WriteBufferFromString buf(paths_and_values_for_shared_data.back().second); WriteBufferFromString buf(paths_and_values_for_shared_data.back().second);
dynamic_serialization->serializeBinary(*tmp_dynamic_column, 0, buf, format_settings); /// Use default format settings for binary serialization. Non-default settings may change
/// the binary representation of the values and break the future deserialization.
dynamic_serialization->serializeBinary(*tmp_dynamic_column, 0, buf, getDefaultFormatSettings());
} }
return true; return true;
@ -1807,6 +1809,12 @@ private:
return false; return false;
} }
const FormatSettings & getDefaultFormatSettings() const
{
static const FormatSettings settings;
return settings;
}
std::unordered_map<String, std::unique_ptr<JSONExtractTreeNode<JSONParser>>> typed_path_nodes; std::unordered_map<String, std::unique_ptr<JSONExtractTreeNode<JSONParser>>> typed_path_nodes;
std::unordered_set<String> paths_to_skip; std::unordered_set<String> paths_to_skip;
std::vector<String> sorted_paths_to_skip; std::vector<String> sorted_paths_to_skip;

View File

@ -0,0 +1,8 @@
set enable_json_type=1;
set output_format_binary_write_json_as_string=1;
drop table if exists test;
create table test (json JSON(max_dynamic_paths=0)) engine=Memory;
insert into test format JSONAsObject {"a" : [{"b" : 42}]};
select * from test;