Repository navigation
Add input_format_skip_duplicated_fields to keep the first value of a field repeated in a row - #133483
Conversation
…repeated field A row with the same key twice was rejected by JSONEachRow (and the formats reading JSON objects the same way), BSONEachRow, TSKV and Form with "Duplicate field found", and by their schema inference with "Duplicate column name found while schema inference", with no way to accept it. The new setting (default false) makes each reader skip the value of a field already read in the current row with the skip primitive it uses for unknown fields (skipJSONField, skipBSONField, the NullOutput sink, Form's own value read), so the first value is kept, consistent with type_json_skip_duplicated_paths. Schema inference ignores a repeated name in IRowWithNamesSchemaReader::readSchema, the base of all five schema readers, so the type comes from the first value. The JSONEachRow fast path for input_format_json_ignore_unnecessary_fields skips keys after a complete row without a lookup and reports them as unknown when input_format_skip_unknown_fields = 0; with the new setting enabled and unknown fields not skipped, those keys take the normal lookup, so a trailing duplicate is skipped and an unknown field is still an error. TSKV keeps the column index at -1 for a skipped duplicate so its garbage-after-field cleanup cannot pop the kept value. The setting changes what schema inference returns, so it joins the schema cache key shared by row-based formats (like max_parser_depth); four tests that print the whole key gain the field. Closes ClickHouse#133468 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 4 findings; 1 full pass, no fix round needed).
Also checked, not changed: keys inside a named Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261122-043800 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261122-032100 |
|
Workflow [PR], commit [c8db5cd] Summary: ✅
AI ReviewSummaryAdds opt-in Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units811 translation units recompiled, 4668 s compile time in total, 811 of them have a recent master baseline. |
With input_format_skip_duplicated_fields, every schema reader still inferred the value of a repeated field, and only IRowWithNamesSchemaReader::readSchema dropped its name afterwards. So a value the row reader skips could fail inference: a BSON Regexp (no inferable type), or a JSONEachRow, TSKV or Form value nested deeper than max_parser_depth. Each schema reader now skips a repeated top-level field before inferring it, with the skip it uses when reading (skipJSONField, skipBSONField, the value already read for TSKV and Form), so readSchema no longer sees repeated names with the setting enabled. A JSONObjectEachRow field repeating the column set by format_json_object_each_row_column_for_object_name is skipped by the row reader, which fills that column first, but inference returned both names and failed with "column with this name already exists". readSchema now drops such a field and keeps the static String column. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With input_format_skip_duplicated_fields, the JSONObjectEachRow row reader
fills the format_json_object_each_row_column_for_object_name column first, so a
field of the same name inside the object is a repeated one and is skipped. Schema
inference still inferred its value and dropped the name only afterwards, so the
discarded value could fail inference: a type conflict between rows
(`{"r1":{"id":[1]},"r2":{"id":1}}`) or a value nested deeper than
max_parser_depth.
The JSON row inference helper now takes the name already read for the row and
skips such a field with skipJSONField, returning it with a null type. Returning
the name keeps a row made only of that field from looking empty, so
`{"user1":{"id":"user1"}}` still infers `id String` instead of failing with
EMPTY_DATA_PASSED; readSchema still drops the name and keeps the String column.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rors The "Duplicate field found while parsing <format> format" errors of JSONEachRow, TSKV, BSONEachRow and Form, and the "Duplicate column name found while schema inference" errors of the schema reader these formats share, now name the setting as the workaround, the same way the JSON type errors name type_json_skip_duplicated_paths. The header errors of the *WithNames formats and the Freeform schema inference error keep their text: the setting does not apply to them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
AI review of a later commit does not approve the PR, see the AI Review comment.
…e_case With `input_format_column_name_matching_mode = 'ignore_case'` the JSONEachRow and BSONEachRow row readers resolve `a` and `A` to the same column, so with `input_format_skip_duplicated_fields` the second one is a repeated field. Schema inference compared the raw names and kept both, and the reader then rejected the inferred schema with `Ambiguous field`. Inference now compares the lowercased names under `ignore_case`, in the JSON and BSON schema readers and for the JSONObjectEachRow object-name column. With `auto` and `match_case` both spellings stay columns, since the reader then matches each one exactly. TSKV and Form readers never fold names, so their inference is unchanged. The schema cache key now includes the matching mode. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #133468
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added the
input_format_skip_duplicated_fieldssetting (disabled by default). When it is enabled, a field that appears more than once in a row ofJSONEachRow(and the other formats that read JSON objects the same way, including nested fields read withinput_format_import_nested_json),BSONEachRow,TSKVorFormkeeps its first value instead of throwing theDuplicate field foundexception, and schema inference takes the type of such a field from its first value. Closes #133468.Description
A row with the same key twice was rejected by
JSONEachRow,BSONEachRow,TSKVandForm(Duplicate field found) and by their schema inference (Duplicate column name found while schema inference), with no setting to accept it. ForJSONEachRowthe result also depended on the key order: withinput_format_json_ignore_unnecessary_fields = 1, a duplicate after all columns were read was skipped without a lookup.With the new setting each of the four readers skips the value of a field already read in the current row with the skip function it uses for unknown fields, so the first value is kept, as with
type_json_skip_duplicated_paths. Each of the five schema readers skips a repeated field the same way before inferring its type, including aJSONObjectEachRowfield that repeats theformat_json_object_each_row_column_for_object_namecolumn. Withinput_format_column_name_matching_mode = 'ignore_case'theJSONEachRowandBSONEachRowschema readers, like their row readers, treat names that differ only in case as one field. Withinput_format_skip_unknown_fields = 0and the setting enabled,JSONEachRowlooks up the keys that follow a complete row, so a trailing duplicate is skipped and an unknown field is still an error. The setting and the matching mode join the schema cache key of row-based formats. With the setting disabled the behaviour is unchanged, and the errors above name the setting as a workaround.Not covered: duplicate names in
*WithNamesheaders,JSONColumns, and keys inside a namedTuplevalue.Validation:
05843_input_format_skip_duplicated_fieldscovers the cases of the issue, nested fields,JSONObjectEachRow, the three other formats, repeated values that inference cannot type (a BSON Regexp, a value deeper thanmax_parser_depth) and anINSERT;05844_input_format_skip_duplicated_fields_schema_cachechecks that a schema inferred with the setting is not reused without it or with another matching mode. Reverting any single hunk fails one of them, and 50 randomized runs pass.Workflow [PR]
Sync PR [sync-upstream/pr/133483]
Version info
26.12.1.298-master(included in26.12and later)