ClickHouse icon indicating copy to clipboard operation
ClickHouse copied to clipboard

Add Spark-compatible xxHash64 function

Open lalitium opened this issue 5 months ago • 3 comments

Closes: https://github.com/ClickHouse/ClickHouse/issues/107847

Adds xxHash64Spark, a Spark-compatible variant of xxHash64 that uses seed 42 and returns Int64. This helps users compare or migrate hashes produced by Spark's xxhash64 without manual conversion.

Changelog category (leave one):

  • New Feature

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

Added function xxHash64Spark, which computes Spark-compatible xxHash64 values using seed 42 and returns Int64.

lalitium avatar Jun 25 '26 03:06 lalitium

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jun 25 '26 03:06 CLAassistant

@rschu1ze please provide the approval for the workflow. Thanks.

lalitium avatar Jun 25 '26 03:06 lalitium

Workflow [PR], commit [e6d95657]

Summary: ✅


AI Review

Summary

This PR adds xxHash64Spark as a single-argument String/NULL wrapper around xxHash64 with Spark's seed 42 and Int64 return type. The earlier arity, type, and NULL-handling problems are fixed, but the final implementation still leaves the signed Int64 projection to an implicit UInt64 -> Int64 conversion and the new test only covers a positive hash value, so the Spark Long contract is not fully pinned down yet.

Findings

⚠️ Majors

  • [src/Functions/FunctionsHashing.h:765] xxHash64Spark promises Spark's signed 64-bit result, but XXH_INLINE_XXH64 returns UInt64 and the current code relies on the later implicit conversion into ColumnVector<Int64> to reinterpret hashes above INT64_MAX. That conversion is implementation-defined, and the regression test does not cover any negative output (xxHash64Spark('a') is -8582455328737087284), so half of the hash space is only correct as a compiler assumption. Suggested fix: return an explicit Int64 bit reinterpretation here (for example with bit_cast<Int64>) and add a negative-value stateless test to lock in Spark's signed Long semantics.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: make the signed UInt64 -> Int64 mapping explicit in xxHash64Spark and add one negative-value regression test.

clickhouse-gh[bot] avatar Jun 25 '26 03:06 clickhouse-gh[bot]

@rschu1ze I have implemented spark-compatible xxHash64. Please take a look. Thanks.

lalitium avatar Jun 25 '26 20:06 lalitium

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.80% 85.80% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 77.90% 77.90% +0.00%

Changed lines: Changed C/C++ lines covered: 36/36 (100.00%) · Uncovered code

Full report · Diff report

clickhouse-gh[bot] avatar Jul 09 '26 21:07 clickhouse-gh[bot]