Skip to content

Add input_format_parquet_detect_variant_by_structure to the Parquet schema inference cache key - #125408

Open
groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:parquet-schema-cache-key-detect-variant
Open

groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:parquet-schema-cache-key-detect-variant

Conversation

@groeneai

@groeneai groeneai commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #124986
Related: #117106

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

The schema inference cache for Parquet now takes input_format_parquet_detect_variant_by_structure into account, so a query gets the Dynamic or Tuple type its own setting asks for instead of the type inferred by an earlier query on the same file.

Description

#117106 made Parquet schema inference read input_format_parquet_detect_variant_by_structure: an unannotated group with only metadata and value BYTE_ARRAY fields is inferred as Dynamic when it is 1 (the default) and as Tuple(value String, metadata String) when it is 0 (or compatibility below 26.10). The setting was not part of the Parquet key of the schema inference cache, so within one server or clickhouse-local process the first query decided the type for every later query on the same file:

DESC file('04928_variant_spark.parquet') SETTINGS input_format_parquet_detect_variant_by_structure = 1; -- v Dynamic
DESC file('04928_variant_spark.parquet') SETTINGS input_format_parquet_detect_variant_by_structure = 0; -- v Dynamic, expected Tuple

The reverse order returned Tuple twice. This PR appends the setting to the Parquet getter registered with registerAdditionalInfoForSchemaCacheGetter, next to the other inference-affecting Parquet settings (same approach as #113533). It is appended at the end of the key string, so existing additional_format_info probes keep matching.

The new test runs both orders in two clickhouse-local processes. It fails on master (Dynamic, Dynamic, Tuple, Tuple) and passes with the change (50 of 50 runs). The setting exists only on master (no release branch has it), hence Not for changelog.


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

… key

`input_format_parquet_detect_variant_by_structure` (added in ClickHouse#117106)
decides whether Parquet schema inference reads an unannotated
`{metadata, value}` BYTE_ARRAY group as `Dynamic` or as
`Tuple(value String, metadata String)`, but it was missing from the
Parquet getter registered with `registerAdditionalInfoForSchemaCacheGetter`.
Both values of the setting therefore shared one schema cache entry, and
within one server or clickhouse-local process the first query decided
the inferred type for every later query on the same source.

Append the setting at the end of the key string, so existing
`extract(additional_format_info, ...)` probes keep matching. Same class
of fix as ClickHouse#113533.

The new test runs both orders (1 then 0, 0 then 1) in two
clickhouse-local processes; on master it prints Dynamic/Dynamic and
Tuple/Tuple.

Closes ClickHouse#124986

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Oct 12, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding) plus my own cold review (2 nits).

# Sev Finding Verdict Evidence / action
1 ⚠️ The new test would pass if the schema cache were never populated or read (05366_...sh:12-18) DISAGREE Run with the unfixed binary, the test prints Dynamic, Dynamic, Tuple, Tuple and fails, which only happens if each second DESC reads the first one's cache entry.
2 💡 PR description said "randomized" runs, but clickhouse-local is not randomized AGREE, fixed Reworded in the PR description

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-8:20261012-121500

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. One clickhouse-local process, DESC file('04928_variant_spark.parquet', Parquet) with input_format_parquet_detect_variant_by_structure = 1 then = 0: master returns Dynamic twice; the reverse order returns Tuple twice.
b Root cause explained? Yes. Parquet inference reads detect_variant_by_structure (SchemaConverter.cpp:777) to pick Dynamic or Tuple, but the Parquet getter in ParquetV3BlockInputFormat.cpp that builds the schema cache key did not include it, so both values share one cache entry.
c Fix matches root cause? Yes. The setting is added to the cache key at the same allow-list as every other inference-affecting Parquet setting; no cache bypass, no guard.
d Test intent preserved / new tests added? Yes. New test 05366_parquet_variant_schema_inference_cache_key.sh; existing 04757_schema_inference_cache_key_settings* tests unchanged and green.
e Both directions demonstrated? Yes. Master binary: test FAILS (Dynamic, Dynamic, Tuple, Tuple, both orders wrong). Fixed binary: test passes, 50/50 runs.
f Fix is general across code paths? Yes. The one getter serves every engine that caches Parquet schemas (file, s3, url, hdfs, azureBlobStorage, *Cluster, object storage). Every other format setting the Parquet schema converter reads during inference is already in the key; no other code reads this setting.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. Boolean setting: both values and both query orders are tested. An explicit structure or column list bypasses inference and the cache.
h Backward compatible? (maintainer-approved exception only) Yes. The schema cache is in memory only; the key string gains one trailing field. No setting or default changes.
i Invariants and contracts preserved? Yes. "Every setting that can change the inferred type is part of the cache key" now holds for this setting; existing key fields keep their order and spelling.

Session id: cron:clickhouse-impl-slot-6:20261012-120300

@clickhouse-gh

clickhouse-gh Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4da6985]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_asan_ubsan, db disk, targeted) FAIL
test_storage_delta/test.py::test_writes_timestamp_ntz_annotation_nested FAIL cidb
Integration tests (arm_binary, distributed plan, targeted) FAIL
test_storage_delta/test.py::test_writes_timestamp_ntz_annotation_nested FAIL cidb
Integration tests (amd_tsan, targeted) FAIL
test_storage_delta/test.py::test_writes_timestamp_ntz_annotation_nested FAIL cidb
Integration tests (arm_binary, 1/4) FAIL
test_storage_delta/test.py::test_writes_timestamp_ntz_annotation_nested FAIL cidb
test_storage_delta/test_writes_interop.py::test_write_to_table_with_unsupported_writer_feature_is_rejected FAIL cidb

AI Review

Summary

This PR fixes a real Parquet schema-inference cache poisoning bug by adding input_format_parquet_detect_variant_by_structure to the Parquet schema-cache key in src/Processors/Formats/Impl/ParquetV3BlockInputFormat.cpp:659 and by adding a regression test that now ages a copied fixture so the second DESC actually reuses the cached entry in tests/queries/0_stateless/05366_parquet_variant_schema_inference_cache_key.sh:12. I did not find any remaining correctness, safety, or coverage issues in the current diff.

Final Verdict

✅ No new findings. The previously reported test-flakiness issue is fixed in the current code, so I resolved that review thread.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Oct 12, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-parquet-reader-v3 Issues related to the native Parquet reader. label Oct 12, 2026
`SchemaCache::tryGetImpl` drops an entry when the file's mtime is >= the
entry's registration second. The test read the checked-in fixture
directly, so it only exercised the cache when the checkout was at least a
second older than the first query: with a fresh or future mtime the
second `DESC` re-infers and the test goes green on a binary without the
fix. Copy the fixture to a unique name and age it with `touch -d`, like
the other schema-cache-key tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 4da6985

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Integration tests (amd_asan_ubsan, db disk, targeted), (amd_tsan, targeted), (arm_binary, 1/4), (arm_binary, distributed plan, targeted) / test_storage_delta/test.py::test_writes_timestamp_ntz_annotation_nested not from this PR (it only changes the Parquet schema cache key and adds a test): the Spark 4.0 runner image of #117198 broke this test on master. The tested tree predates the revert #125455 (external, merged)
Integration tests (arm_binary, 1/4) / test_storage_delta/test_writes_interop.py::test_write_to_table_with_unsupported_writer_feature_is_rejected same cause as the row above #125455 (external, merged)
Mergeable Check, PR praktika rollups of the rows above #125455 (external, merged)

CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261012-230010

@al13n321
al13n321 removed their request for review October 29, 2026 16:43

This branch has not been deployed

No deployments
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-parquet-reader-v3 Issues related to the native Parquet reader. groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parquet schema cache ignores input_format_parquet_detect_variant_by_structure

1 participant