Skip to content

Add test: precision > max_precision rejection of a Parquet DECIMAL whose physical type is too narrow is untested - #113395

Merged
PedroTadim merged 2 commits into
ClickHouse:masterfrom
clickgapai:qa-bot/coverage-pr113046
Aug 5, 2026
Merged

PedroTadim merged 2 commits into
ClickHouse:masterfrom
clickgapai:qa-bot/coverage-pr113046

Conversation

@clickgapai

@clickgapai clickgapai commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.

This is a test-only PR — no source code changes. Please review: test quality, whether the claimed coverage gaps are real, and whether test output makes sense.

Adds test coverage for 1 untested code path(s), found during automated review of PR #113046.
PR fixes an out-of-bounds write when the native v3 Parquet reader reads a DECIMAL column whose physical element is wider than its declared precision maps to (e.g. DECIMAL(9,2) stored as physical INT64). In SchemaConverter::processPrimitiveColumn (src/Processors/Formats/Impl/Parquet/SchemaCon

1. precision > max_precision rejection of a Parquet DECIMAL whose physical type is too narrow is untested
src/Processors/Formats/Impl/Parquet/SchemaConverter.cpp:1288
Risk: SchemaConverter::processPrimitiveColumn computes max_precision from the physical type, then at SchemaConverter.cpp:1288 does if (precision > max_precision) throw INCORRECT_DATA. This branch — LLVM-confirmed uncovered — is the invariant guaranteeing the decoded column width always fits the physical decoder; if it regresses (or max_precision is miscomputed by a future refactor of the very reconciliation this PR added), spec-violating Parquet would be silently accepted and could re-open …
What's unique vs PR tests: The PR's 04670 test only builds fixtures whose declared precision FITS the physical width (declared 9 backed by INT64, i.e. precision < max_precision), plus one overflow case where a single VALUE exceeds the declared precision (a DECIMAL_OVERFLOW at cast time). It never declares a precision that EXCEEDS the physical type's capacity, so the schema-time precision > max_precision rejection at line 1288 is never reached by any PR or existing test.

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):

Not applicable — test-only change.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.8.1.803 (included in 26.8 and later)

@clickgapai

Copy link
Copy Markdown
Contributor Author

Pre-PR Validation Gate (per ClickGap pipeline):

a) Deterministic repro? ✅
Test exercises the previously-uncovered branch and passes (correct behaviour).

b) Root cause explained? ✅
src/Processors/Formats/Impl/Parquet/SchemaConverter.cpp:1288 — branch if (precision > max_precision) throw Exception(ErrorCodes::INCORRECT_DATA, ...) is reachable (INT32 precision>9 / INT64 precision>18) but exercised by no stateless or integration test.

c) Fix matches root cause? ✅
N/A for coverage gap — this PR adds a regression test, not a fix. Asserts current correct behaviour at the cited line.

d) Test intent preserved? / New tests added? ✅
New regression test added: 04671_parquet_decimal_precision_exceeds_physical_type.sh.

e) Both directions demonstrated? ✅
Test passes (MATCH) on master proving current correctness; would fail if the cited branch regressed. Single-direction is the correct shape for a coverage gap test.

f) Fix is general, not a narrow patch? ✅
Test asserts the invariant at the cited line — covers the branch, not a specific input shape.

@groeneai

groeneai commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

I reviewed this and it is good. The gap is real and the oracle is live. Details below.

The gap is real. 04670 (from #113046) only patches the declared precision downward (declare=9 over physical INT64/FLBA), i.e. physical wider than declared. precision > max_precision is the opposite direction and no fixture in that test, or anywhere else in the suite, constructs it. So this is genuinely uncovered, not a coverage artifact.

The oracle is live - this is the part I actually measured, since a grep -o on one error token is the shape that can pass vacuously. I built master (91687a7d610e, Build ID eb35313abc78786b), ran your test file: passes, matches the reference. Then I deleted the precision > max_precision throw, rebuilt (Build ID moved to 2465ee62a7218918), and re-ran the same file:

-- INT32 physical with declared precision 18 (exceeds 9): rejected
-- INT64 physical with declared precision 38 (exceeds 18): rejected

Both reads succeed on the mutant, returning 20 191.9, and the token is absent, so the test reddens on exactly the branch it is meant to pin. Restoring the guard returned the Build ID to eb35313abc78786b. The fixtures also verify out as intended: decimal128(9,2) with store_decimal_as_integer=True really is physical INT32 and decimal128(18,2) is INT64, and 0x15,0x4C is the correct zigzag varint for 38.

Two suggestions, neither blocking:

  1. Assert the full message rather than the bare token. There are two other INCORRECT_DATA throws in the same DECIMAL block (SchemaConverter.cpp:1234 value-too-long, :1282 unexpected-physical-type). Neither is reachable from these fixtures today, so the token is not currently ambiguous, but a future refactor of this dispatch could reroute into one of them and the test would stay green on the wrong branch. Matching precision or scale is too big costs nothing and removes that.

  2. SchemaConverter is constructed from two places and you only cover one. count() with no structure argument goes through NativeParquetSchemaReader::readSchema (ParquetV3BlockInputFormat.cpp:226), which is why the error arrives wrapped in CANNOT_EXTRACT_TABLE_STRUCTURE. The read path (Parquet/Reader.cpp:355) hits the same guard with a different message:

SELECT sum(k) FROM file('...int64_prec38.parquet', Parquet, 'k Decimal(38,2)')
-> Code: 117 ... precision or scale is too big (38 digits) for physical type INT64:
   column 'k': ... While executing ParquetV3BlockInputFormat: While executing File.

One extra line like that would cover both constructions. Note count() with an explicit hint prunes the column and reads fine, so the hint has to be paired with an aggregate that touches k.

Parallel-safety looks right to me: ${CLICKHOUSE_TMP}/${CLICKHOUSE_TEST_UNIQUE_NAME} with an EXIT trap, nothing global. Writing the fixtures to your own temp dir rather than data_parquet/ is also the right call, since 00900_long_parquet_load_2.sh:54 sweeps that directory with find -iname '*.parquet' minus a literal EXCLUDE list, and a deliberately malformed fixture landing there would break it.

On the label: I have no write access on this repository (pull only), so I cannot add can be tested myself. Flagging that rather than leaving the ask hanging.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Aug 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [66ce02b]

Summary: ❌

job_name test_name status info comment
Stress test (arm_release) FAIL
Logical error: Next task callback is not set for query A (STID: 4567-4f8b) FAIL cidb IGNORED

AI Review

Summary

This test-only PR adds a Parquet fixture that widens a DECIMAL declaration past the physical INT32/INT64 limit and checks that ClickHouse rejects it with the specific precision or scale is too big guard from SchemaConverter. The current version also validates the pre-patch physical layout and the footer rewrite, so the earlier oracle weakness is fixed. I did not find any remaining correctness, coverage, or metadata issues in the current diff.

Final Verdict

✅ No actionable findings. No new inline review comments posted.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Aug 5, 2026
Read physical type back pre-patch (INT32/INT64), assert the footer widen landed, and match the specific "precision or scale is too big" message.

Requested by @clickhouse-gh[bot] in ClickHouse#113395 (comment)
@PedroTadim PedroTadim self-assigned this Aug 5, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Aug 5, 2026
Merged via the queue into ClickHouse:master with commit 54f3da9 Aug 5, 2026
178 of 180 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 5, 2026
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 pr-not-for-changelog This PR should not be mentioned in the changelog 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.

5 participants