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

Function hash_dictionary_inner

datafusion/common/src/hash_utils.rs:439–482  ·  view source on GitHub ↗
(
    array: &DictionaryArray<K>,
    random_state: &RandomState,
    hashes_buffer: &mut [u64],
)

Source from the content-addressed store, hash-verified

437#[cfg(not(feature = "force_hash_collisions"))]
438#[inline(never)]
439fn hash_dictionary_inner<
440 K: ArrowDictionaryKeyType,
441 const HAS_NULL_KEYS: bool,
442 const HAS_NULL_VALUES: bool,
443 const MULTI_COL: bool,
444>(
445 array: &DictionaryArray<K>,
446 random_state: &RandomState,
447 hashes_buffer: &mut [u64],
448) -> Result<()> {
449 // Hash each dictionary value once, and then use that computed
450 // hash for each key value to avoid a potentially expensive
451 // redundant hashing for large dictionary elements (e.g. strings)
452 let dict_values = array.values();
453 let mut dict_hashes = vec![0; dict_values.len()];
454 create_hashes([dict_values], random_state, &mut dict_hashes)?;
455
456 if HAS_NULL_KEYS {
457 for (hash, key) in hashes_buffer.iter_mut().zip(array.keys().iter()) {
458 if let Some(key) = key {
459 let idx = key.as_usize();
460 if !HAS_NULL_VALUES || dict_values.is_valid(idx) {
461 if MULTI_COL {
462 *hash = combine_hashes(dict_hashes[idx], *hash);
463 } else {
464 *hash = dict_hashes[idx];
465 }
466 }
467 }
468 }
469 } else {
470 for (hash, key) in hashes_buffer.iter_mut().zip(array.keys().values()) {
471 let idx = key.as_usize();
472 if !HAS_NULL_VALUES || dict_values.is_valid(idx) {
473 if MULTI_COL {
474 *hash = combine_hashes(dict_hashes[idx], *hash);
475 } else {
476 *hash = dict_hashes[idx];
477 }
478 }
479 }
480 }
481 Ok(())
482}
483
484/// Hash the values in a dictionary array
485#[cfg(not(feature = "force_hash_collisions"))]

Callers

nothing calls this directly

Calls 6

create_hashesFunction · 0.85
combine_hashesFunction · 0.85
valuesMethod · 0.45
iterMethod · 0.45
as_usizeMethod · 0.45
is_validMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…