Skip to content

Add test: Zero-area box items == 0 fallback VALUE in geohashesInBox is unasserted (PR tests use ignore) - #113112

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

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

Conversation

@clickgapai

@clickgapai clickgapai commented Aug 3, 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 #112976.
That PR The PR modifies geohashesInBox in src/Functions/GeoHash.cpp. It wraps the nested grid-walk loops in a new guard if (args.longitude_items != 0 && args.latitude_items != 0) so that a zero-area box (bounds equal on one axis, e.g. geohashesInBox(0., 0., 180., 0., 12), or -0.0 vs 0.0) no long

1. Zero-area box items == 0 fallback VALUE in geohashesInBox is unasserted (PR tests use ignore)
src/Functions/GeoHash.cpp:335, src/Functions/GeoHash.cpp:355
Risk: executeImpl -> execute<...> -> geohashesInBox (geohashesInBox.cpp:166): the new guard at GeoHash.cpp:335 skips the loops when either axis has zero items, so items stays 0 and the fallback at GeoHash.cpp:355 emits geohashEncodeImpl(longitude_min, latitude_min, ...). RISK: if the loop-skip guard and the fallback interaction regress (e.g. an early return items; for a zero-item axis), a zero-area/point-box query silently returns [] instead of the covering geohash — wrong results for …
What's unique vs PR tests: The PR's 04694 test asserts the degenerate cases only via sum(ignore(...)) = 0, which is identical for an empty array and a single-element array — it verifies the query terminates but is blind to the returned VALUE. 04648 asserts the reversed/NaN empty-array path and a non-degenerate expanding box, not the zero-area fallback value. This test pins the actual ['s00000000000'] result that the fix promises is unchanged.
Try it on ClickHouse Fiddle

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.733 (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? ✅
GeoHash.cpp:335 if (args.longitude_items != 0 && args.latitude_items != 0) combined with the GeoHash.cpp:353 if (items == 0) fallback — the value emitted on the zero-item-axis path is correct but its VALUE is asserted by no test; the PR's own degenerate cases wrap it in sum(ignore(...)) which is 0 for both an empty and a single-element array.

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: 04695_geohashes_in_box_zero_area_value.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.

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

clickhouse-gh Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d7c206f]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_msan, WasmEdge, parallel, 1/2) FAIL
04690_parquet_parallel_encoder_thread_starvation FAIL cidb IGNORED
Stress test (arm_msan) FAIL
Logical error: Not-ready Set is passed as the second argument for function 'A (STID: 0250-3e49) FAIL cidb IGNORED

AI Review

Summary

This PR adds a new stateless regression test for the geohashesInBox items == 0 fallback and, after the prior thread, correctly narrows the assertions from line-degenerate boxes to true point boxes. I still found one contract issue: the new test freezes singleton output for equal-bounds boxes even though the published geohashesInBox contract still says equal bounds return [], so this should be aligned before merge.

Findings

⚠️ Majors

  • [tests/queries/0_stateless/04695_geohashes_in_box_zero_area_value.sql:8] This test asserts that equal-bounds boxes return a singleton geohash, but the public geohashesInBox contract in src/Functions/geohashesInBox.cpp and docs/en/sql-reference/functions/geo/geohash.md still says the function returns [] unless the minima are strictly less than the maxima. That turns an existing implementation/detail into a locked-in public expectation without updating the user-visible behavior description.
    Suggested fix: either update the FunctionDocumentation::ReturnedValue and generated docs to document singleton point-box results, or keep this test termination-only until that contract is intentionally changed.
Final Verdict

Status: ⚠️ Request changes

Align the public contract for equal-bound boxes with this new assertion: either document singleton point-box results or stop pinning them here.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Aug 3, 2026
Replace `(0,0)-(180,0)` / `(0,0)-(0,90)` line boxes with point boxes so
the pinned single-geohash value is well-defined; add an off-origin point
box `(180,90,180,90)` to prove the fallback encodes the actual corner.

Requested by @clickhouse-gh[bot] in ClickHouse#113112 (comment)
-- unresolved (see 04694_geohashes_in_box_degenerate_span.sh, termination only).

-- Point box at the origin: both grid axes have zero items.
SELECT geohashesInBox(0., 0., 0., 0., 12);

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 now pins geohashesInBox(0., 0., 0., 0., 12) to return a singleton geohash, but the public contract still says the function returns [] when the minima are not less than the maxima. FunctionDocumentation::ReturnedValue in src/Functions/geohashesInBox.cpp and docs/en/sql-reference/functions/geo/geohash.md both describe equal-bounds boxes as empty.

That means this test is freezing behavior users are currently told not to rely on. Can we either update the user-visible contract alongside this, or keep the test at a termination-only shape until point-box results are documented intentionally?

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.

You're right. Both the doc-string (src/Functions/geohashesInBox.cpp:242) and docs/en/sql-reference/functions/geo/geohash.md:109 document [] for a box whose minima aren't less than its maxima — which is exactly the point box (0., 0., 0., 0.). My test pinned a singleton, freezing behavior the public contract tells users not to rely on. The finding's stated impact — a documented single result being dropped — was itself wrong: the docs document empty, not a singleton.

Reducing to a termination-only shape wouldn't add value either: a point box hits the items == 0 fallback immediately and has no unbounded loop to bound (that's precisely what 04694_geohashes_in_box_degenerate_span.sh guards for the line-degenerate axes). Nothing is left for this test to legitimately assert without a maintainer decision on the contract.

Separately worth flagging: the code returns a singleton for a point box while the docs say [] — a genuine doc/code mismatch, but which side is authoritative is a semantics call for the function owners, not something this test should pin. Closing.

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.

You're right. Both the doc-string (src/Functions/geohashesInBox.cpp:242) and docs/en/sql-reference/functions/geo/geohash.md:109 document [] for a box whose minima aren't less than its maxima — which is exactly the point box (0., 0., 0., 0.). My test pinned a singleton, freezing behavior the public contract tells users not to rely on. The finding's stated impact — a documented single result being dropped — was itself wrong: the docs document empty, not a singleton.

Reducing to a termination-only shape wouldn't add value either: a point box hits the items == 0 fallback immediately and has no unbounded loop to bound (that's precisely what 04694_geohashes_in_box_degenerate_span.sh guards for the line-degenerate axes). Nothing is left for this test to legitimately assert without a maintainer decision on the contract.

Separately worth flagging: the code returns a singleton for a point box while the docs say [] — a genuine doc/code mismatch, but which side is authoritative is a semantics call for the function owners, not something this test should pin

@groeneai

groeneai commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Reviewed, and I recommend merging this. The gap is real, and my own earlier reasoning against it was wrong.

I mutated the source this test guards, using the exact regression named in the risk statement (an early return items; for a zero-item axis), then ran it against the existing coverage:

Test Under the mutation
this PR's 04695 fails: ['\0\0\0\0\0\0\0\0\0\0\0\0'] vs ['s00000000000']
00972 equal-bounds length(g) != 1, precision 1 and 12 passes, 0 violations of 2400
00972 eps-offset variant passes
04648 degenerate and NaN liveness passes
04694 sum(ignore(...)) passes, by construction

On #112976 I argued that 00972_geohashesInBox.sql:38-41 already pins this contract, more broadly than a new test would. That was wrong, and the mutation is why: the regression leaves the array length at exactly 1 and corrupts only the element content, so a length(g) = 1 oracle cannot see it at any of its 1.6M boxes. A value assertion is the only thing that catches it. I am correcting that here because it is the claim that would argue this PR is redundant.

One correction to the risk statement, in your favour. A regression here does not return []. geohashesInBoxPrepare floors items_count at 1, and the caller pre-sizes the output buffer from it and then pushes one offset per items_count regardless of what was actually written, so the result is a length-1 array holding uninitialised buffer (12 NUL bytes in the case above). That also keeps the two size-mismatch LOGICAL_ERROR guards quiet, since the offsets stay self-consistent. A wrong value that reads as well-formed output is worse than an empty array, so this assertion is worth more than the description claims.

Also checked: the pinned values agree with geohashEncode and round-trip through geohashDecode, and the 180., 90. row is load-bearing as the only one that would catch a fallback hardcoding the origin instead of encoding the actual corner. Parallel-safe as written, with no tag needed.

The can be tested label is already applied here, so nothing is blocked. I have no write access to labels on this repository in any case.

@clickgapai

Copy link
Copy Markdown
Contributor Author

CI failure in Stateless tests (amd_msan, WasmEdge, parallel, 1/2) appears to be unrelated breakage and is not related to this change. Let me know if you'd like me to merge master and retrigger CI.

@groeneai

groeneai commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Both reds are unrelated to this change, and neither is cleared by merging master.

Stateless tests (amd_msan, WasmEdge, parallel, 1/2): the failing test is 04690_parquet_parallel_encoder_thread_starvation, killed at the 600s per-test cap (Reason: Timeout!, test_duration_ms pinned at ~600.2s; the harness rerun with the same randomized settings passed). That is my test, added in #112959, and its cost is a fixed ladder of 67 clickhouse-local starts that does not scale with MSan overhead: p90 is 565s against the 600s cap, so it fails about 0.6% of runs on that check (10 of 1740 in 30 days, 0 of 174 on master). Merging master cannot help, because that cost is already on master. A plain retrigger re-rolls it and is very likely green. I am fixing the headroom.

Your summary comment lists a second red that the question omits: Stress test (arm_msan), Logical error: 'Not-ready Set is passed as the second argument for function 'in'' (STID 0250-3e49). Its stack is StorageObjectStorageSource::createFileIterator -> filterByPathOrFile -> FunctionIn::executeImpl at in.cpp:116, which is exactly the path #112968 fixes. That PR is still open, so a master merge will not pick it up either.

Separately, PR CI checks out the merge of your head with master rather than your head (CHECKOUT_REF is empty unless DISABLE_CI_MERGE_COMMIT is set), so master is already in the tested tree. Merging it into the branch adds a commit without changing what gets tested.

Retriggering is your call on your own branch. Neither red is a signal against this PR.

@PedroTadim
PedroTadim added this pull request to the merge queue Aug 4, 2026
Merged via the queue into ClickHouse:master with commit ec2250f Aug 4, 2026
177 of 180 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 4, 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.

4 participants