You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2022/10/08 09:16:13 UTC

[arrow-rs] branch master updated: Simplify filter_dict (#2831)

This is an automated email from the ASF dual-hosted git repository.

tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new 97480a97e Simplify filter_dict (#2831)
97480a97e is described below

commit 97480a97ec50c1df8c0dc31338216d808a6eb4e3
Author: Raphael Taylor-Davies <17...@users.noreply.github.com>
AuthorDate: Sat Oct 8 10:16:09 2022 +0100

    Simplify filter_dict (#2831)
---
 arrow/src/compute/kernels/filter.rs | 25 +++++++++----------------
 1 file changed, 9 insertions(+), 16 deletions(-)

diff --git a/arrow/src/compute/kernels/filter.rs b/arrow/src/compute/kernels/filter.rs
index d528b0632..d1e2ad175 100644
--- a/arrow/src/compute/kernels/filter.rs
+++ b/arrow/src/compute/kernels/filter.rs
@@ -660,22 +660,15 @@ where
     T: ArrowPrimitiveType,
     T::Native: num::Num,
 {
-    let filtered_keys = filter_primitive::<T>(array.keys(), predicate);
-    let filtered_data = filtered_keys.data_ref();
-
-    let data = unsafe {
-        ArrayData::new_unchecked(
-            array.data_type().clone(),
-            filtered_data.len(),
-            Some(filtered_data.null_count()),
-            filtered_data.null_buffer().cloned(),
-            filtered_data.offset(),
-            filtered_data.buffers().to_vec(),
-            array.data().child_data().to_vec(),
-        )
-    };
-
-    DictionaryArray::from(data)
+    let builder = filter_primitive::<T>(array.keys(), predicate)
+        .into_data()
+        .into_builder()
+        .data_type(array.data_type().clone())
+        .child_data(array.data().child_data().to_vec());
+
+    // SAFETY:
+    // Keys were valid before, filtered subset is therefore still valid
+    DictionaryArray::from(unsafe { builder.build_unchecked() })
 }
 
 #[cfg(test)]