Merge pull request #71359 from ClickHouse/backport/24.8/71182

Backport #71182 to 24.8: Escape special symbols in files for JSON subcolumns
This commit is contained in:
robot-ch-test-poll3 2024-11-01 15:42:06 +01:00 committed by GitHub
commit f3d4236ce2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 3 deletions

View File

@ -162,7 +162,7 @@ String getNameForSubstreamPath(
String stream_name,
SubstreamIterator begin,
SubstreamIterator end,
bool escape_tuple_delimiter)
bool escape_for_file_name)
{
using Substream = ISerialization::Substream;
@ -187,7 +187,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;
@ -207,7 +207,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;