You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem or challenge?
Follow-on from review feedback on #23473, which rewrote hex_encode_bytes (datafusion/spark/src/function/math/hex.rs) to write hex digits directly into a single value buffer. Two further optimizations were suggested during review but left out of that PR to keep it focused:
Reuse the input NullBuffer instead of rebuilding one. The current implementation constructs a fresh NullBufferBuilder and calls append_null/append_non_null per row. Since hex encoding is 1:1 with the input rows (a null in maps to a null out), the output nulls are identical to the input's. We could clone the input array's NullBuffer directly instead of rebuilding it. This requires plumbing the input array (or its nulls) through to hex_encode_bytes, which currently only receives an Iterator<Item = Option<T>> and has no access to the underlying NullBuffer.
Special-case the "no nulls" path. When the input NullBuffer is None, there is no need to check each value for Some/None. We could split into two loops — one tight loop for the no-nulls case and one for the has-nulls case.
Is your feature request related to a problem or challenge?
Follow-on from review feedback on #23473, which rewrote
hex_encode_bytes(datafusion/spark/src/function/math/hex.rs) to write hex digits directly into a single value buffer. Two further optimizations were suggested during review but left out of that PR to keep it focused:Reuse the input
NullBufferinstead of rebuilding one. The current implementation constructs a freshNullBufferBuilderand callsappend_null/append_non_nullper row. Since hex encoding is 1:1 with the input rows (a null in maps to a null out), the output nulls are identical to the input's. We could clone the input array'sNullBufferdirectly instead of rebuilding it. This requires plumbing the input array (or its nulls) through tohex_encode_bytes, which currently only receives anIterator<Item = Option<T>>and has no access to the underlyingNullBuffer.Special-case the "no nulls" path. When the input
NullBufferisNone, there is no need to check each value forSome/None. We could split into two loops — one tight loop for the no-nulls case and one for the has-nulls case.Describe the solution you'd like
Refactor
hex_encode_bytesindatafusion/spark/src/function/math/hex.rsto:NullBuffer) so the output nulls can be cloned directly rather than rebuilt viaNullBufferBuilder.Optioncheck when the input has no nulls.Validate with the existing
datafusion/spark/benches/hex.rsbenchmark againstmain.Describe alternatives you've considered
Leaving the implementation as-is; it already avoids the per-row copy that #23473 targeted. These are incremental improvements on top of that.
Additional context
Both suggestions came from review of #23473.