Skip to content

Infer each Form field independently - #132172

Merged
PedroTadim merged 3 commits into
ClickHouse:masterfrom
hsusul:fix/form-schema-inference-stale-value
Nov 18, 2026
Merged

PedroTadim merged 3 commits into
ClickHouse:masterfrom
hsusul:fix/form-schema-inference-stale-value

Conversation

@hsusul

@hsusul hsusul commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #132102

Why

readRowAndGetNamesAndDataTypesForFormRow declared its value and decoded_value buffers outside the field loop, and readStringUntilAmpersand appends to its argument rather than assigning to it. So every field carried all the previous fields' text into it, and a field's inferred type depended on the fields before it: in format(Form, 'n=1&a=x&m=2'), n was inferred as UInt8 but m as String, because by then the buffer held 1a=x2.

What changed

  • FormRowInputFormat.cpp: the two buffers are declared inside the loop, so each field is decoded and inferred from its own text only.

Scope

  • Only the type-inference path for the Form format. Nothing is used after the loop, so the narrower scope changes no other behaviour.
  • + handling is unchanged: Poco::URI::decode only maps + to a space after a ?, so a body field keeps a literal +.

Verification

  • 05580_form_schema_inference_independent_fields.sql fails on master (26.11.1.2276) on three of its seven lines: the fields after the first came back quoted, i.e. inferred as String, instead of as their own type.
  • The reference for the multi-field cases is what master already produces for each field on its own, where there is nothing to accumulate, so it records the uncontaminated inference rather than a guess.
  • 02984_form_format is updated in two places, because removing the contamination lets col3=%5B1%2C%202%2C%203%5D infer as Array(Nullable(Int64)) — the type master already infers for that field on its own — and so renders as [1,2,3]. Every other field in that test's large body was checked one by one and renders identically before and after.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixes schema inference for the Form format, where the type inferred for a field depended on the fields before it. For example, in format(Form, 'n=1&a=x&m=2') the field m was inferred as String instead of a number.


Workflow [PR]
Sync PR [sync-upstream/pr/132172]

Version info

  • Merged into: 26.11.1.2687-master (included in 26.11 and later)

readRowAndGetNamesAndDataTypesForFormRow declared its value buffers outside the
field loop, and readStringUntilAmpersand appends to its argument, so every field
carried the previous fields into it and its inferred type depended on the fields
before it.
@clickhouse-gh clickhouse-gh Bot added comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). external Author is not a member of the ClickHouse organization labels Nov 17, 2026
@PedroTadim PedroTadim self-assigned this Nov 17, 2026
@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Nov 17, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7fc8ab9]

Summary: ✅


AI Review

Summary

Reviewed #132172 at 7fc8ab9b01558aa674ec650678dec22823041049. Moving the buffers inside the field loop fixes cross-field contamination in Form schema inference. The regression cases cover field order, intervening strings, numeric values, and percent decoding. No blockers or major findings; one explanatory comment needs a factual correction.

Findings

💡 Nits

  • src/Processors/Formats/Impl/FormRowInputFormat.cpp:140: The comment and PR explanation attribute accumulation to readStringUntilAmpersand, but that function clears its destination. Poco::URI::decode appends to decoded_value, which is the buffer causing contamination. Describe that behavior instead; the implementation fixes it correctly.
Missing context / blind spots
  • ⚠️ Local tests were not run because no built binary is available. Both affected tests passed repeatedly in the targeted ASan/UBSan report for the preceding revision. The latest revision's full CI is still in progress; its completed stateless jobs would close this execution gap.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 17, 2026
Fields that are now correctly inferred as numbers trigger the Vertical
large-number tip, which the reference did not yet reflect.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 7fc8ab9b0 with master 58f152aee (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 10 s compile time in total, 7 of them have a recent master baseline.

Job report

@PedroTadim
PedroTadim added this pull request to the merge queue Nov 18, 2026
Merged via the queue into ClickHouse:master with commit 38486a9 Nov 18, 2026
193 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 18, 2026
alexey-milovidov added a commit that referenced this pull request Nov 19, 2026
…ort_nested_json`

The test relied on `Form` schema inference appending each field to the previous ones, which
made `x=1.5` inferred as a string. #132172 fixed
that on master, so `1.5` is now inferred as a number and is a value-level error, not a structure
mismatch. Use `x=abc`, which is inferred as a string, to keep testing the intent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). external Author is not a member of the ClickHouse organization pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Form format schema inference makes every field after a String field String

3 participants