Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of filter_dict #2063

Merged
merged 2 commits into from Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions arrow/src/array/array_dictionary.rs
Expand Up @@ -151,6 +151,28 @@ impl<K: ArrowPrimitiveType> DictionaryArray<K> {
Ok(array.into())
}

/// Create a new DictionaryArray directly from specified keys
/// (indexes into the dictionary) and values (dictionary)
/// array, and the corresponding ArrayData. This is used internally
/// for the usage like filter kernel.
///
/// # Safety
///
/// The input keys, values and data must form a valid DictionaryArray,
/// or undefined behavior can occur.
pub(crate) unsafe fn try_new_unchecked(
keys: PrimitiveArray<K>,
values: ArrayRef,
data: ArrayData,
) -> Self {
Self {
data,
keys,
values,
is_ordered: false,
}
}

/// Return an array view of the keys of this dictionary as a PrimitiveArray.
pub fn keys(&self) -> &PrimitiveArray<K> {
&self.keys
Expand Down
8 changes: 7 additions & 1 deletion arrow/src/compute/kernels/filter.rs
Expand Up @@ -786,7 +786,13 @@ where
)
};

DictionaryArray::<T>::from(data)
unsafe {
DictionaryArray::<T>::try_new_unchecked(
filtered_keys,
array.values().clone(),
data,
)
}
}

#[cfg(test)]
Expand Down