Skip to content

Add test: dictGetOrDefault constant NULL key: default-mask exemption untested - #121233

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
clickgapai:qa-bot/coverage-pr120674
Sep 28, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
clickgapai:qa-bot/coverage-pr120674

Conversation

@clickgapai

@clickgapai clickgapai commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Test-only PR. Review: are the gaps real, is the test right.

Adds test coverage for 1 untested code path, found during automated review of PR #120674.
That PR: (1) FunctionCast::prepareRemoveNullable stops handing a text source a NULL-on-error parser when cast_type == CastType::accurate and the target is Nullable, and filters out rows the source marked NULL before converting (filter + expand, plus an all-NULL fast path and an identity-conversion …

1. dictGetOrDefault constant NULL key: default-mask exemption untested
src/Functions/FunctionsExternalDictionaries.h:704, src/Functions/FunctionsExternalDictionaries.h:707
Risk: FunctionDictGetNoType::executeImpl keeps the key column as ColumnConst(ColumnNullable) (a function only materializes const arguments when all of them are const — IFunction.cpp:139-151), so checkAndGetColumn<ColumnNullable> returns nullptr and only the isNullAt(0) arm can clear the …
Unique vs PR tests: 05232_accurate_cast_nullable_callers.sql's dictGetOrDefault, NULL key section reads the key from nkeys_05232, i.e. a materialized ColumnNullable, which takes the loop at :696-703. No test anywhere passes a constant NULL key, which is the else if at :704 and the std::fill at :707. The …
Try it on ClickHouse Fiddle

cc @groeneai (author of #120674), @alexey-milovidov (merged/approved #120674) — could you take a look, and add the can be tested label if this looks good?

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)

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

Version info

  • Merged into: 26.10.1.890-master (included in 26.10 and later)

@clickgapai

Copy link
Copy Markdown
Contributor Author
Pre-PR validation: 6/6 ✅

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

b) Root cause explained? ✅
src/Functions/FunctionsExternalDictionaries.h:704 — else if (nullable_key_column && nullable_key_column->isNullAt(0)), whose body at :707 (std::fill(default_mask.begin(), default_mask.end(), 0)) is the only changed line CI's coverage run reports as executed by no 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: 05233_dict_get_or_default_const_null_key.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.

@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Sep 20, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

Reviewed against master ed38f61d0941c, which contains #120674 as 78438476e587. The gap is real and the test is sound. Details, since the interesting part is that the oracle genuinely discriminates rather than just passing:

Coverage claim holds. Of the 59 files under tests/queries/ and tests/integration/ that call dictGetOrDefault, every NULL sits in the default argument; the key is always non-NULL (toUInt64(2), id+1, 1337, tuple(2.0, 2.0), toUInt128(0)). Your reading of 05232 is also right: its dictGetOrDefault, NULL key section takes k from nkeys_05232, a materialized ColumnNullable, so it goes through the loop at :696-703 and never the else if.

Reachability measured, not argued. I commented out the std::fill at :707 and rebuilt (dependent TUs confirmed recompiled, server Build-ID 6a15216 to a5313d6). The test then fails on its first query with Cannot parse string 'zz1' as UInt32 (CANNOT_PARSE_TEXT); restoring the line returns it to green. So :704 is taken and :707 is what the test observes. The failing query's plan text also confirms the key stays constant, _CAST(NULL_Nullable(UInt64), ...) :: 3 beside a non-const concat('zz', toString(__table1.x)) :: 0, which is your IFunction.cpp all-const point.

Both NULL-key arms pull their weight, and differently. Under the flip the a arm throws CANNOT_PARSE_TEXT (6) and the b arm throws CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN (349), so the Nullable and non-Nullable attributes cover two distinct downstream consequences rather than the same one twice. The two constant non-NULL key queries are correctly insensitive to the flip, which is what makes them controls for the key's NULL-ness rather than for its const-ness.

The SET at the top is load-bearing. With short_circuit_function_evaluation = 'disable' the first query throws on current master, because the eager path never reaches :704. The in-file SET also wins against a hostile --client-option short_circuit_function_evaluation=disable (2/2), so the test cannot be randomized out of the path it is testing.

Stability. 30/30 under randomization, spanning 33 distinct short_circuit_function_evaluation_for_nulls_threshold draws from 0.067 to 1.078, plus forced 0, 0.5, 1.0 and 1.1. No no-parallel-replicas tag needed: the tables are Memory, and 48 of 180 dictionary queries ran with cluster_for_parallel_replicas = 'parallel_replicas' without a failure. check_style.py is 14/15 locally, the single failure being settings_changes_history refusing to run without a changed-files record, which is an artifact of running it outside CI and not a property of the test.

No findings from me. On the label: I do not apply labels on another author's PR, so can be tested needs to come from a maintainer.

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

clickhouse-gh Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [dcd7235]

Summary: ✅


AI Review

Summary

This PR adds a focused stateless regression test for the dictGetOrDefault short-circuit path where the key is a constant NULL Nullable(UInt64). I did not find a correctness, coverage, or stability issue in the new test: it exercises the distinct nullable_key_column->isNullAt(0) branch in getDefaultsShortCircuit, and the control queries show the test would fail if that branch stopped suppressing default conversion.

Final Verdict

✅ No findings. The new test is not redundant with 05232_accurate_cast_nullable_callers.sql; that older test covers materialized nullable keys, while this PR covers the constant-null-key branch. The visible CI surface was clean at review time (Fast test and Style check passed; broader jobs were still pending).

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Sep 27, 2026
@alexey-milovidov alexey-milovidov self-assigned this Sep 28, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 28, 2026
Merged via the queue into ClickHouse:master with commit b6a6cfc Sep 28, 2026
176 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 Sep 28, 2026
@clickhouse-gh clickhouse-gh Bot added comp-dictionary Dictionaries (in-memory key-value, periodically refreshed from sources). and removed comp-testing Test content only (no production code). labels Nov 22, 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 comp-dictionary Dictionaries (in-memory key-value, periodically refreshed from sources). 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.

4 participants