MCPcopy Create free account
hub / github.com/apache/datafusion / hex_encode_bytes

Function hex_encode_bytes

datafusion/spark/src/function/math/hex.rs:160–195  ·  view source on GitHub ↗

Generic hex encoding for byte array types

(
    iter: I,
    lowercase: bool,
    len: usize,
)

Source from the content-addressed store, hash-verified

158
159/// Generic hex encoding for byte array types
160fn hex_encode_bytes<'a, I, T>(
161 iter: I,
162 lowercase: bool,
163 len: usize,
164) -> Result<ArrayRef, DataFusionError>
165where
166 I: Iterator<Item = Option<T>>,
167 T: AsRef<[u8]> + 'a,
168{
169 let mut builder = StringBuilder::with_capacity(len, len * 64);
170 let mut buffer = Vec::with_capacity(64);
171 let lookup = if lowercase {
172 &HEX_LOOKUP_LOWER
173 } else {
174 &HEX_LOOKUP_UPPER
175 };
176
177 for v in iter {
178 if let Some(b) = v {
179 let bytes = b.as_ref();
180 buffer.clear();
181 buffer.reserve(bytes.len() * 2);
182 for &byte in bytes {
183 buffer.extend_from_slice(&lookup[byte as usize]);
184 }
185 // SAFETY: buffer contains only ASCII hex digits, which are valid UTF-8.
186 unsafe {
187 builder.append_value(from_utf8_unchecked(&buffer));
188 }
189 } else {
190 builder.append_null();
191 }
192 }
193
194 Ok(Arc::new(builder.finish()))
195}
196
197/// Generic hex encoding for int64 type
198fn hex_encode_int64(

Callers 1

compute_hexFunction · 0.85

Calls 8

newFunction · 0.85
reserveMethod · 0.80
as_refMethod · 0.45
clearMethod · 0.45
lenMethod · 0.45
append_valueMethod · 0.45
append_nullMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…