Merge pull request #71182 from Avogar/json-escape-file-names

Escape special symbols in files for JSON subcolumns
This commit is contained in:
Pavel Kruglov 2024-11-01 11:05:12 +00:00 committed by GitHub
commit 0c252de99a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 3 deletions

View File

@ -161,7 +161,7 @@ String getNameForSubstreamPath(
String stream_name,
SubstreamIterator begin,
SubstreamIterator end,
bool escape_tuple_delimiter)
bool escape_for_file_name)
{
using Substream = ISerialization::Substream;
@ -186,7 +186,7 @@ String getNameForSubstreamPath(
/// Because nested data may be represented not by Array of Tuple,
/// but by separate Array columns with names in a form of a.b,
/// and name is encoded as a whole.
if (it->type == Substream::TupleElement && escape_tuple_delimiter)
if (it->type == Substream::TupleElement && escape_for_file_name)
stream_name += escapeForFileName(substream_name);
else
stream_name += substream_name;
@ -206,7 +206,7 @@ String getNameForSubstreamPath(
else if (it->type == SubstreamType::ObjectSharedData)
stream_name += ".object_shared_data";
else if (it->type == SubstreamType::ObjectTypedPath || it->type == SubstreamType::ObjectDynamicPath)
stream_name += "." + it->object_path_name;
stream_name += "." + (escape_for_file_name ? escapeForFileName(it->object_path_name) : it->object_path_name);
}
return stream_name;

View File

@ -0,0 +1,3 @@
{"a-b-c":"43","a-b\\/c-d\\/e":"44","a\\/b\\/c":"42"}
42 43 44
42 43 44

View File

@ -0,0 +1,10 @@
set allow_experimental_json_type = 1;
drop table if exists test;
create table test (json JSON) engine=MergeTree order by tuple() settings min_rows_for_wide_part=0, min_bytes_for_wide_part=0;
insert into test format JSONAsObject {"a/b/c" : 42, "a-b-c" : 43, "a-b/c-d/e" : 44};
select * from test;
select json.`a/b/c`, json.`a-b-c`, json.`a-b/c-d/e` from test;
select json.`a/b/c`.:Int64, json.`a-b-c`.:Int64, json.`a-b/c-d/e`.:Int64 from test;
drop table test;