mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-15 12:14:18 +00:00
Merge pull request #71182 from Avogar/json-escape-file-names
Escape special symbols in files for JSON subcolumns
This commit is contained in:
commit
0c252de99a
@ -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;
|
||||
|
@ -0,0 +1,3 @@
|
||||
{"a-b-c":"43","a-b\\/c-d\\/e":"44","a\\/b\\/c":"42"}
|
||||
42 43 44
|
||||
42 43 44
|
10
tests/queries/0_stateless/03257_json_escape_file_names.sql
Normal file
10
tests/queries/0_stateless/03257_json_escape_file_names.sql
Normal 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;
|
||||
|
Loading…
Reference in New Issue
Block a user