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

Function sha2_binary_bitlen_iter

datafusion/spark/src/function/hash/sha2.rs:210–247  ·  view source on GitHub ↗
(
    values: &BinaryArrType,
    bit_lengths: I,
)

Source from the content-addressed store, hash-verified

208}
209
210fn sha2_binary_bitlen_iter<'a, BinaryArrType, I>(
211 values: &BinaryArrType,
212 bit_lengths: I,
213) -> ArrayRef
214where
215 BinaryArrType: BinaryArrayType<'a>,
216 I: Iterator<Item = Option<i32>>,
217{
218 let array = values
219 .iter()
220 .zip(bit_lengths)
221 .map(|(value, bit_length)| match (value, bit_length) {
222 (Some(value), Some(224)) => {
223 let mut digest = sha2::Sha224::default();
224 digest.update(value);
225 Some(hex_encode(digest.finalize()))
226 }
227 (Some(value), Some(0 | 256)) => {
228 let mut digest = sha2::Sha256::default();
229 digest.update(value);
230 Some(hex_encode(digest.finalize()))
231 }
232 (Some(value), Some(384)) => {
233 let mut digest = sha2::Sha384::default();
234 digest.update(value);
235 Some(hex_encode(digest.finalize()))
236 }
237 (Some(value), Some(512)) => {
238 let mut digest = sha2::Sha512::default();
239 digest.update(value);
240 Some(hex_encode(digest.finalize()))
241 }
242 // Unknown bit-lengths go to null, same as in Spark
243 _ => None,
244 })
245 .collect::<StringArray>();
246 Arc::new(array)
247}
248
249const HEX_CHARS: [u8; 16] = *b"0123456789abcdef";
250

Callers 2

sha2_binary_implFunction · 0.85

Calls 6

newFunction · 0.85
finalizeMethod · 0.80
hex_encodeFunction · 0.70
mapMethod · 0.45
iterMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…