Converts an iterator of hex strings to a binary array.
(
iter: I,
len: usize,
capacity: usize,
)
| 111 | |
| 112 | /// Converts an iterator of hex strings to a binary array. |
| 113 | fn unhex_array<I, T>( |
| 114 | iter: I, |
| 115 | len: usize, |
| 116 | capacity: usize, |
| 117 | ) -> Result<ArrayRef, DataFusionError> |
| 118 | where |
| 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 |
| 143 | fn unhex_scalar(s: &str) -> Option<Vec<u8>> { |
no test coverage detected
searching dependent graphs…