Add Java bindings for the remaining libcudf hash functions #25394
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.
Contributors can view more details about this message here.
Please use the getNativeViews helper here and for md5 and wherever needed for alignment and less repetition.
Maybe declare this higher up in the file, before it's used?
Do we need the same auto_set_device in sha1 and md5 and others above?
Done in 1a91873c8e
Done in 1a91873c8e
Yes, done in 1a91873c8e. md5 and sha1 were the only JNI entry points in ColumnVectorJni.cpp without it, so they could run on the wrong device when the calling thread had a different current device.
/ok to test 1a91873c8e3b8eeca9aebe3e7920817f114ad099
<!-- coderabbit-ai-generated:v1 -->
<!-- This is an auto-generated comment: summarize by coderabbit.ai -->
<!-- review_stack_entry_start -->
<a href="https://app.coderabbit.ai/change-stack/NVIDIA/cudf/pull/25394?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg" alt="Explain Change →" height="32"></picture></a>
<!-- review_stack_entry_end -->
<!-- recent_review_status_start -->
No actionable comments were generated in the recent review.
<!-- recent_review_status_end -->
<!-- walkthrough_start -->
<details>
<summary><strong>Summary</strong></summary>
<dl>
<dd>
<br>
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
New Features
Added SHA-224, SHA-256, SHA-384, and SHA-512 hashing, along with seeded XXHash and MurmurHash options.
Added support for hashing multiple columns and for Trino- and Spark-compatible hash variants.
Bug Fixes
Hash operations now set the active device before processing columns.
Hashing requires at least one column; invalid inputs are rejected.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->ColumnVector adds Java entry points for SHA-224/256/384/512, MurmurHash variants, and xxHash variants. JNI implements these hash calls and selects the active device. Tests check expected outputs, seeds, null rows, multiple columns, and byte-list inputs.
Changes: Java hash bindings
|Layer / File(s)|Summary|
|:---|:---|
|Hash API and shared input handling <br> java/src/main/java/ai/rapids/cudf/ColumnVector.java|A shared helper validates hash inputs and collects native views. New Java entry points and native declarations cover SHA-224/256/384/512, MurmurHash variants, and xxHash variants. MD5 retains its type assertions, and SHA-1 uses the shared helper.|
|JNI hash implementations <br> java/src/main/native/src/ColumnVectorJni.cpp|JNI adds implementations for the new hash methods. The MD5 and SHA-1 methods also select the active device before accessing column views.|
|Hash output and input tests <br> java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java|Tests check expected hashes for strings, seeded variants, multiple columns, and Trino-compatible VARCHAR and VARBINARY inputs. They also check null rows and the empty-input exception for seeded XXHash64.|
<!-- change_assessment_start -->
Estimated code review effort: 3 (Moderate) | ~25 minutes
<!-- change_assessment_commit:"1a91873c8e3b8eeca9aebe3e7920817f114ad099" -->
<!-- change_assessment_priority:{"version":1,"urgency":"p2","manual":false} -->
Change: Feature
<!-- change_assessment_end -->
Possibly related issues
Suggested reviewers: rishic3, ttnghia
</dd>
</dl>
</details>
<!-- walkthrough_end -->
<details>
<summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-unassessed-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minimal</strong> · up to <code>1a918</code></summary>
<dl>
<dd>
<br>
<!-- final_review_risk_start -->
<!-- final_review_risk_label
Merge Risk: ⚪ Minimal · up to 1a918
-->
<!-- final_review_risk_coverage:{"sourceCommitId":"1a91873c8e3b8eeca9aebe3e7920817f114ad099","coveredCommitId":"1a91873c8e3b8eeca9aebe3e7920817f114ad099","kind":"reviewed"} -->
This change adds Java bindings for the SHA-2, MurmurHash and xxHash functions already present in libcudf, and moves MD5 and SHA-1 onto shared input checks. No concrete defect was found, and the added tests cover the main input and seed cases. Merge-readiness risk is minimal, subject to the normal CI GPU test run.
<!-- final_review_risk_end -->
</dd>
</dl>
</details>
<details>
<summary><strong>Security architecture risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-unassessed-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minimal</strong> · up to <code>1a918</code></summary>
<dl>
<dd>
<br>
<!-- architecture_review_start -->
<!-- architecture_review_label
Security Architecture Review
Security architecture risk: ⚪ Minimal · up to 1a918
-->
The added hashing APIs follow the existing Java-to-native execution and resource-ownership model. The inspected changes do not establish a material weakening of security, failure containment, or ownership guarantees.
Retained concerns
No architecture-level concerns identified.
<details>
<summary><strong>Security review details</strong></summary>
<dl>
<dd>
<br>
Security Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
</dd>
</dl>
</details>
<!-- architecture_review_end -->
</dd>
</dl>
</details>
<!-- pre_merge_checks_walkthrough_start -->
<details>
<summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4</strong></summary>
<dl>
<dd>
<br>
| Check name | Status | Explanation |
| :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Title check | !Passed | The title states the main change: adding Java ColumnVector bindings for the remaining libcudf hash functions. The raw summary confirms the SHA-224/256/384/512, MurmurHash, and xxHash bindings and thei… |
| Description check | !Passed | The description states that cuDF Java exposed only md5Hash and sha1Hash and lists the new ColumnVector bindings (SHA-2 variants, MurmurHash3 variants, xxhash32/64). This matches the raw summary of the… |
| Linked Issues check | !Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | !Passed | Check skipped because no linked issues were found for this pull request. |
<details>
<summary><strong>Full details: Title check</strong></summary>
<dl>
<dd>
<br>
Explanation
The title states the main change: adding Java ColumnVector bindings for the remaining libcudf hash functions. The raw summary confirms the SHA-224/256/384/512, MurmurHash, and xxHash bindings and their JNI methods. The title is specific and concise.
</dd>
</dl>
</details>
<details>
<summary><strong>Full details: Description check</strong></summary>
<dl>
<dd>
<br>
Explanation
The description states that cuDF Java exposed only md5Hash and sha1Hash and lists the new ColumnVector bindings (SHA-2 variants, MurmurHash3 variants, xxhash32/64). This matches the raw summary of the ColumnVector, JNI, and test changes. It also explains the seed handling and the xxHash64 verification approach.
</dd>
</dl>
</details>
</dd>
</dl>
</details>
<!-- pre_merge_checks_walkthrough_end -->
<!-- finishing_touch_checkbox_start -->
<details>
<summary><strong>Finishing Touches</strong></summary>
<dl>
<dd>
<br>
<details open>
<summary><strong>Generate unit tests (beta)</strong></summary>
<dl>
<dd>
<br>
</dd>
</dl>
</details>
</dd>
</dl>
</details>
<!-- finishing_touch_checkbox_end -->
<!-- autopilot:start -->
<!-- autopilot:end -->
<!-- recent_review_start -->
<h6>
<details>
<summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Recent review info</strong></summary>
<dl>
<dd>
<br>
<!-- review_info_content -->
<details>
<summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</strong></summary>
<dl>
<dd>
<br>
69addc5d-089d-437e-8699-84a84d734d53</dd>
</dl>
</details>
<details>
<summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</strong></summary>
<dl>
<dd>
<br>
Reviewing files that changed from the base of the PR and between a8434b630df6c73f2caf4c5166c72b4072ee5583 and 1a91873c8e3b8eeca9aebe3e7920817f114ad099.
</dd>
</dl>
</details>
<details>
<summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 3</strong></summary>
<dl>
<dd>
<br>
java/src/main/java/ai/rapids/cudf/ColumnVector.java
java/src/main/native/src/ColumnVectorJni.cpp
java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java</dd>
</dl>
</details>
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.
</dd>
</dl>
</details>
</h6>
<!-- recent_review_end -->
IMO the library API should be engine agnostic. The reader wanting to use this function should not have to look up what spark murmur is. Also, if future Spark version changes their hash or combine functions, the semantics of this method cannot silently change.
Can you name and document the API in engine agnostic terms? This can be supplemented with "This is the same algorithm that Spark v X.Y.Z's .... does."
If this check didn't exist, what would sha1Hash(new ColumnView[0]) return?
SHA-256 is well defined over bytes. Table != bytes.
This function -- and every other hash function -- should define how a row is converted into bytes, including how individual cells are combined. For example: is ["a", "bc"] row converted to same bytes as ["ab","c"]? Or maybe the SHA-256 of each cell is combined with some custom combining function? How are numbers, including floats and decimals, converted to bytes to the purpose of hashing? How are structs and lists?
These are all questions a user of this API should be able to answer from reading the javadoc, and without reading the code.
The javadoc here doesn't fully say how the hash is obtained. For example, the reader doesn't know whether list<uint8> is hashed as series of consecutive bytes (the way https://github.com/NVIDIA/cudf/pull/25357 wanted it), or differently (which I guess is the case).
Could you add a test for xxhash64 over a single INT64 column, checked against reference XXH64 values with seed 0 (e.g. 0, -1, Long.MIN_VALUE, Long.MAX_VALUE)? That would pin down that a single fixed-width column hashes to the plain XXH64 of its 8 little-endian bytes.
Also, the NULL treatment should be documented.
I don't see why we actually need hashName here. If this throw, we always have the stacktrace in Java.
bdice
Description
cuDF Java exposed only
md5Hashandsha1Hashfromcudf/hashing.hpp. This addsColumnVectorbindings for the rest:sha224Hash,sha256Hash,sha384Hash,sha512Hash,murmurHash3x86_32,sparkMurmurHash3x86_32,murmurHash3x64_128(returns a two-columnTable),xxhash32andxxhash64. Seeds are Javaint/longwhose bits are passed to libcudf as unsigned, matching the C++ seed widths.For a single STRING column, libcudf's xxHash64 is the reference XXH64 of each row's UTF-8 bytes, which the tests check against Python's
xxhash. This covers the use case in #25314 without a new libcudf API.xref #25314, #25357
Checklist