diff --git a/src/DataTypes/Serializations/SerializationTuple.cpp b/src/DataTypes/Serializations/SerializationTuple.cpp index ec92ceb9110..62b05b1079c 100644 --- a/src/DataTypes/Serializations/SerializationTuple.cpp +++ b/src/DataTypes/Serializations/SerializationTuple.cpp @@ -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); diff --git a/tests/queries/0_stateless/03284_json_object_as_tuple_duplicate_keys.reference b/tests/queries/0_stateless/03284_json_object_as_tuple_duplicate_keys.reference new file mode 100644 index 00000000000..4fe371d5dfc --- /dev/null +++ b/tests/queries/0_stateless/03284_json_object_as_tuple_duplicate_keys.reference @@ -0,0 +1,2 @@ +a Tuple(\n b Nullable(String)) +a Tuple(\n b Nullable(String)) diff --git a/tests/queries/0_stateless/03284_json_object_as_tuple_duplicate_keys.sql b/tests/queries/0_stateless/03284_json_object_as_tuple_duplicate_keys.sql new file mode 100644 index 00000000000..a60b8c9488b --- /dev/null +++ b/tests/queries/0_stateless/03284_json_object_as_tuple_duplicate_keys.sql @@ -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} +