From 0bd58de002d1344d7320b8e8c11c397709366775 Mon Sep 17 00:00:00 2001 From: "Jorge C. Leitao" Date: Sun, 30 Oct 2022 21:04:22 +0000 Subject: [PATCH] Optimized slice --- src/array/binary/mod.rs | 3 ++- src/array/boolean/mod.rs | 3 ++- src/array/fixed_size_binary/mod.rs | 3 ++- src/array/fixed_size_list/mod.rs | 3 ++- src/array/list/mod.rs | 3 ++- src/array/map/mod.rs | 3 ++- src/array/primitive/mod.rs | 3 ++- src/array/struct_/mod.rs | 3 ++- src/array/utf8/mod.rs | 3 ++- 9 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/array/binary/mod.rs b/src/array/binary/mod.rs index c55bee2418d..ba68b5231b4 100644 --- a/src/array/binary/mod.rs +++ b/src/array/binary/mod.rs @@ -203,7 +203,8 @@ impl BinaryArray { let validity = self .validity .clone() - .map(|x| x.slice_unchecked(offset, length)); + .map(|bitmap| bitmap.slice_unchecked(offset, length)) + .and_then(|bitmap| (bitmap.unset_bits() > 0).then(|| bitmap)); let offsets = self.offsets.clone().slice_unchecked(offset, length + 1); Self { data_type: self.data_type.clone(), diff --git a/src/array/boolean/mod.rs b/src/array/boolean/mod.rs index 2c33ef155ab..d5fe08fbc04 100644 --- a/src/array/boolean/mod.rs +++ b/src/array/boolean/mod.rs @@ -167,7 +167,8 @@ impl BooleanArray { let validity = self .validity .clone() - .map(|x| x.slice_unchecked(offset, length)); + .map(|bitmap| bitmap.slice_unchecked(offset, length)) + .and_then(|bitmap| (bitmap.unset_bits() > 0).then(|| bitmap)); Self { data_type: self.data_type.clone(), values: self.values.clone().slice_unchecked(offset, length), diff --git a/src/array/fixed_size_binary/mod.rs b/src/array/fixed_size_binary/mod.rs index ab1a28beb08..d467d2c3c00 100644 --- a/src/array/fixed_size_binary/mod.rs +++ b/src/array/fixed_size_binary/mod.rs @@ -131,7 +131,8 @@ impl FixedSizeBinaryArray { let validity = self .validity .clone() - .map(|x| x.slice_unchecked(offset, length)); + .map(|bitmap| bitmap.slice_unchecked(offset, length)) + .and_then(|bitmap| (bitmap.unset_bits() > 0).then(|| bitmap)); let values = self .values .clone() diff --git a/src/array/fixed_size_list/mod.rs b/src/array/fixed_size_list/mod.rs index dac5f19c70a..c603f6bf6aa 100644 --- a/src/array/fixed_size_list/mod.rs +++ b/src/array/fixed_size_list/mod.rs @@ -150,7 +150,8 @@ impl FixedSizeListArray { let validity = self .validity .clone() - .map(|x| x.slice_unchecked(offset, length)); + .map(|bitmap| bitmap.slice_unchecked(offset, length)) + .and_then(|bitmap| (bitmap.unset_bits() > 0).then(|| bitmap)); let values = self .values .clone() diff --git a/src/array/list/mod.rs b/src/array/list/mod.rs index 819f6b1dd20..feb5a5df93b 100644 --- a/src/array/list/mod.rs +++ b/src/array/list/mod.rs @@ -222,7 +222,8 @@ impl ListArray { let validity = self .validity .clone() - .map(|x| x.slice_unchecked(offset, length)); + .map(|bitmap| bitmap.slice_unchecked(offset, length)) + .and_then(|bitmap| (bitmap.unset_bits() > 0).then(|| bitmap)); let offsets = self.offsets.clone().slice_unchecked(offset, length + 1); Self { data_type: self.data_type.clone(), diff --git a/src/array/map/mod.rs b/src/array/map/mod.rs index cc8a02c7ccd..51ca56a8459 100644 --- a/src/array/map/mod.rs +++ b/src/array/map/mod.rs @@ -167,7 +167,8 @@ impl MapArray { let validity = self .validity .clone() - .map(|x| x.slice_unchecked(offset, length)); + .map(|bitmap| bitmap.slice_unchecked(offset, length)) + .and_then(|bitmap| (bitmap.unset_bits() > 0).then(|| bitmap)); Self { data_type: self.data_type.clone(), offsets, diff --git a/src/array/primitive/mod.rs b/src/array/primitive/mod.rs index 2bbdbd05239..a35ae530a2e 100644 --- a/src/array/primitive/mod.rs +++ b/src/array/primitive/mod.rs @@ -233,7 +233,8 @@ impl PrimitiveArray { let validity = self .validity .clone() - .map(|x| x.slice_unchecked(offset, length)); + .map(|bitmap| bitmap.slice_unchecked(offset, length)) + .and_then(|bitmap| (bitmap.unset_bits() > 0).then(|| bitmap)); Self { data_type: self.data_type.clone(), values: self.values.clone().slice_unchecked(offset, length), diff --git a/src/array/struct_/mod.rs b/src/array/struct_/mod.rs index 3fb7be0c7b1..a371147f3d8 100644 --- a/src/array/struct_/mod.rs +++ b/src/array/struct_/mod.rs @@ -198,7 +198,8 @@ impl StructArray { let validity = self .validity .clone() - .map(|x| x.slice_unchecked(offset, length)); + .map(|bitmap| bitmap.slice_unchecked(offset, length)) + .and_then(|bitmap| (bitmap.unset_bits() > 0).then(|| bitmap)); Self { data_type: self.data_type.clone(), values: self diff --git a/src/array/utf8/mod.rs b/src/array/utf8/mod.rs index dc453a5c37b..2295d9c2439 100644 --- a/src/array/utf8/mod.rs +++ b/src/array/utf8/mod.rs @@ -220,7 +220,8 @@ impl Utf8Array { let validity = self .validity .clone() - .map(|x| x.slice_unchecked(offset, length)); + .map(|bitmap| bitmap.slice_unchecked(offset, length)) + .and_then(|bitmap| (bitmap.unset_bits() > 0).then(|| bitmap)); // + 1: `length == 0` implies that we take the first offset. let offsets = self.offsets.clone().slice_unchecked(offset, length + 1); Self {