Repository navigation
Update H3 C library from v3.7.1 to v4.4.1 - #100348
Conversation
The H3 C library fork (github.com/ClickHouse/h3) was on v3.7.1 with 2 ClickHouse-specific range-check patches. Upstream H3 v4 already includes equivalent validation in `_h3ToFaceIjk`, so the patches are no longer needed. Created a clean `clickhouse-v4` branch in the fork at upstream tag v4.4.1 with no additional patches. This fixes two known bugs in the v3 lookup tables: - Average hexagon edge lengths were actually inradii (apothems), not edge lengths (uber/h3#201, fixed in uber/h3#749) - Average hexagon areas naively divided Earth surface by total cell count without excluding pentagon areas (fixed in uber/h3#529) The v4 API changed most functions to return `H3Error` with results via output parameters. Updated all 27 wrapper files in `src/Functions/` to use the new calling convention. Also updated function renames: `exactEdgeLengthM` → `edgeLengthM`, `distanceM` → `greatCircleDistanceM`, etc. Updated 11 test reference files to reflect the corrected values. Reference: #100272 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Workflow [PR], commit [066c404] Summary: ✅ AI ReviewSummaryThis PR upgrades bundled H3 from v3 to v4 and updates ClickHouse wrappers/tests to the new API and corrected geometric metrics. Most API migration changes look consistent, but I found one user-visible contract mismatch in PR Metadata
Suggested replacement: Findings💡 Nits
ClickHouse Rules
Final Verdict
|
alexey-milovidov
left a comment
There was a problem hiding this comment.
The code is good.
| res = gridPathCellsSize(start, end); | ||
| { | ||
| int64_t distance = 0; | ||
| if (!gridDistance(start, end, &distance)) |
There was a problem hiding this comment.
h3Distance used to return a negative value when distance cannot be computed (see the function docs below), but this new path initializes res = 0 and only assigns on E_SUCCESS. On any non-success from gridDistance, this now returns 0, which is also a valid distance (start == end).
That silently changes semantics and loses error signaling for valid-but-unreachable pairs.
Please preserve the previous contract by mapping non-success to a negative sentinel (for example -1) or by updating both behavior and docs/tests consistently if you intentionally changed semantics.
There was a problem hiding this comment.
@alexey-milovidov Hi, this comment looks meaningful, could you please double check?
…ntinel - Zero-initialize `std::array<H3Index>` in `h3GetIndexesFromUnidirectionalEdge` and `h3GetUnidirectionalEdgesFromHexagon` to fix MSan use-of-uninitialized-value when H3 v4 functions fail on invalid input. - Change `h3Distance` default result from 0 to -1 so that failure is distinguishable from a valid zero distance (start == end), preserving the documented contract. - Restore test reference to expect `(0,0)` for invalid edge inputs. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The previous commit changed the error sentinel of `h3Distance` from 0 to -1 to distinguish errors from a valid zero-distance result, but the reference file for `04034_h3_functions_default_if_invalid` was not updated accordingly. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
| @@ -1,28 +1,28 @@ | |||
| 6 | |||
There was a problem hiding this comment.
This PR changes h3Distance results (see this updated reference: values drop from 7/8/13 to 6/8/12), which is a user-visible backward-incompatible behavior change beyond length/area precision updates. Please update the Changelog entry to mention h3Distance semantic/result changes explicitly so users can anticipate query output differences.
There was a problem hiding this comment.
This is true.
@alexey-milovidov Should we mention this somewhere? We call different function right now
|
So, do we continue with the C library or migrate to Rust? |
|
@CurtizJ, first, we will merge the C library update to eat the backward incompatible changes and get the new baseline. Then, merge the Rust library if it is better for us. |
| res_data[row_num] = h3_index; | ||
|
|
||
| if (res_data[row_num] == 0) | ||
| if (err || res_data[row_num] == 0) |
There was a problem hiding this comment.
stringToH3 now explicitly checks H3Error and throws on invalid input, but the function docs still claim it returns 0 for invalid strings. This creates a user-visible contract mismatch.
Please update the ReturnedValue text to say it throws an exception for invalid input (or change implementation to match docs).
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 94.01% (204/217, 0 noise lines excluded) |
The CI Docker image installs an uninstrumented `fips.so` (built from stock OpenSSL 3.1.2) that gets loaded during OpenSSL global initialization. Sanitizers cannot track writes from uninstrumented shared libraries, causing false positives — currently MSan reports "use-of-uninitialized-value" in `OPENSSL_LH_retrieve` inside `fips.so`, crashing the unit test binary before any tests run. This has been a latent issue since FIPS was added to the Docker image (June 2025), but only manifested now due to a link order change from ClickHouse#100348 (H3 library upgrade) which shifted global constructor ordering so that `sqid.cpp`'s `DEFAULT_BLOCKLIST` initialization poisons stack memory before `curl.cpp`'s global constructor loads the FIPS provider. Set `OPENSSL_CONF=/dev/null` for all sanitizer builds to prevent loading the uninstrumented FIPS provider. https://s3.amazonaws.com/clickhouse-test-reports/PRs/100798/f39aa9f209bb3760611b2bcb6eff737dad3b6f21/unit_tests_msan/job.log Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
alexbakharew
left a comment
There was a problem hiding this comment.
Just few clarifications about incompatible changes
| res = gridPathCellsSize(start, end); | ||
| { | ||
| int64_t distance = 0; | ||
| if (!gridDistance(start, end, &distance)) |
There was a problem hiding this comment.
@alexey-milovidov Hi, this comment looks meaningful, could you please double check?
| res_data[row_num] = h3_index; | ||
|
|
||
| if (res_data[row_num] == 0) | ||
| if (err || res_data[row_num] == 0) |
| @@ -1,28 +1,28 @@ | |||
| 6 | |||
There was a problem hiding this comment.
This is true.
@alexey-milovidov Should we mention this somewhere? We call different function right now
The H3 C library fork (github.com/ClickHouse/h3) was on v3.7.1 with 2 ClickHouse-specific range-check patches. Upstream H3 v4 already includes equivalent validation in
_h3ToFaceIjk, so the patches are no longer needed.Created a clean
clickhouse-v4branch in the fork at upstream tag v4.4.1 with no additional patches.This fixes two known bugs in the v3 lookup tables:
The v4 API changed most functions to return
H3Errorwith results via output parameters. Updated all 27 wrapper files insrc/Functions/to use the new calling convention. Also updated function renames:exactEdgeLengthM→edgeLengthM,distanceM→greatCircleDistanceM, etc.Updated 11 test reference files to reflect the corrected values.
Reference: #100272
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The H3 library has been updated to v4, which improves the precision of length, area, and other metric calculations. This change is backward incompatible because the new results differ from previous ones.
Version info
26.4.1.270