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

Function hash_union_array_default

datafusion/common/src/hash_utils.rs:744–775  ·  view source on GitHub ↗
(
    array: &UnionArray,
    union_fields: &UnionFields,
    random_state: &RandomState,
    hashes_buffer: &mut [u64],
)

Source from the content-addressed store, hash-verified

742/// this simpler approach is preferred.
743#[cfg(not(feature = "force_hash_collisions"))]
744fn hash_union_array_default(
745 array: &UnionArray,
746 union_fields: &UnionFields,
747 random_state: &RandomState,
748 hashes_buffer: &mut [u64],
749) -> Result<()> {
750 let mut child_hashes: HashMap<i8, Vec<u64>> =
751 HashMap::with_capacity(union_fields.len());
752
753 // Hash each child array fully
754 for (type_id, _field) in union_fields.iter() {
755 let child = array.child(type_id);
756 let mut child_hash_buffer = vec![0; child.len()];
757 create_hashes([child], random_state, &mut child_hash_buffer)?;
758
759 child_hashes.insert(type_id, child_hash_buffer);
760 }
761
762 // Combine hashes for each row using the appropriate child offset
763 // For dense unions: value_offset points to the actual position in the child
764 // For sparse unions: value_offset equals the row index
765 #[expect(clippy::needless_range_loop)]
766 for i in 0..array.len() {
767 let type_id = array.type_id(i);
768 let child_offset = array.value_offset(i);
769
770 let child_hash = child_hashes.get(&type_id).expect("invalid type_id");
771 hashes_buffer[i] = combine_hashes(hashes_buffer[i], child_hash[child_offset]);
772 }
773
774 Ok(())
775}
776
777/// Hash a sparse union array.
778/// Sparse unions have child arrays with the same length as the union array.

Callers 2

hash_union_arrayFunction · 0.85
hash_sparse_union_arrayFunction · 0.85

Calls 6

create_hashesFunction · 0.85
combine_hashesFunction · 0.85
lenMethod · 0.45
iterMethod · 0.45
insertMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…