Skip to content

Commit

Permalink
add flag
Browse files Browse the repository at this point in the history
  • Loading branch information
st1page committed Mar 14, 2024
1 parent e3a35fe commit e1d3d43
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/batch/src/task/hash_shuffle_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn generate_hash_values(chunk: &DataChunk, hash_info: &HashInfo) -> BatchResult<
.map(|idx| *idx as usize)
.collect::<Vec<_>>(),
hasher_builder,
false
false,
)
.iter_mut()
.map(|hash_value| hash_value.value() as usize % output_count)
Expand Down
17 changes: 11 additions & 6 deletions src/common/src/array/data_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,20 +344,25 @@ impl DataChunk {
Ok(outputs)
}

/// Compute hash values for each row. The number of the HashCodes is `self.capacity()`.
/// When skip_invisible_row is true, the HashCode for the invisible rows is arbitrary.
/// Compute hash values for each row. The number of the returning `HashCodes` is `self.capacity()`.
/// When `skip_invisible_row` is true, the `HashCode` for the invisible rows is arbitrary.
pub fn get_hash_values<H: BuildHasher>(
&self,
column_idxes: &[usize],
hasher_builder: H,
skip_invisible_row: bool
skip_invisible_row: bool,
) -> Vec<HashCode<H>> {
let mut states = Vec::with_capacity(self.capacity());
states.resize_with(self.capacity(), || hasher_builder.build_hasher());
let len = self.capacity();
let mut states = Vec::with_capacity(len);
states.resize_with(len, || hasher_builder.build_hasher());
// Compute hash for the specified columns.
for column_idx in column_idxes {
let array = self.column_at(*column_idx);
array.hash_vec(&mut states[..]);
if skip_invisible_row {
array.hash_vec(&mut states[..], self.visibility());
} else {
array.hash_vec(&mut states[..], &Bitmap::ones(len));
}
}
finalize_hashers(&states[..])
.into_iter()
Expand Down
14 changes: 8 additions & 6 deletions src/common/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@ pub trait Array:
}
}

fn hash_vec<H: Hasher>(&self, hashers: &mut [H]) {
fn hash_vec<H: Hasher>(&self, hashers: &mut [H], vis: &Bitmap) {
assert_eq!(hashers.len(), self.len());
for (idx, state) in hashers.iter_mut().enumerate() {
self.hash_at(idx, state);
for idx in vis.iter_ones() {
self.hash_at(idx, &mut hashers[idx]);
}
}

Expand Down Expand Up @@ -554,8 +554,8 @@ impl ArrayImpl {
dispatch_array_variants!(self, inner, { inner.hash_at(idx, state) })
}

pub fn hash_vec<H: Hasher>(&self, hashers: &mut [H]) {
dispatch_array_variants!(self, inner, { inner.hash_vec(hashers) })
pub fn hash_vec<H: Hasher>(&self, hashers: &mut [H], vis: &Bitmap) {
dispatch_array_variants!(self, inner, { inner.hash_vec(hashers, vis) })
}

/// Select some elements from `Array` based on `visibility` bitmap.
Expand Down Expand Up @@ -711,6 +711,7 @@ mod test_util {
use std::hash::{BuildHasher, Hasher};

use super::Array;
use crate::buffer::Bitmap;
use crate::util::iter_util::ZipEqFast;

pub fn hash_finish<H: Hasher>(hashers: &[H]) -> Vec<u64> {
Expand All @@ -732,8 +733,9 @@ mod test_util {
arr.hash_at(i, state)
}
});
let vis = Bitmap::ones(len);
arrs.iter()
.for_each(|arr| arr.hash_vec(&mut states_vec[..]));
.for_each(|arr| arr.hash_vec(&mut states_vec[..], &vis));
itertools::cons_tuples(
expects
.iter()
Expand Down

0 comments on commit e1d3d43

Please sign in to comment.