Skip to content

Add coverage tests for six untested function branches - #114260

Merged
zlareb1 merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/coverage-functions-types-batch2-group-a
Aug 24, 2026
Merged

zlareb1 merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/coverage-functions-types-batch2-group-a

Conversation

@groeneai

Copy link
Copy Markdown
Collaborator

Related: #103918
Related: #103922
Related: #103940
Related: #107447
Related: #103885
Related: #103931

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

Test-only, 12 files, 42 insertions. @ zlareb1 asked me to re-file six closed clickgapai coverage PRs (linked above); this is the functions/types group.

I did not take the tests on trust. For each one I mutated the exact line it claims to cover, rebuilt, and required that test to fail while the other five stayed green. That found three defects in the originals:

  • 103931 was flaky by construction. Its overflow arguments were unqualified DateTime literals, read in the session timezone, which CI randomizes. In a positive-offset zone the value falls below the overflow boundary and the guard never fires: unpinned it FAILs under Africa/Khartoum and Asia/Kolkata and passes only under UTC. Every argument now pins a timezone, and it passes in all six zones swept.
  • 103931 covered only one of two guard copies. The wstart > wend check exists in both the windowID and hop paths and neither was tested. Mutating one copy reddens only its own row, so both are now pinned, each row the other's scoping control.
  • 103922's Nullable(String) block could not detect the regression. Its nested default '' never equals an array element, so it stays green under the mutation while Nullable(UInt64) (default 0, present in the array) reddens. Dropped.

Two oracles were also too weak to bind a per-row read, and were strengthened after review: 04146 now pins the ordered address-to-digest mapping rather than the digest count, and 04329 uses two distinguishable rows rather than one.

Per the recent "trim the tests" reviews, each file keeps one row per distinct dispatch or template instantiation rather than every spelling that reddens. The implementation commentary lives in the commit messages, not the .sql.

Validation

Debug build, clickhouse-test with randomization on (the CI default). Every mutation changes the branch's output rather than deleting it, so a fall-through to an equivalent slower path cannot be mistaken for a vacuous test. Each arm was reverted and rebuilt before the next.

test mutated line result
04201_dot_product_const_nonconst_size_mismatch arrayDotProduct.cpp:397 size check neutered FAIL alone; other 5 OK
04201_array_index_of_count_equal_nullable_value arrayIndex.h:1246 null_map skip removed FAIL alone; other 5 OK
04201_json_extract_keys_and_values_low_cardinality_input FunctionsJSON.cpp:577 LC stripping skipped FAIL alone; other 5 OK
04329_like_fixedstring_constant_match_everything MatchImpl.h:322 per-row fill replaced by a first-row-only write FAIL alone; other 5 OK
04146_ipv6_hashing_distinct_values FunctionsStringHashFixedString.cpp:316 &data[i] -> &data[input_rows_count-1-i] FAIL alone; other 5 OK
04201_windowID_hop_time_overflow FunctionsTimeWindow.cpp:580 guard neutered FAIL, windowID row only
04201_windowID_hop_time_overflow FunctionsTimeWindow.cpp:430 guard neutered FAIL, hop row only

The 4th and 5th mutations are the point of the strengthening: under each, the weaker oracle those tests originally carried stays green on the same binary.

  • 50 randomized runs of each of the six: 300/300 OK, and 200/200 again on the four changed by the strengthening.
  • Each test run 8 times concurrently with itself: 16/16 OK on the two rewritten ones, so no no-parallel tag.
  • 04201_windowID_hop_time_overflow swept across 6 timezones, one test per run: 6/6 OK.
  • 04146's digests are build-independent: an independent Python sha256(inet_pton(AF_INET6, addr)) reproduces them byte-for-byte, and the same method reproduces master's own committed digest in 02184_hash_functions_and_ip_types.reference.

Re-files six test-only coverage PRs that were closed without merging, at the
request of their author. Each test was verified to be non-vacuous by mutating
the exact line it claims to cover and requiring the test to fail; the arms and
their controls are listed below.

- 04201_dot_product_const_nonconst_size_mismatch: the size check in
  arrayDotProduct's one-constant-argument path. The existing 02708_dotProduct
  covers only equal sizes there, and the two-non-constant path throws from a
  different site with a different message.
- 04201_array_index_of_count_equal_nullable_value: the null_map row skip shared
  by has/indexOf/countEqual. Only has() reached it before. Trimmed to
  Nullable(UInt64): with Nullable(String) the nested default never equals an
  array element, so that variant cannot detect the regression.
- 04201_json_extract_keys_and_values_low_cardinality_input: LowCardinality
  stripping for the two functions that force their return type. Only
  JSONExtract exercised it with a non-constant LowCardinality column.
- 04329_like_fixedstring_constant_match_everything: the matches-everything
  shortcut for a FixedString haystack. Existing FixedString LIKE tests all use
  substantive patterns. Keeps one row per template instantiation
  (LIKE / NOT LIKE / ILIKE / match).
- 04146_ipv6_hashing_distinct_values: per-row indexing when hashing an IPv6
  column. 02998_ipv6_hashing repeats a single value, so it cannot detect a
  regression that always reads row 0.
- 04201_windowID_hop_time_overflow: the hop-window overflow guard, which is
  duplicated in the windowID and hop code paths. Neither copy was tested;
  mutating one reddens only its own row, so both are now pinned. Every
  argument carries an explicit timezone because an unqualified DateTime
  literal is read in the session timezone, which CI randomizes across the
  overflow boundary.

Related: ClickHouse#103918
Related: ClickHouse#103922
Related: ClickHouse#103940
Related: ClickHouse#107447
Related: ClickHouse#103885
Related: ClickHouse#103931
Both tests passed on master while being blind to a whole class of regression
in the branch they claim to cover.

04146 asserted only the digest cardinality, count(DISTINCT SHA256(addr)) = 4,
which measures that the four addresses hash differently but not that each row
is hashed from its own address. A permuted read of the input column keeps four
distinct digests, so it stayed green. It now asserts the ordered
address-to-digest mapping. Committing the digests is safe on every CI
architecture: IPv6 is parsed into four big-endian 32-bit components on both
endiannesses (see the note in FunctionsHashing.h), so no byte swap applies, and
02998_ipv6_hashing.reference already commits raw IPv6 digests. Verified by
computing the same four digests independently from the network-order bytes.

04329 had a single input row against a per-row fill loop, so a regression
writing only the first row and leaving the rest untouched was undetectable. It
now uses two distinguishable FixedString rows. No new template instantiation is
added: the same four columns are kept.

Also drop a dead SET allow_experimental_window_view from the windowID test (only
WATCH and StorageWindowView are gated by it), and correct a comment that stated
a false general rule -- a NULL needle does match a NULL array element; what the
test pins is that the array here holds no NULLs.

Both new oracles were mutation-proven: a permuting read of the IPv6 column, and
a first-row-only write of the match result, each reddens its own test and no
other, while the previous assertions stayed green under those same mutations.
@groeneai

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

Two rounds of independent cold review plus a second model reviewed this diff before publication. 7 findings, 5 accepted, 2 declined with evidence. The second round returned 0 findings.

# Finding Verdict
❌ 04146 asserted count(DISTINCT SHA256(addr)), which measures cardinality, not the per-row binding it claims to pin: a permuted read still yields four distinct digests. Now asserts the ordered (addr, hex(SHA256(addr))) mapping, proven by a permuting-read mutation under which the old assertion stayed green. AGREE, fixed
❌ 04329 had one input row, but the shortcut is a per-row fill loop, so a first-row-only regression was undetectable. Now two FixedString rows, proven by a first-row-only mutation under which the old assertion stayed green. AGREE, fixed
⚠️ 04201_windowID carried a dead SET allow_experimental_window_view = 1: the functions are not gated by it, only WATCH and StorageWindowView are. Removed. AGREE, fixed
⚠️ 04201_array_index comment claimed a NULL never matches an array element. False in general: a NULL needle does match a NULL element. Qualified to the array-without-NULLs case this test pins. AGREE, fixed
⚠️ Provenance Related: links sat inside the leading HTML comment, so they did not render. Moved into the visible body. AGREE, fixed
💡 Add a second row to 04201_dot_product so a prev_offset regression is caught. Declined: that arithmetic is already owned by master. 04312_array_dot_product_bfloat16.sql:20-24 runs the const-left path over 200 equal-length rows, so a stale prev_offset throws on row 2 for input that must succeed; 02354_vector_search_queries.sql:266 and 04061_array_dot_product_empty_arrays.sql:16 cover it too. This test's contract is narrower and its own arm proves it. DISAGREE
💡 Add a branch-specific oracle to 04201_json_extract that fails if JSONExtractKeysAndValuesImpl is dropped from functionForcesTheReturnType. Declined: that mutation routes to the default LowCardinality adaptor, which (as the finding itself notes) strips the input and prints the same value, so there is no SQL-observable difference to assert. The invariant claimed is behavioural, and dropping the strip itself reddens with Code: 43. DISAGREE

Both declines are the same class: a mutation that deletes a branch falls through to an equivalent slower path, so identical output is expected and is not evidence of a vacuous test. Every accepted arm instead changes the branch's output.

Also noted and not treated as blocking: 04146's in-file comment describes only the permutation case, while the assertion is in fact stronger (it also catches a collapsing read, a wrong read length, and an endianness change). Left as written rather than expanded.

Session id: cron:clickhouse-review-slot-8:20260811-021900

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, but note this PR adds coverage tests, so the equivalent obligation is falsification, not defect reproduction. Each test has a deterministic mutation that reddens it: e.g. arrayDotProduct.cpp:397 replaced by false, rebuild, clickhouse-test 04201_dot_product_const_nonconst_size_mismatch FAILs. 9 arms in total (7 plus two added while strengthening two oracles: a permuting read of the IPv6 input column, and a first-row-only write of the match result).
b Root cause explained? Each test closes a named branch-coverage gap: the branch exists on master and no test reaches it. Verified per test by reading the dispatch and enumerating master's existing callers (e.g. all 5 JSONExtractKeysAndValues call sites on master pass a constant haystack, which takes the useDefaultImplementationForConstants path and never reaches the LowCardinality stripping at FunctionsJSON.cpp:577).
c Fix matches root cause? Yes. Test-only, no src/ change; the assertion targets exactly the line claimed, proven by the mutation reddening that test and no other.
d Test intent preserved / new tests added? 6 new tests, 0 modified, 0 removed. Arms were cut only where measured non-distinct or provably unable to detect the regression, each recorded with its dispatch citation and redness observation. Two oracles were then strengthened: the IPv6 test asserts the ordered address-to-digest mapping rather than only the digest count, and the FixedString LIKE test uses two rows rather than one, because the branch it covers fills the answer per row. In both cases the previous assertion was measured to stay green under a mutation the new one catches.
e Both directions demonstrated? Yes, per test under the real runner: FAILs on its mutated binary, passes on the pristine one, with the Build ID asserted to move on every transition and asserted equal between the on-disk binary and the running server. After reverting all arms, all 28 probe results were byte-identical to the pre-mutation baseline. Every changed test also ran 50x with randomized settings (200/200 OK), and the overflow test was swept across 6 session timezones.
f Fix is general across code paths? Duplicated guards are covered, not just the reported one: the wstart > wend check is copied at FunctionsTimeWindow.cpp:430 (hop) and :580 (windowID), neither was tested, and 04201 now pins both. Mutating :580 reddens only the windowID row and mutating :430 only the hop row, so each row is the other's scoping control. Sibling paths deliberately left out of scope are named in the PR body.
g Fix generalizes across inputs? Type-wrapper and instantiation coverage is the subject matter here: 103922 covers Nullable(UInt64) (with the measurement showing Nullable(String) cannot detect the regression), 103940 covers non-constant LowCardinality(String), 107447 keeps one row per template instantiation (LIKE / NOT LIKE / ILIKE / match), 103931 covers the DateTime overflow boundary.
h Backward compatible? N/A. Test-only: no setting default, no serialization format, no new validation.
i Invariants and contracts preserved? N/A for source invariants (no src/ change). Test-level contracts checked: no default.-qualified reference and no database name in any reference file, no no-parallel tag (8-way concurrent with itself, 48/48 OK, plus 16/16 for the two rewritten tests), filenames free-checked case-insensitively against live master, all-author open PRs, and live fleet worktrees with passing positive controls, and CI's check_file_names predicate re-run over the whole post-change tree.

Session id: cron:clickhouse-impl-slot-5:20260811-003900

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @antaljanosbenjamin, could you review this? It is test-only: six coverage tests for function branches that no test reached, each proven non-vacuous by mutating the exact line it covers and requiring only that test to fail.

@zlareb1 zlareb1 self-assigned this Aug 11, 2026
@zlareb1 zlareb1 added the can be tested Allows running workflows for external contributors label Aug 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c2e4128]

Summary: ✅


AI Review

Summary

This PR adds six stateless coverage tests for previously untested function/type branches, including the const-array nullable indexOf / countEqual path, the one-constant-argument dotProduct size check, JSONExtractKeysAndValues on a non-constant LowCardinality(String) JSON input, the duplicated windowID / hop overflow guards, the FixedString "matches everything" LIKE / ILIKE / match shortcut, and per-row IPv6 SHA256 hashing. I checked the current diff against the cited source branches and nearby existing tests on master; the new assertions still map to the intended branches and I did not find a correctness or test-quality issue that warrants a review comment.

Final Verdict

✅ Approve.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 11, 2026
@zlareb1

zlareb1 commented Aug 11, 2026

Copy link
Copy Markdown
Member

@groeneai can you check the CI failures and if they are flaky tests merge latest master and rerun the CI.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - c52bd50

Every failure below has an owner: a fixing PR (ours 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
Stress test (amd_tsan) / Hung check failed, possible deadlock found chronic trunk hang, not this PR a fix task owns it (investigating at full effort - fixing-PR link to follow here)
Stress test (amd_msan) / Hung check failed, possible deadlock found same signature as above a fix task owns it (investigating at full effort - fixing-PR link to follow here)
Stress test (arm_tsan) / Hung check failed, possible deadlock found same signature as above a fix task owns it (investigating at full effort - fixing-PR link to follow here)

@zlareb1 answering your question directly: all three failures are one trunk defect, not flaky tests,
and a plain master merge will not clear them, so I have not pushed one. Detail below.

The report only keeps the tail of hung_check.log, which holds the aggregated frame list; the
per-query processlist is in the discarded head. Reading the artifacts directly, all three arms hang on
the same single query:

arm query cancelled elapsed
amd_tsan DROP TABLE prometheus; 1 1162.5 s
amd_msan DROP TABLE prometheus; 1 1301.7 s
arm_tsan DROP TABLE prometheus; 1 876.7 s

Its frames are StorageTimeSeries::dropInnerTableIfAny -> InterpreterDropQuery::executeDropQuery
-> waitForTableToBeActuallyDroppedOrDetached -> DatabaseCatalog::waitTableFinallyDropped, parked in
condition_variable::__do_timed_wait. An already-cancelled DROP of a TimeSeries table never returns
from that wait, so teardown convoys behind it. That is a real hang rather than test flakiness, which is
why "flaky, merge master and rerun" would only move the failure to a new head.

It is not caused by this PR: the diff is stateless .sql/.reference files only, with no TimeSeries
or DatabaseCatalog code. Breadth over 30 days for this test name is 979 rows across 524 pull requests
with 130 rows on master.

Not linked here, deliberately: #97586 and #113504 both already fix a wait of this shape, both are
ancestors of the tested build 1343aefc4be5, and the hang still fired with them present, so neither
covers this path.

Session id: cron:our-pr-ci-monitor:20260811-080000

@groeneai

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the hung DROP TABLE of a TimeSeries table (waitTableFinallyDropped): #114302 (external, open).

@zlareb1

zlareb1 commented Aug 16, 2026

Copy link
Copy Markdown
Member

@groeneai lets merge latest master and retry CI

Requested by zlareb1 on ClickHouse#114260 to re-run CI against current master.
Base was 3690 commits behind; merge is clean, no conflicts, diff unchanged
(12 stateless test files, 42 insertions).
@groeneai

Copy link
Copy Markdown
Collaborator Author

@zlareb1 done. Merged master (d8392cfb8bad) into the branch; head is now c2e4128a0630a1383d3063cec25cb4613072121c and a fresh CI run is in progress. The base was 3690 commits behind, the merge was clean, and the diff is unchanged: the same 12 stateless test files, 42 insertions, no source changes.

One thing to expect: the three reds were Hung check failed, possible deadlock found on the Stress tests (amd_tsan, amd_msan, arm_tsan), and that is a trunk defect rather than flakiness in these tests. The fix is #114953, which is still open, so this merge does not pick it up and the hung check may fire again on this run. If it does, that PR is the owner and I will link it here rather than re-investigating.

@clickhouse-gh

clickhouse-gh Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing c2e4128a0 with master d8392cfb8 (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
Binary Master PR Δ
programs/clickhouse-stripped 694.55 MiB 691.54 MiB -3.01 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

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

Job report

@groeneai groeneai added the groeneai-origin-request PR origin: a maintainer pinged or directed groeneai label Aug 19, 2026
@zlareb1
zlareb1 added this pull request to the merge queue Aug 24, 2026
Merged via the queue into ClickHouse:master with commit c9e31a7 Aug 24, 2026
183 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 Aug 24, 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 groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-ci 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