Skip to content

Add test: illegal-type additional_table_filters rejected by FilterTransform::transformHeader - #109856

Merged
fm4v merged 2 commits into
ClickHouse:masterfrom
clickgapai:qa-bot/coverage-pr106438
Jul 20, 2026
Merged

fm4v merged 2 commits into
ClickHouse:masterfrom
clickgapai:qa-bot/coverage-pr106438

Conversation

@clickgapai

@clickgapai clickgapai commented Jul 9, 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 the illegal-type additional_table_filters rejection branch, found during automated review of PR #106438.

Illegal-type additional_table_filters rejected by FilterTransform::transformHeader
src/Processors/Transforms/FilterTransform.cpp:58
Risk: additional_table_filters injects a filter that bypasses the analyzer's ValidationUtils::validateFilters. The materialized FilterStep is type-checked by FilterTransform::transformHeader at plan-build time (via FilterStep::updateOutputHeader, FilterStep.cpp:253) — that is the only guard reached for this feature. If the canUseType check regresses, a non-boolean additional_table_filters column would be silently accepted, leading to a deeper LOGICAL_ERROR or wrong results instead of a clean user error.
What's unique vs PR tests: The PR's 04305_..._2.sql exercises additional_table_filters only with the native Int32 column c0, which passes the type check and never enters the throw branch. This test exercises the REJECTION (throw) branch with String/Decimal filter expressions, including under optimize_use_projections = 1 to confirm that projection settings do not open a bypass around the FilterStep type check.

Scope note: an earlier draft also claimed coverage of the projectionsCommon::findInOutputs throw (projectionsCommon.cpp:153-156). That branch is not reachable via additional_table_filters: the FilterStep constructor computes its output header with transformHeader during planning and throws before projection optimization (QueryDAG::build / findInOutputs) ever runs. findInOutputs only guards row-level-filter / PREWHERE DAGs attached directly to ReadFromMergeTree. Scope narrowed to the reachable transformHeader guard.

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.7.1.1209 (included in 26.7 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/QueryPlan/Optimizations/projectionsCommon.cpp:154 if (!node->result_type->canBeUsedInBooleanContext()) throw at 155-157 and src/Processors/Transforms/FilterTransform.cpp:58 if (!canUseType(filter_type)) throw at 59-61 — taken (throw) branch untested for additional_table_filters.

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: 04509_additional_table_filters_illegal_type.sql.

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.

@fm4v fm4v added the can be tested Allows running workflows for external contributors label Jul 9, 2026
@fm4v fm4v self-assigned this Jul 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b7664fe]

Summary: ❌

job_name test_name status info comment
Stress test (arm_debug) FAIL
Logical error: Cannot finalize buffer after cancellation. (STID: 2341-2d32) FAIL cidb IGNORED

AI Review

Summary

This PR adds a new stateless test for illegal-type additional_table_filters expressions. The SQL now correctly documents that the rejection happens in FilterTransform::transformHeader during FilterStep construction, but the PR still overclaims coverage for projectionsCommon::findInOutputs, which this test never reaches.

Findings

⚠️ Majors

  • [tests/queries/0_stateless/04509_additional_table_filters_illegal_type.sql:20-25] The PR contract still promises coverage for the projectionsCommon::findInOutputs rejection branch, but the updated test itself states that the aggregate case is rejected earlier in FilterTransform::transformHeader. Either add a focused test that actually reaches QueryDAG::build/findInOutputs, or narrow the PR title/body to FilterTransform::transformHeader only.
Final Verdict

Status: ⚠️ Request changes

  • Either add real coverage for projectionsCommon::findInOutputs, or update the PR title/body so it no longer claims that coverage.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jul 9, 2026
The count() case is rejected at FilterStep construction (FilterTransform::transformHeader), not projectionsCommon::findInOutputs; reword header and case comments to state actual scope.

Requested by @clickhouse-gh[bot] in ClickHouse#109856 (comment)

-- Aggregate with projections + implicit projections enabled: the filter is still rejected
-- during FilterStep construction (FilterTransform::transformHeader), before projection
-- optimization runs, so this does NOT reach projectionsCommon::findInOutputs -- it guards

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This updated comment is correct: this count() case is rejected during FilterStep construction, before projectionsCommon::findInOutputs ever runs.

That means the PR still does not provide the findInOutputs coverage promised by the title/body; it only adds FilterTransform::transformHeader coverage. Please either add a smaller test that actually exercises QueryDAG::build/findInOutputs, or narrow the PR title/body so the contract is just the transformHeader rejection branch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified and narrowed the contract to the reachable guard.

The analysis holds: for additional_table_filters the FilterStep computes its output header via FilterTransform::transformHeader at plan-build time (FilterStep::updateOutputHeader, FilterStep.cpp:253), which throws ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER before optimizations run QueryDAG::build / findInOutputs. So the findInOutputs throw (projectionsCommon.cpp:153-156) is unreachable through this feature — it only guards row-level-filter / PREWHERE DAGs attached directly to ReadFromMergeTree (projectionsCommon.cpp:178-194), not FilterStep-wrapped filters. A "smaller test exercising findInOutputs" via additional_table_filters isn't constructible, so I took the narrowing option rather than fabricate one.

Changes (PR metadata only, no source/test diff):

  • Title: → Add test: illegal-type additional_table_filters rejected by FilterTransform::transformHeader (dropped the findInOutputs claim).
  • Body: dropped the findInOutputs coverage claim; risk/uniqueness sections now cite only FilterTransform.cpp:58 and FilterStep.cpp:253, plus a scope note explaining why findInOutputs is unreachable via this path.

The test itself is unchanged — its comments (lines 20-25) already state the count()+projections case is rejected in transformHeader, not findInOutputs; that case stays as a regression guard that projection settings don't bypass the type check.

Verification: ran all four statements against the local server on :19000 — the three illegal-type cases (toString(c0), toDecimal64(c0,2), and count()+optimize_use_projections=1) each raise ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER; the native c0 filter returns 10\n20, matching .reference.


ClickGapAI · Confidence: HIGH

@clickgapai clickgapai changed the title Add test: Illegal-type additional_table_filters rejection branch in findInOutputs/transformHeader is untested Add test: illegal-type additional_table_filters rejected by FilterTransform::transformHeader Jul 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.07% 86.08% +0.02%
Functions 91.51% 91.51% +0.00%
Branches 78.59% 78.63% +0.04%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 126 line(s), 10 function(s) across 41 file(s) · Details

Top files
  • src/Functions/FunctionShowCertificate.cpp: 36 line(s), 2 function(s)
  • src/Processors/Transforms/BufferedShardByHashTransform.cpp: 8 line(s)
  • src/Storages/ObjectStorageQueue/ObjectStorageQueueSource.cpp: 8 line(s)
  • src/Processors/QueryPlan/resolveStorages.cpp: 5 line(s)
  • src/DataTypes/Serializations/SerializationFixedString.cpp: 4 line(s), 1 function(s)

Full report

@fm4v
fm4v added this pull request to the merge queue Jul 20, 2026
Merged via the queue into ClickHouse:master with commit 47ba24e Jul 20, 2026
172 of 174 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 20, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The count() case is rejected at FilterStep construction (FilterTransform::transformHeader), not projectionsCommon::findInOutputs; reword header and case comments to state actual scope.

Requested by @clickhouse-gh[bot] in ClickHouse#109856 (comment)
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…pr106438

Add test: illegal-type additional_table_filters rejected by FilterTransform::transformHeader
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.

3 participants