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

Function unhex_array

datafusion/spark/src/function/math/unhex.rs:113–140  ·  view source on GitHub ↗

Converts an iterator of hex strings to a binary array.

(
    iter: I,
    len: usize,
    capacity: usize,
)

Source from the content-addressed store, hash-verified

111
112/// Converts an iterator of hex strings to a binary array.
113fn unhex_array<I, T>(
114 iter: I,
115 len: usize,
116 capacity: usize,
117) -> Result<ArrayRef, DataFusionError>
118where
119 I: Iterator<Item = Option<T>>,
120 T: AsRef<str>,
121{
122 let mut builder = BinaryBuilder::with_capacity(len, capacity);
123 let mut buffer = Vec::new();
124
125 for v in iter {
126 if let Some(s) = v {
127 buffer.clear();
128 buffer.reserve(s.as_ref().len().div_ceil(2));
129 if unhex_common(s.as_ref().as_bytes(), &mut buffer) {
130 builder.append_value(&buffer);
131 } else {
132 builder.append_null();
133 }
134 } else {
135 builder.append_null();
136 }
137 }
138
139 Ok(Arc::new(builder.finish()))
140}
141
142/// Convert a single hex string to binary
143fn unhex_scalar(s: &str) -> Option<Vec<u8>> {

Callers 1

spark_unhexFunction · 0.85

Calls 9

newFunction · 0.85
unhex_commonFunction · 0.85
reserveMethod · 0.80
clearMethod · 0.45
lenMethod · 0.45
as_refMethod · 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…