Check for duplicate JSON keys during Tuple parsing

This commit is contained in:
avogar 2024-12-10 16:52:07 +00:00
parent e83921d2cb
commit 1d6c3629c6
3 changed files with 14 additions and 0 deletions

View File

@ -400,6 +400,9 @@ ReturnType SerializationTuple::deserializeTupleJSONImpl(IColumn & column, ReadBu
return false;
}
if (seen_elements[element_pos])
throw Exception(ErrorCodes::INCORRECT_DATA, "JSON object contains duplicate key '{}'", name);
seen_elements[element_pos] = 1;
auto & element_column = extractElementColumn(column, element_pos);

View File

@ -0,0 +1,2 @@
a Tuple(\n b Nullable(String))
a Tuple(\n b Nullable(String))

View File

@ -0,0 +1,9 @@
select * from format(JSONEachRow, 'a Tuple(b UInt32)', '{"a" : {"b" : 1, "b" : 2}}'); -- {serverError INCORRECT_DATA}
select * from format(JSONEachRow, '{"a" : {"b" : 1, "b" : 2}}'); -- {serverError INCORRECT_DATA}
select * from format(JSONEachRow, '{"a" : {"b" : 1, "b" : 2, "b" : 3}, "c" : 42}'); -- {serverError INCORRECT_DATA}
set input_format_json_use_string_type_for_ambiguous_paths_in_named_tuples_inference_from_objects=1;
desc format(JSONEachRow, '{"a" : {"b" : 1, "b" : "Hello"}}');
select * from format(JSONEachRow, '{"a" : {"b" : 1, "b" : "Hello"}}'); -- {serverError INCORRECT_DATA}
desc format(JSONEachRow, '{"a" : {"b" : 1, "b" : {"c" : "Hello"}}}');
select * from format(JSONEachRow, '{"a" : {"b" : 1, "b" : {"c" : "Hello"}}}'); -- {serverError INCORRECT_DATA}