From 976ada2c637157b86e5eeb6a7c66c5ec8cfa4ae4 Mon Sep 17 00:00:00 2001 From: baishen Date: Thu, 9 Nov 2023 15:59:30 +0800 Subject: [PATCH] fix clippy --- src/array/binary/mod.rs | 8 +++++++- src/array/binary/mutable.rs | 2 +- src/array/binary/mutable_values.rs | 8 +++++++- src/array/boolean/iterator.rs | 2 +- src/array/boolean/mod.rs | 8 +++++++- src/array/boolean/mutable.rs | 2 +- src/array/dictionary/mod.rs | 7 +++++++ src/array/fixed_size_binary/mod.rs | 8 +++++++- src/array/fixed_size_binary/mutable.rs | 8 +++++++- src/array/fixed_size_list/mod.rs | 8 +++++++- src/array/fixed_size_list/mutable.rs | 6 ++++++ src/array/fmt.rs | 2 ++ src/array/growable/mod.rs | 5 +++++ src/array/list/mod.rs | 8 +++++++- src/array/list/mutable.rs | 6 ++++++ src/array/map/mod.rs | 8 +++++++- src/array/primitive/fmt.rs | 1 + src/array/primitive/iterator.rs | 2 +- src/array/primitive/mod.rs | 8 +++++++- src/array/primitive/mutable.rs | 2 +- src/array/specification.rs | 2 +- src/array/struct_/mod.rs | 2 +- src/array/union/mod.rs | 6 ++++++ src/array/utf8/mod.rs | 8 +++++++- src/array/utf8/mutable.rs | 8 +++++++- src/array/utf8/mutable_values.rs | 8 +++++++- src/bitmap/utils/zip_validity.rs | 8 ++++---- src/compute/sort/row/mod.rs | 12 +++++++++--- src/compute/take/mod.rs | 2 +- src/io/avro/read/deserialize.rs | 2 +- src/io/parquet/read/deserialize/nested_utils.rs | 11 +++++++++++ src/io/parquet/write/dictionary.rs | 2 +- src/io/parquet/write/pages.rs | 5 +++++ src/offset.rs | 14 +++++++++++++- 34 files changed, 169 insertions(+), 30 deletions(-) diff --git a/src/array/binary/mod.rs b/src/array/binary/mod.rs index 7247decb300..3069372ff88 100644 --- a/src/array/binary/mod.rs +++ b/src/array/binary/mod.rs @@ -133,6 +133,12 @@ impl BinaryArray { self.offsets.len_proxy() } + /// Returns `true` if the array has a length of 0. + #[inline] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + /// Returns the element at index `i` /// # Panics /// iff `i >= self.len()` @@ -212,7 +218,7 @@ impl BinaryArray { pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize) { self.validity.as_mut().and_then(|bitmap| { bitmap.slice_unchecked(offset, length); - (bitmap.unset_bits() > 0).then(|| bitmap) + (bitmap.unset_bits() > 0).then_some(bitmap) }); self.offsets.slice_unchecked(offset, length + 1); } diff --git a/src/array/binary/mutable.rs b/src/array/binary/mutable.rs index 32a6f17acb5..f010ba6e46d 100644 --- a/src/array/binary/mutable.rs +++ b/src/array/binary/mutable.rs @@ -125,7 +125,7 @@ impl MutableBinaryArray { let value = self.values.pop()?; self.validity .as_mut() - .map(|x| x.pop()?.then(|| ())) + .map(|x| x.pop()?.then_some(())) .unwrap_or_else(|| Some(())) .map(|_| value) } diff --git a/src/array/binary/mutable_values.rs b/src/array/binary/mutable_values.rs index 3e14d9c578a..260da7030bb 100644 --- a/src/array/binary/mutable_values.rs +++ b/src/array/binary/mutable_values.rs @@ -132,6 +132,12 @@ impl MutableBinaryValuesArray { self.offsets.len_proxy() } + /// Returns `true` if the array has a length of 0. + #[inline] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + /// Pushes a new item to the array. /// # Panic /// This operation panics iff the length of all values (in bytes) exceeds `O` maximum value. @@ -143,7 +149,7 @@ impl MutableBinaryValuesArray { /// Pop the last entry from [`MutableBinaryValuesArray`]. /// This function returns `None` iff this array is empty. pub fn pop(&mut self) -> Option> { - if self.len() == 0 { + if self.is_empty() { return None; } self.offsets.pop()?; diff --git a/src/array/boolean/iterator.rs b/src/array/boolean/iterator.rs index 8243a8d985f..cc735b3a76c 100644 --- a/src/array/boolean/iterator.rs +++ b/src/array/boolean/iterator.rs @@ -23,7 +23,7 @@ impl IntoIterator for BooleanArray { let (_, values, validity) = self.into_inner(); let values = values.into_iter(); let validity = - validity.and_then(|validity| (validity.unset_bits() > 0).then(|| validity.into_iter())); + validity.and_then(|validity| (validity.unset_bits() > 0).then_some(validity.into_iter())); ZipValidity::new(values, validity) } } diff --git a/src/array/boolean/mod.rs b/src/array/boolean/mod.rs index 0b634ee90e3..f54f655423f 100644 --- a/src/array/boolean/mod.rs +++ b/src/array/boolean/mod.rs @@ -110,6 +110,12 @@ impl BooleanArray { self.values.len() } + /// Returns `true` if the array has a length of 0. + #[inline] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + /// The values [`Bitmap`]. /// Values on null slots are undetermined (they can be anything). #[inline] @@ -181,7 +187,7 @@ impl BooleanArray { pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize) { self.validity.as_mut().and_then(|bitmap| { bitmap.slice_unchecked(offset, length); - (bitmap.unset_bits() > 0).then(|| bitmap) + (bitmap.unset_bits() > 0).then_some(bitmap) }); self.values.slice_unchecked(offset, length); } diff --git a/src/array/boolean/mutable.rs b/src/array/boolean/mutable.rs index f0f67e04c17..a0eb235dce1 100644 --- a/src/array/boolean/mutable.rs +++ b/src/array/boolean/mutable.rs @@ -129,7 +129,7 @@ impl MutableBooleanArray { let value = self.values.pop()?; self.validity .as_mut() - .map(|x| x.pop()?.then(|| value)) + .map(|x| x.pop()?.then_some(value)) .unwrap_or_else(|| Some(value)) } diff --git a/src/array/dictionary/mod.rs b/src/array/dictionary/mod.rs index a6189a94d13..136de605299 100644 --- a/src/array/dictionary/mod.rs +++ b/src/array/dictionary/mod.rs @@ -265,6 +265,7 @@ impl DictionaryArray { /// # Panics /// /// This function panics if the `values` array + #[allow(clippy::type_complexity)] pub fn iter_typed( &self, ) -> Result, DictionaryValuesIterTyped, BitmapIter>, Error> @@ -335,6 +336,12 @@ impl DictionaryArray { self.keys.len() } + /// Returns `true` if the array has a length of 0. + #[inline] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + /// The optional validity. Equivalent to `self.keys().validity()`. #[inline] pub fn validity(&self) -> Option<&Bitmap> { diff --git a/src/array/fixed_size_binary/mod.rs b/src/array/fixed_size_binary/mod.rs index 34242d9ad62..306ac5f8b64 100644 --- a/src/array/fixed_size_binary/mod.rs +++ b/src/array/fixed_size_binary/mod.rs @@ -110,7 +110,7 @@ impl FixedSizeBinaryArray { pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize) { self.validity.as_mut().and_then(|bitmap| { bitmap.slice_unchecked(offset, length); - (bitmap.unset_bits() > 0).then(|| bitmap) + (bitmap.unset_bits() > 0).then_some(bitmap) }); self.values .slice_unchecked(offset * self.size, length * self.size); @@ -129,6 +129,12 @@ impl FixedSizeBinaryArray { self.values.len() / self.size } + /// Returns `true` if the array has a length of 0. + #[inline] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + /// The optional validity. #[inline] pub fn validity(&self) -> Option<&Bitmap> { diff --git a/src/array/fixed_size_binary/mutable.rs b/src/array/fixed_size_binary/mutable.rs index 9009f2702df..910c6ab085a 100644 --- a/src/array/fixed_size_binary/mutable.rs +++ b/src/array/fixed_size_binary/mutable.rs @@ -149,6 +149,12 @@ impl MutableFixedSizeBinaryArray { self.values.len() / self.size } + /// Returns `true` if the array has a length of 0. + #[inline] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + /// Pop the last entry from [`MutableFixedSizeBinaryArray`]. /// This function returns `None` iff this array is empty pub fn pop(&mut self) -> Option> { @@ -159,7 +165,7 @@ impl MutableFixedSizeBinaryArray { let value = self.values.split_off(value_start); self.validity .as_mut() - .map(|x| x.pop()?.then(|| ())) + .map(|x| x.pop()?.then_some(())) .unwrap_or_else(|| Some(())) .map(|_| value) } diff --git a/src/array/fixed_size_list/mod.rs b/src/array/fixed_size_list/mod.rs index 0d335167b20..0462ba14f07 100644 --- a/src/array/fixed_size_list/mod.rs +++ b/src/array/fixed_size_list/mod.rs @@ -123,7 +123,7 @@ impl FixedSizeListArray { pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize) { self.validity.as_mut().and_then(|bitmap| { bitmap.slice_unchecked(offset, length); - (bitmap.unset_bits() > 0).then(|| bitmap) + (bitmap.unset_bits() > 0).then_some(bitmap) }); self.values .slice_unchecked(offset * self.size, length * self.size); @@ -142,6 +142,12 @@ impl FixedSizeListArray { self.values.len() / self.size } + /// Returns `true` if the array has a length of 0. + #[inline] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + /// The optional validity. #[inline] pub fn validity(&self) -> Option<&Bitmap> { diff --git a/src/array/fixed_size_list/mutable.rs b/src/array/fixed_size_list/mutable.rs index 1e387a2f70c..cde1a22846e 100644 --- a/src/array/fixed_size_list/mutable.rs +++ b/src/array/fixed_size_list/mutable.rs @@ -73,6 +73,12 @@ impl MutableFixedSizeListArray { self.values.len() / self.size } + /// Returns `true` if the array has a length of 0. + #[inline] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + /// The inner values pub fn values(&self) -> &M { &self.values diff --git a/src/array/fmt.rs b/src/array/fmt.rs index 4f2c6896beb..7fb131c8690 100644 --- a/src/array/fmt.rs +++ b/src/array/fmt.rs @@ -7,6 +7,7 @@ use super::Array; /// Returns a function that writes the value of the element of `array` /// at position `index` to a [`Write`], /// writing `null` in the null slots. +#[allow(clippy::type_complexity)] pub fn get_value_display<'a, F: Write + 'a>( array: &'a dyn Array, null: &'static str, @@ -101,6 +102,7 @@ pub fn get_value_display<'a, F: Write + 'a>( /// Returns a function that writes the element of `array` /// at position `index` to a [`Write`], writing `null` to the null slots. +#[allow(clippy::type_complexity)] pub fn get_display<'a, F: Write + 'a>( array: &'a dyn Array, null: &'static str, diff --git a/src/array/growable/mod.rs b/src/array/growable/mod.rs index 45f79405307..2b91766ab49 100644 --- a/src/array/growable/mod.rs +++ b/src/array/growable/mod.rs @@ -48,6 +48,11 @@ pub trait Growable<'a> { /// The current length of the [`Growable`]. fn len(&self) -> usize; + /// Returns `true` if the length of the [`Growable`] is 0. + fn is_empty(&self) -> bool { + self.len() == 0 + } + /// Converts this [`Growable`] to an [`Arc`], thereby finishing the mutation. /// Self will be empty after such operation. fn as_arc(&mut self) -> Arc { diff --git a/src/array/list/mod.rs b/src/array/list/mod.rs index b7eda9b4d5c..5170dd628b4 100644 --- a/src/array/list/mod.rs +++ b/src/array/list/mod.rs @@ -125,7 +125,7 @@ impl ListArray { pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize) { self.validity.as_mut().and_then(|bitmap| { bitmap.slice_unchecked(offset, length); - (bitmap.unset_bits() > 0).then(|| bitmap) + (bitmap.unset_bits() > 0).then_some(bitmap) }); self.offsets.slice_unchecked(offset, length + 1); } @@ -143,6 +143,12 @@ impl ListArray { self.offsets.len_proxy() } + /// Returns `true` if the array has a length of 0. + #[inline] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + /// Returns the element at index `i` /// # Panic /// Panics iff `i >= self.len()` diff --git a/src/array/list/mutable.rs b/src/array/list/mutable.rs index d24475e86db..5a1ffce5017 100644 --- a/src/array/list/mutable.rs +++ b/src/array/list/mutable.rs @@ -210,6 +210,12 @@ impl MutableListArray { self.offsets.len_proxy() } + /// Returns `true` if the array has a length of 0. + #[inline] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + /// The values pub fn mut_values(&mut self) -> &mut M { &mut self.values diff --git a/src/array/map/mod.rs b/src/array/map/mod.rs index 952695297fa..d4c8740b112 100644 --- a/src/array/map/mod.rs +++ b/src/array/map/mod.rs @@ -127,7 +127,7 @@ impl MapArray { pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize) { self.validity.as_mut().and_then(|bitmap| { bitmap.slice_unchecked(offset, length); - (bitmap.unset_bits() > 0).then(|| bitmap) + (bitmap.unset_bits() > 0).then_some(bitmap) }); self.offsets.slice_unchecked(offset, length + 1); } @@ -159,6 +159,12 @@ impl MapArray { self.offsets.len_proxy() } + /// Returns `true` if the array has a length of 0. + #[inline] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + /// returns the offsets #[inline] pub fn offsets(&self) -> &OffsetsBuffer { diff --git a/src/array/primitive/fmt.rs b/src/array/primitive/fmt.rs index 05357ef5876..1cd1a5dfa81 100644 --- a/src/array/primitive/fmt.rs +++ b/src/array/primitive/fmt.rs @@ -19,6 +19,7 @@ macro_rules! dyn_primitive { }}; } +#[allow(clippy::type_complexity)] pub fn get_write_value<'a, T: NativeType, F: Write>( array: &'a PrimitiveArray, ) -> Box Result + 'a> { diff --git a/src/array/primitive/iterator.rs b/src/array/primitive/iterator.rs index 18e213b563d..0ab75aa597c 100644 --- a/src/array/primitive/iterator.rs +++ b/src/array/primitive/iterator.rs @@ -17,7 +17,7 @@ impl IntoIterator for PrimitiveArray { let (_, values, validity) = self.into_inner(); let values = values.into_iter(); let validity = - validity.and_then(|validity| (validity.unset_bits() > 0).then(|| validity.into_iter())); + validity.and_then(|validity| (validity.unset_bits() > 0).then_some(validity.into_iter())); ZipValidity::new(values, validity) } } diff --git a/src/array/primitive/mod.rs b/src/array/primitive/mod.rs index 04b74a3529b..90d7aa7f359 100644 --- a/src/array/primitive/mod.rs +++ b/src/array/primitive/mod.rs @@ -160,6 +160,12 @@ impl PrimitiveArray { self.values.len() } + /// Returns `true` if the array has a length of 0. + #[inline] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + /// The values [`Buffer`]. /// Values on null slots are undetermined (they can be anything). #[inline] @@ -232,7 +238,7 @@ impl PrimitiveArray { pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize) { self.validity.as_mut().and_then(|bitmap| { bitmap.slice_unchecked(offset, length); - (bitmap.unset_bits() > 0).then(|| bitmap) + (bitmap.unset_bits() > 0).then_some(bitmap) }); self.values.slice_unchecked(offset, length); } diff --git a/src/array/primitive/mutable.rs b/src/array/primitive/mutable.rs index 09fa401fc37..78d1fa39c7b 100644 --- a/src/array/primitive/mutable.rs +++ b/src/array/primitive/mutable.rs @@ -160,7 +160,7 @@ impl MutablePrimitiveArray { let value = self.values.pop()?; self.validity .as_mut() - .map(|x| x.pop()?.then(|| value)) + .map(|x| x.pop()?.then_some(value)) .unwrap_or_else(|| Some(value)) } diff --git a/src/array/specification.rs b/src/array/specification.rs index efa8fe1be4a..34dcbf28253 100644 --- a/src/array/specification.rs +++ b/src/array/specification.rs @@ -72,7 +72,7 @@ pub(crate) fn try_check_utf8>( .enumerate() .skip(1) .rev() - .find_map(|(i, offset)| (offset.to_usize() < values.len()).then(|| i)); + .find_map(|(i, offset)| (offset.to_usize() < values.len()).then_some(i)); let last = if let Some(last) = last { // following the example: last = 1 (offset = 5) diff --git a/src/array/struct_/mod.rs b/src/array/struct_/mod.rs index 767ba8242fc..ac488592095 100644 --- a/src/array/struct_/mod.rs +++ b/src/array/struct_/mod.rs @@ -188,7 +188,7 @@ impl StructArray { pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize) { self.validity.as_mut().and_then(|bitmap| { bitmap.slice_unchecked(offset, length); - (bitmap.unset_bits() > 0).then(|| bitmap) + (bitmap.unset_bits() > 0).then_some(bitmap) }); self.values .iter_mut() diff --git a/src/array/union/mod.rs b/src/array/union/mod.rs index e3e664916f8..2f31d3cb8e9 100644 --- a/src/array/union/mod.rs +++ b/src/array/union/mod.rs @@ -265,6 +265,12 @@ impl UnionArray { self.types.len() } + /// Returns `true` if the array has a length of 0. + #[inline] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + /// The optional offsets. pub fn offsets(&self) -> Option<&Buffer> { self.offsets.as_ref() diff --git a/src/array/utf8/mod.rs b/src/array/utf8/mod.rs index 9440ae43304..795ce9dd769 100644 --- a/src/array/utf8/mod.rs +++ b/src/array/utf8/mod.rs @@ -149,6 +149,12 @@ impl Utf8Array { self.offsets.len_proxy() } + /// Returns `true` if the array has a length of 0. + #[inline] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + /// Returns the value of the element at index `i`, ignoring the array's validity. /// # Panic /// This function panics iff `i >= self.len`. @@ -231,7 +237,7 @@ impl Utf8Array { pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize) { self.validity.as_mut().and_then(|bitmap| { bitmap.slice_unchecked(offset, length); - (bitmap.unset_bits() > 0).then(|| bitmap) + (bitmap.unset_bits() > 0).then_some(bitmap) }); self.offsets.slice_unchecked(offset, length + 1); } diff --git a/src/array/utf8/mutable.rs b/src/array/utf8/mutable.rs index 108fe8e474b..4a10c20f6df 100644 --- a/src/array/utf8/mutable.rs +++ b/src/array/utf8/mutable.rs @@ -141,6 +141,12 @@ impl MutableUtf8Array { self.values.len() } + /// Returns `true` if the array has a length of 0. + #[inline] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + /// Pushes a new element to the array. /// # Panic /// This operation panics iff the length of all values (in bytes) exceeds `O` maximum value. @@ -171,7 +177,7 @@ impl MutableUtf8Array { let value = self.values.pop()?; self.validity .as_mut() - .map(|x| x.pop()?.then(|| ())) + .map(|x| x.pop()?.then_some(())) .unwrap_or_else(|| Some(())) .map(|_| value) } diff --git a/src/array/utf8/mutable_values.rs b/src/array/utf8/mutable_values.rs index dce8b09e4c1..a3cac2f925e 100644 --- a/src/array/utf8/mutable_values.rs +++ b/src/array/utf8/mutable_values.rs @@ -167,6 +167,12 @@ impl MutableUtf8ValuesArray { self.offsets.len_proxy() } + /// Returns `true` if the array has a length of 0. + #[inline] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + /// Pushes a new item to the array. /// # Panic /// This operation panics iff the length of all values (in bytes) exceeds `O` maximum value. @@ -178,7 +184,7 @@ impl MutableUtf8ValuesArray { /// Pop the last entry from [`MutableUtf8ValuesArray`]. /// This function returns `None` iff this array is empty. pub fn pop(&mut self) -> Option { - if self.len() == 0 { + if self.is_empty() { return None; } self.offsets.pop()?; diff --git a/src/bitmap/utils/zip_validity.rs b/src/bitmap/utils/zip_validity.rs index 40965bab411..87a67f3892e 100644 --- a/src/bitmap/utils/zip_validity.rs +++ b/src/bitmap/utils/zip_validity.rs @@ -40,7 +40,7 @@ where let is_valid = self.validity.next(); is_valid .zip(value) - .map(|(is_valid, value)| is_valid.then(|| value)) + .map(|(is_valid, value)| is_valid.then_some(value)) } #[inline] @@ -54,7 +54,7 @@ where let is_valid = self.validity.nth(n); is_valid .zip(value) - .map(|(is_valid, value)| is_valid.then(|| value)) + .map(|(is_valid, value)| is_valid.then_some(value)) } } @@ -69,7 +69,7 @@ where let is_valid = self.validity.next_back(); is_valid .zip(value) - .map(|(is_valid, value)| is_valid.then(|| value)) + .map(|(is_valid, value)| is_valid.then_some(value)) } } @@ -126,7 +126,7 @@ where /// are valid. pub fn new_with_validity(values: I, validity: Option<&'a Bitmap>) -> Self { // only if the validity has nulls we take the optional branch. - match validity.and_then(|validity| (validity.unset_bits() > 0).then(|| validity.iter())) { + match validity.and_then(|validity| (validity.unset_bits() > 0).then_some(validity.iter())) { Some(validity) => Self::Optional(ZipValidityIter::new(values, validity)), _ => Self::Required(values), } diff --git a/src/compute/sort/row/mod.rs b/src/compute/sort/row/mod.rs index 2388a6c8680..46314ca6c73 100644 --- a/src/compute/sort/row/mod.rs +++ b/src/compute/sort/row/mod.rs @@ -284,6 +284,12 @@ impl Rows { self.offsets.len() - 1 } + /// Returns `true` if the number of rows is 0. + #[inline] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + #[inline] /// Returns the iterator pub fn iter(&self) -> RowsIter<'_> { @@ -710,7 +716,7 @@ mod tests { { let mut rng = thread_rng(); (0..len) - .map(|_| rng.gen_bool(valid_percent).then(|| rng.gen())) + .map(|_| rng.gen_bool(valid_percent).then_some(rng.gen())) .collect() } @@ -718,7 +724,7 @@ mod tests { let mut rng = thread_rng(); (0..len) .map(|_| { - rng.gen_bool(valid_percent).then(|| { + rng.gen_bool(valid_percent).then_some({ let len = rng.gen_range(0..100); let bytes = (0..len).map(|_| rng.gen_range(0..128)).collect(); String::from_utf8(bytes).unwrap() @@ -742,7 +748,7 @@ mod tests { let keys: PrimitiveArray = (0..len) .map(|_| { rng.gen_bool(valid_percent) - .then(|| rng.gen_range(min_key..max_key)) + .then_some(rng.gen_range(min_key..max_key)) }) .collect(); diff --git a/src/compute/take/mod.rs b/src/compute/take/mod.rs index 3acf47dc7a1..1e70ef397cd 100644 --- a/src/compute/take/mod.rs +++ b/src/compute/take/mod.rs @@ -39,7 +39,7 @@ pub(crate) use boolean::take as take_boolean; /// Returns a new [`Array`] with only indices at `indices`. Null indices are taken as nulls. /// The returned array has a length equal to `indices.len()`. pub fn take(values: &dyn Array, indices: &PrimitiveArray) -> Result> { - if indices.len() == 0 { + if indices.is_empty() { return Ok(new_empty_array(values.data_type().clone())); } diff --git a/src/io/avro/read/deserialize.rs b/src/io/avro/read/deserialize.rs index d2de2a7ac4e..d48f419d4c8 100644 --- a/src/io/avro/read/deserialize.rs +++ b/src/io/avro/read/deserialize.rs @@ -522,7 +522,7 @@ pub fn deserialize( arrays .iter_mut() .zip(projection.iter()) - .filter_map(|x| x.1.then(|| x.0)) + .filter_map(|x| x.1.then_some(x.0)) .map(|array| array.as_box()) .collect(), ) diff --git a/src/io/parquet/read/deserialize/nested_utils.rs b/src/io/parquet/read/deserialize/nested_utils.rs index 86c7f5bdabe..750ae7948f5 100644 --- a/src/io/parquet/read/deserialize/nested_utils.rs +++ b/src/io/parquet/read/deserialize/nested_utils.rs @@ -30,6 +30,11 @@ pub trait Nested: std::fmt::Debug + Send + Sync { /// number of rows fn len(&self) -> usize; + /// Returns `true` if the number of rows is 0. + fn is_empty(&self) -> bool { + self.len() == 0 + } + /// number of values associated to the primitive type this nested tracks fn num_values(&self) -> usize; } @@ -347,6 +352,12 @@ impl NestedState { // outermost is the number of rows self.nested[0].len() } + + /// Returns `true` if the number of rows is 0. + #[inline] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } } /// Extends `items` by consuming `page`, first trying to complete the last `item` diff --git a/src/io/parquet/write/dictionary.rs b/src/io/parquet/write/dictionary.rs index 9669797589e..fddaabf2239 100644 --- a/src/io/parquet/write/dictionary.rs +++ b/src/io/parquet/write/dictionary.rs @@ -47,7 +47,7 @@ fn serialize_keys_values( // discard indices whose values are null. let keys = keys .zip(validity.iter()) - .filter_map(|(key, is_valid)| is_valid.then(|| key)); + .filter_map(|(key, is_valid)| is_valid.then_some(key)); let num_bits = utils::get_bit_width(keys.clone().max().unwrap_or(0) as u64); let keys = utils::ExactSizedIter::new(keys, array.len() - validity.unset_bits()); diff --git a/src/io/parquet/write/pages.rs b/src/io/parquet/write/pages.rs index 10aea638a22..99dfd1526c4 100644 --- a/src/io/parquet/write/pages.rs +++ b/src/io/parquet/write/pages.rs @@ -55,6 +55,11 @@ impl Nested { Nested::Struct(_, _, len) => *len, } } + + /// Returns `true` if the length of the element is 0. + pub fn is_empty(&self) -> bool { + self.len() == 0 + } } /// Constructs the necessary `Vec>` to write the rep and def levels of `array` to parquet diff --git a/src/offset.rs b/src/offset.rs index 80b45d6680b..8618c66897c 100644 --- a/src/offset.rs +++ b/src/offset.rs @@ -177,12 +177,18 @@ impl Offsets { self.0.len() - 1 } - #[inline] /// Returns the number of offsets in this container. + #[inline] pub fn len(&self) -> usize { self.0.len() } + /// Returns `true` if the offsets has a length of 0. + #[inline] + pub fn is_empty(&self) -> bool { + self.len_proxy() == 0 + } + /// Returns the byte slice stored in this buffer #[inline] pub fn as_slice(&self) -> &[O] { @@ -389,6 +395,12 @@ impl OffsetsBuffer { self.0.len() } + /// Returns `true` if the offsets has a length of 0. + #[inline] + pub fn is_empty(&self) -> bool { + self.len_proxy() == 0 + } + /// Returns the byte slice stored in this buffer #[inline] pub fn as_slice(&self) -> &[O] {