Jefffrey commented on code in PR #23456:
URL: https://github.com/apache/datafusion/pull/23456#discussion_r3562722860
##########
datafusion/functions/src/encoding/inner.rs:
##########
@@ -459,6 +455,45 @@ impl Encoding {
}
}
+/// Hex-encode a binary array into a string array, writing the lowercase hex
+/// digits directly into a single pre-sized value buffer. Each input byte maps
+/// to exactly two hex characters, so the output size is known up front and no
+/// per-element `String` is allocated.
+fn hex_encode_array<'a, InputBinaryArray, OutputOffset>(
+ array: &InputBinaryArray,
+) -> Result<ArrayRef>
+where
+ InputBinaryArray: BinaryArrayType<'a>,
+ OutputOffset: OffsetSizeTrait,
+{
+ let total_input_bytes: usize = array.iter().flatten().map(|v|
v.len()).sum();
+
+ let mut values = vec![0u8; total_input_bytes * 2];
+ let mut offsets = Vec::<OutputOffset>::with_capacity(array.len() + 1);
+ offsets.push(OutputOffset::zero());
+
+ let mut pos = 0usize;
+ for v in array.iter() {
+ if let Some(v) = v {
+ let out_len = v.len() * 2;
+ // The slice is sized to exactly `2 * v.len()`, which is the only
+ // condition under which `encode_to_slice` can fail, so this cannot
+ // error.
+ hex::encode_to_slice(v, &mut values[pos..pos + out_len])
Review Comment:
i remember we did some work previously on having a faster hex encoding
algorithm (iirc for Spark functions)
would that be applicable here too?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]