with_hashes

Function with_hashes 

Source
pub fn with_hashes<I, T, F, R>(
    arrays: I,
    random_state: &RandomState,
    callback: F,
) -> Result<R>
where I: IntoIterator<Item = T>, T: AsDynArray, F: FnOnce(&[u64]) -> Result<R>,
Expand description

Creates hashes for the given arrays using a thread-local buffer, then calls the provided callback with an immutable reference to the computed hashes.

This function manages a thread-local buffer to avoid repeated allocations. The buffer is automatically truncated if it exceeds MAX_BUFFER_SIZE after use.

§Arguments

  • arrays - The arrays to hash (must contain at least one array)
  • random_state - The random state for hashing
  • callback - A function that receives an immutable reference to the hash slice and returns a result

§Errors

Returns an error if:

  • No arrays are provided
  • The function is called reentrantly (i.e., the callback invokes with_hashes again on the same thread)
  • The function is called during or after thread destruction

§Example

use datafusion_common::hash_utils::{with_hashes, RandomState};
use arrow::array::{Int32Array, ArrayRef};
use std::sync::Arc;

let array: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 3]));
let random_state = RandomState::new();

let result = with_hashes([&array], &random_state, |hashes| {
    // Use the hashes here
    Ok(hashes.len())
})?;