Skip to content

Add compatibility setting functions_h3_default_if_invalid - #97821

Merged
bharatnc merged 8 commits into
masterfrom
h3ck
Mar 12, 2026
Merged

bharatnc merged 8 commits into
masterfrom
h3ck

Conversation

@al13n321

@al13n321 al13n321 commented Feb 24, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Closes #97705

(This doesn't quite bring back the old behavior, because the old behavior was to call the h3 library functions with the invalid arguments, which was doings all sorts of out-of-bounds array accesses and sometimes crashed the server or got stuck in a loop.)


Note

Medium Risk
Changes runtime behavior of multiple H3 functions on invalid inputs, which can alter query results and error handling. Touches geospatial function execution paths but is gated behind a setting with tests.

Overview
Introduces functions_h3_default_if_invalid, allowing H3 functions to return default values (0/empty arrays) instead of throwing INCORRECT_DATA when given invalid H3 cell indices.

Refactors H3 cell validation into a context-aware H3Validator and updates a set of H3 functions (e.g., h3ToGeo, h3kRing, h3Line, area/distance/neighbor and edge helpers) to skip H3 library calls on invalid inputs when the setting is enabled. Adds a stateless test covering both default (throw) and compatibility (default-return) behaviors.

Written by Cursor Bugbot for commit f4d2f05. This will update automatically on new commits. Configure here.

Version info

  • Merged into: 26.3.1.604
  • Backported to: 26.2.5.21

@clickhouse-gh

clickhouse-gh Bot commented Feb 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f4d2f05]

Summary: ✅


AI Review

1) Summary

This PR introduces functions_h3_default_if_invalid, refactors H3 cell validation through H3Validator, and updates multiple H3 functions to return defaults on invalid cells when compatibility mode is enabled. The implementation changes are coherent and safety-oriented, but test coverage is incomplete for one modified function. High-level verdict: Request changes.

2) Missing context (if any)

  • Full CI matrix details (the fetched Praktika summary for the linked report contained no per-test entries).
  • No benchmark evidence for potential overhead of per-row validation checks.

3) Findings (by severity)

Blockers

  • None.

Majors

  • [tests/queries/0_stateless/04034_h3_functions_default_if_invalid.sql:30] src/Functions/h3HexRing.cpp changed invalid-input semantics, but the new test file does not cover h3HexRing in either mode. This leaves an untested behavior change on a touched path and can miss regressions that reintroduce calls into H3 internals on invalid cells.
    • Suggested fix: add two cases for h3HexRing(toUInt64(0), 1) — one expecting serverError INCORRECT_DATA (default mode), and one after SET functions_h3_default_if_invalid = true expecting [].

4) Tests & Evidence

  • Positives: The new stateless test validates throw-vs-default behavior for most changed functions, and checks both default and compatibility mode.
  • Negatives/error paths: Present for many functions via invalid toUInt64(0) inputs.
  • Gap: add explicit negative/default checks for h3HexRing because this function’s code path was modified and currently has no coverage in this PR test.

5) ClickHouse Compliance Checklist (Yes/No + short note)

  • Data deletions logged? Yes (not applicable; no deletion logic touched).
  • Serialization formats versioned? Yes (not applicable; no format/protocol changes).
  • Experimental setting gate present? Yes (functions_h3_default_if_invalid).
  • Settings exposed for constants/thresholds? Yes (behavior is setting-controlled).
  • Backward compatibility preserved? Yes (compatibility wiring via SettingsChangesHistory.cpp).
  • SettingsHistory.cpp updated for new/changed settings? Yes (SettingsChangesHistory.cpp entry added).
  • Existing tests untouched (only additions)? Yes (new test file added).
  • Docs/user-facing notes updated? No (no dedicated docs change in this PR).
  • Core-area change got extra scrutiny? Yes (H3 function safety/error handling paths reviewed).

6) Performance & Safety Notes

The change improves safety by preventing unsafe H3 library calls on invalid cells, reducing risk of undefined behavior/exception loops from upstream library internals. Runtime overhead is small and linear (extra isValidCell checks per row), but no microbenchmark is attached; a minimal benchmark could run affected H3 functions on large valid columns (e.g., 10M rows) with setting on/off and compare CPU time.

7) User-Lens Review

Behavior is more robust and predictable, and the new setting offers explicit compatibility control for users who prefer default-return semantics. Error handling in strict mode remains actionable (INCORRECT_DATA), and compatibility mode gives deterministic defaults; the primary surprise risk is only the current missing test for one touched function.

8) Final Verdict

Status: Request changes

Minimum required actions to get approval:

  1. Extend tests/queries/0_stateless/04034_h3_functions_default_if_invalid.sql and .reference with h3HexRing invalid-input checks in both modes.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Feb 24, 2026
@bharatnc bharatnc self-assigned this Mar 9, 2026
Comment thread src/Core/Settings.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.80% 83.80% +0.00%
Functions 23.90% 23.90% +0.00%
Branches 76.30% 76.30% +0.00%

PR changed lines: PR changed-lines coverage: 95.70% (267/279)
Diff coverage report
Uncovered code

@bharatnc
bharatnc added this pull request to the merge queue Mar 12, 2026
Merged via the queue into master with commit 485fb23 Mar 12, 2026
471 of 478 checks passed
@bharatnc
bharatnc deleted the h3ck branch March 12, 2026 12:03
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 12, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Mar 12, 2026
robot-clickhouse added a commit that referenced this pull request Mar 12, 2026
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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 v26.2-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backward compatibility request 26.2: h3 functions

6 participants