You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "floze-the-genius (via GitHub)" <gi...@apache.org> on 2026/07/18 11:07:21 UTC
[PR] Optimize Spark hex null handling [datafusion]
floze-the-genius opened a new pull request, #23688:
URL: https://github.com/apache/datafusion/pull/23688
## Which issue does this PR close?
- Closes #23674.
## Rationale for this change
Spark hex encoding preserves input validity exactly, but the byte-array path rebuilt the null bitmap row by row and always iterated through `Option` values. The input arrays already expose both the original `NullBuffer` and an all-valid fast path.
## What changes are included in this PR?
- pass the byte array accessor into `hex_encode_bytes` so the output can clone and reuse the input `NullBuffer`
- split nullable and no-null loops, avoiding per-row validity checks when the input has no null buffer
- preserve exact offset, overflow, casing, dictionary, and null semantics
- add a sliced-array regression that verifies semantic equality and bitmap pointer reuse
- add no-null output coverage and dedicated UTF-8/binary Criterion cases
## Are these changes tested?
Yes.
- `cargo test -p datafusion-spark function::math::hex --lib`: 10 passed
- `cargo fmt --all -- --check`: passed
- `cargo clippy -p datafusion-spark --all-targets --all-features --no-deps -- -D warnings`: passed
- `git diff --check`: passed
- benchmark target compiled with `--features core`
The workspace dependency clippy invocation without `--no-deps` reaches an unrelated existing `dead_code` warning in `datafusion/physical-expr/src/expressions/dynamic_filters/mod.rs:464`; the changed crate is clean.
### Benchmark
Command (same warmed build and profile for upstream `main` and this branch):
```bash
CARGO_BUILD_JOBS=2 \
CARGO_PROFILE_BENCH_LTO=false \
CARGO_PROFILE_BENCH_CODEGEN_UNITS=16 \
cargo bench -p datafusion-spark --features core --bench hex -- \
'hex_(utf8|binary)_no_nulls'
```
Mean times from the immediate upstream-then-branch sequence:
| case | upstream main | this PR | change |
| --- | ---: | ---: | ---: |
| UTF-8, 1,024 rows | 79.895 us | 59.181 us | -25.9% |
| UTF-8, 4,096 rows | 317.64 us | 244.88 us | -22.9% |
| UTF-8, 8,192 rows | 509.64 us | 411.27 us | -19.3% |
| Binary, 1,024 rows | 86.135 us | 40.600 us | -52.9% |
| Binary, 4,096 rows | 346.16 us | 253.13 us | -26.9% |
| Binary, 8,192 rows | 635.98 us | 424.78 us | -33.2% |
## Are there any user-facing changes?
No API or behavior changes. This is an internal performance optimization for Spark-compatible hex expressions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Optimize Spark hex null handling [datafusion]
Posted by "floze-the-genius (via GitHub)" <gi...@apache.org>.
floze-the-genius commented on PR #23688:
URL: https://github.com/apache/datafusion/pull/23688#issuecomment-5116805744
Rebased onto current main and resolved the conflict while keeping the shared `encode_bytes_into` / `encode_u64` helpers. I also added the requested dictionary-backed Binary regression where `dict.values()` contains a null. Validation: `cargo test -p datafusion-spark function::math::hex --lib` (11 passed), `cargo fmt --all -- --check`, and `cargo clippy -p datafusion-spark --all-targets --all-features --no-deps -- -D warnings`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Optimize Spark hex null handling [datafusion]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #23688:
URL: https://github.com/apache/datafusion/pull/23688#issuecomment-5011142246
## [Codecov](https://app.codecov.io/gh/apache/datafusion/pull/23688?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `71.08434%` with `24 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 80.67%. Comparing base ([`1734d4b`](https://app.codecov.io/gh/apache/datafusion/commit/1734d4beb4440b1cd34c4d22fbccd3ef9cac0808?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`4e9f34a`](https://app.codecov.io/gh/apache/datafusion/commit/4e9f34ac176cdef77aba4b593207efe702391879?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
| [Files with missing lines](https://app.codecov.io/gh/apache/datafusion/pull/23688?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [datafusion/spark/src/function/math/hex.rs](https://app.codecov.io/gh/apache/datafusion/pull/23688?src=pr&el=tree&filepath=datafusion%2Fspark%2Fsrc%2Ffunction%2Fmath%2Fhex.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9zcGFyay9zcmMvZnVuY3Rpb24vbWF0aC9oZXgucnM=) | 71.08% | [12 Missing and 12 partials :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/23688?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## main #23688 +/- ##
==========================================
- Coverage 80.67% 80.67% -0.01%
==========================================
Files 1087 1087
Lines 367541 367560 +19
Branches 367541 367560 +19
==========================================
- Hits 296529 296524 -5
- Misses 53355 53367 +12
- Partials 17657 17669 +12
```
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/datafusion/pull/23688?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Optimize Spark hex null handling [datafusion]
Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew commented on PR #23688:
URL: https://github.com/apache/datafusion/pull/23688#issuecomment-5088812306
@floze-the-genius
Can you resolve the merge conflicts?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Optimize Spark hex null handling [datafusion]
Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew merged PR #23688:
URL: https://github.com/apache/datafusion/pull/23688
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Optimize Spark hex null handling [datafusion]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on PR #23688:
URL: https://github.com/apache/datafusion/pull/23688#issuecomment-5060284207
may be related to #23766
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Optimize Spark hex null handling [datafusion]
Posted by "floze-the-genius (via GitHub)" <gi...@apache.org>.
floze-the-genius commented on code in PR #23688:
URL: https://github.com/apache/datafusion/pull/23688#discussion_r3673503469
##########
datafusion/spark/src/function/math/hex.rs:
##########
@@ -340,27 +330,27 @@ pub fn compute_hex(
}
DataType::Utf8 => {
let arr = as_string_array(dict_values);
- hex_encode_bytes(arr.iter(), lowercase, arr.len())?
+ hex_encode_bytes(&arr, lowercase)?
}
DataType::LargeUtf8 => {
let arr = as_largestring_array(dict_values);
- hex_encode_bytes(arr.iter(), lowercase, arr.len())?
+ hex_encode_bytes(&arr, lowercase)?
}
DataType::Utf8View => {
let arr = as_string_view_array(dict_values)?;
- hex_encode_bytes(arr.iter(), lowercase, arr.len())?
+ hex_encode_bytes(&arr, lowercase)?
}
DataType::Binary => {
Review Comment:
Added `test_dict_binary_values_null` in `af3fafa65`. It uses dictionary keys `[0, null, 1]` with Binary values `[b"hi", null]` and verifies the encoded dictionary preserves the null value.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Optimize Spark hex null handling [datafusion]
Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew commented on code in PR #23688:
URL: https://github.com/apache/datafusion/pull/23688#discussion_r3655344999
##########
datafusion/spark/src/function/math/hex.rs:
##########
@@ -340,27 +330,27 @@ pub fn compute_hex(
}
DataType::Utf8 => {
let arr = as_string_array(dict_values);
- hex_encode_bytes(arr.iter(), lowercase, arr.len())?
+ hex_encode_bytes(&arr, lowercase)?
}
DataType::LargeUtf8 => {
let arr = as_largestring_array(dict_values);
- hex_encode_bytes(arr.iter(), lowercase, arr.len())?
+ hex_encode_bytes(&arr, lowercase)?
}
DataType::Utf8View => {
let arr = as_string_view_array(dict_values)?;
- hex_encode_bytes(arr.iter(), lowercase, arr.len())?
+ hex_encode_bytes(&arr, lowercase)?
}
DataType::Binary => {
Review Comment:
Could we add a small regression test for a dictionary-backed Binary or LargeBinary array where `dict.values()` itself contains a null, rather than only testing null dictionary keys? The new byte-array path preserves the values array `NullBuffer` directly. We already cover this shape for `Int64` in `test_dict_values_null`, so matching binary coverage would help pin down this updated path. This is optional and does not need to block the PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org