diff --git a/arrow-arith/src/arity.rs b/arrow-arith/src/arity.rs index ff8b82a5d943..3d8214d89dc3 100644 --- a/arrow-arith/src/arity.rs +++ b/arrow-arith/src/arity.rs @@ -358,17 +358,16 @@ where let slice = builder.values_slice_mut(); - match nulls.try_for_each_valid_idx(|idx| { + let r = nulls.try_for_each_valid_idx(|idx| { unsafe { *slice.get_unchecked_mut(idx) = op(*slice.get_unchecked(idx), b.value_unchecked(idx))? }; Ok::<_, ArrowError>(()) - }) { - Ok(_) => {} - Err(err) => return Ok(Err(err)), - }; - + }); + if let Err(err) = r { + return Ok(Err(err)); + } let array_builder = builder.finish().into_data().into_builder(); let array_data = unsafe { array_builder.nulls(Some(nulls)).build_unchecked() }; Ok(Ok(PrimitiveArray::::from(array_data))) diff --git a/arrow-array/src/array/primitive_array.rs b/arrow-array/src/array/primitive_array.rs index a6d5c2277226..d866f0ceb642 100644 --- a/arrow-array/src/array/primitive_array.rs +++ b/arrow-array/src/array/primitive_array.rs @@ -658,7 +658,7 @@ impl PrimitiveArray { } /// Creates a PrimitiveArray based on an iterator of values without nulls - pub fn from_iter_values>(iter: I) -> Self { + pub fn from_iter_values>(iter: I) -> Self { let val_buf: Buffer = iter.into_iter().collect(); let len = val_buf.len() / std::mem::size_of::(); Self { @@ -679,8 +679,8 @@ impl PrimitiveArray { /// Returns an iterator that returns the values of `array.value(i)` for an iterator with each element `i` pub fn take_iter<'a>( &'a self, - indexes: impl Iterator> + 'a, - ) -> impl Iterator> + 'a { + indexes: impl Iterator> + 'a, + ) -> impl Iterator> + 'a { indexes.map(|opt_index| opt_index.map(|index| self.value(index))) } @@ -690,8 +690,8 @@ impl PrimitiveArray { /// caller must ensure that the offsets in the iterator are less than the array len() pub unsafe fn take_iter_unchecked<'a>( &'a self, - indexes: impl Iterator> + 'a, - ) -> impl Iterator> + 'a { + indexes: impl Iterator> + 'a, + ) -> impl Iterator> + 'a { indexes.map(|opt_index| opt_index.map(|index| self.value_unchecked(index))) } @@ -722,8 +722,8 @@ impl PrimitiveArray { /// let b: TimestampNanosecondArray = a.reinterpret_cast(); /// ``` pub fn reinterpret_cast(&self) -> PrimitiveArray - where - K: ArrowPrimitiveType, + where + K: ArrowPrimitiveType, { let d = self.to_data().into_builder().data_type(K::DATA_TYPE); @@ -751,9 +751,9 @@ impl PrimitiveArray { /// # } /// ``` pub fn unary(&self, op: F) -> PrimitiveArray - where - O: ArrowPrimitiveType, - F: Fn(T::Native) -> O::Native, + where + O: ArrowPrimitiveType, + F: Fn(T::Native) -> O::Native, { let nulls = self.nulls().cloned(); let values = self.values().iter().map(|v| op(*v)); @@ -785,8 +785,8 @@ impl PrimitiveArray { /// # } /// ``` pub fn unary_mut(self, op: F) -> Result, PrimitiveArray> - where - F: Fn(T::Native) -> T::Native, + where + F: Fn(T::Native) -> T::Native, { let mut builder = self.into_builder()?; builder @@ -804,9 +804,9 @@ impl PrimitiveArray { /// /// Note: LLVM is currently unable to effectively vectorize fallible operations pub fn try_unary(&self, op: F) -> Result, E> - where - O: ArrowPrimitiveType, - F: Fn(T::Native) -> Result, + where + O: ArrowPrimitiveType, + F: Fn(T::Native) -> Result, { let len = self.len(); @@ -847,8 +847,8 @@ impl PrimitiveArray { self, op: F, ) -> Result, E>, PrimitiveArray> - where - F: Fn(T::Native) -> Result, + where + F: Fn(T::Native) -> Result, { let len = self.len(); let null_count = self.null_count(); @@ -856,13 +856,14 @@ impl PrimitiveArray { let (slice, null_buffer) = builder.slices_mut(); - match try_for_each_valid_idx(len, 0, null_count, null_buffer.as_deref(), |idx| { + let r = try_for_each_valid_idx(len, 0, null_count, null_buffer.as_deref(), |idx| { unsafe { *slice.get_unchecked_mut(idx) = op(*slice.get_unchecked(idx))? }; Ok::<_, E>(()) - }) { - Ok(_) => {} - Err(err) => return Ok(Err(err)), - }; + }); + + if let Err(err) = r { + return Ok(Err(err)); + } Ok(Ok(builder.finish())) } @@ -875,9 +876,9 @@ impl PrimitiveArray { /// /// Note: LLVM is currently unable to effectively vectorize fallible operations pub fn unary_opt(&self, op: F) -> PrimitiveArray - where - O: ArrowPrimitiveType, - F: Fn(T::Native) -> Option, + where + O: ArrowPrimitiveType, + F: Fn(T::Native) -> Option, { let len = self.len(); let (nulls, null_count, offset) = match self.nulls() { @@ -1048,8 +1049,8 @@ impl<'a, T: ArrowPrimitiveType> ArrayAccessor for &'a PrimitiveArray { } impl PrimitiveArray -where - i64: From, + where + i64: From, { /// Returns value as a chrono `NaiveDateTime`, handling time resolution /// @@ -1208,7 +1209,7 @@ impl From<&Option<::Native>> for } impl>> FromIterator for PrimitiveArray { - fn from_iter>(iter: I) -> Self { + fn from_iter>(iter: I) -> Self { let iter = iter.into_iter(); let (lower, _) = iter.size_hint(); @@ -1253,9 +1254,9 @@ impl PrimitiveArray { /// I.e. that `size_hint().1` correctly reports its length. #[inline] pub unsafe fn from_trusted_len_iter(iter: I) -> Self - where - P: std::borrow::Borrow::Native>>, - I: IntoIterator, + where + P: std::borrow::Borrow::Native>>, + I: IntoIterator, { let iterator = iter.into_iter(); let (_, upper) = iterator.size_hint(); @@ -1329,8 +1330,8 @@ impl PrimitiveArray { /// Construct a timestamp array from a vec of i64 values and an optional timezone #[deprecated(note = "Use with_timezone_opt instead")] pub fn from_vec(data: Vec, timezone: Option) -> Self - where - Self: From>, + where + Self: From>, { Self::from(data).with_timezone_opt(timezone) } @@ -1338,8 +1339,8 @@ impl PrimitiveArray { /// Construct a timestamp array from a vec of `Option` values and an optional timezone #[deprecated(note = "Use with_timezone_opt instead")] pub fn from_opt_vec(data: Vec>, timezone: Option) -> Self - where - Self: From>>, + where + Self: From>>, { Self::from(data).with_timezone_opt(timezone) } @@ -1917,7 +1918,7 @@ mod tests { 1667717999000, 1667718000000, ]) - .with_timezone("America/Denver".to_string()); + .with_timezone("America/Denver".to_string()); assert_eq!( "PrimitiveArray\n[\n 2022-03-13T01:59:59-07:00,\n 2022-03-13T03:00:00-06:00,\n 2022-11-06T00:59:59-06:00,\n 2022-11-06T01:00:00-06:00,\n]", format!("{:?}", arr) @@ -2065,7 +2066,7 @@ mod tests { #[test] #[should_panic( - expected = "Trying to access an element at index 4 from a PrimitiveArray of length 3" + expected = "Trying to access an element at index 4 from a PrimitiveArray of length 3" )] fn test_string_array_get_value_index_out_of_bound() { let array: Int8Array = [10_i8, 11, 12].into_iter().collect(); @@ -2254,7 +2255,7 @@ mod tests { #[test] #[should_panic( - expected = "-123223423432432 is too small to store in a Decimal128 of precision 5. Min is -99999" + expected = "-123223423432432 is too small to store in a Decimal128 of precision 5. Min is -99999" )] fn test_decimal_array_with_precision_and_scale_out_of_range() { let arr = Decimal128Array::from_iter_values([12345, 456, 7890, -123223423432432]) @@ -2366,7 +2367,7 @@ mod tests { #[test] #[should_panic( - expected = "Trying to access an element at index 4 from a PrimitiveArray of length 3" + expected = "Trying to access an element at index 4 from a PrimitiveArray of length 3" )] fn test_fixed_size_binary_array_get_value_index_out_of_bound() { let array = Decimal128Array::from(vec![-100, 0, 101]); @@ -2442,7 +2443,7 @@ mod tests { #[test] #[should_panic( - expected = "PrimitiveArray expected data type Interval(MonthDayNano) got Interval(DayTime)" + expected = "PrimitiveArray expected data type Interval(MonthDayNano) got Interval(DayTime)" )] fn test_invalid_interval_type() { let array = IntervalDayTimeArray::from(vec![1, 2, 3]); diff --git a/arrow-row/src/variable.rs b/arrow-row/src/variable.rs index 4451c5287310..466214e7540e 100644 --- a/arrow-row/src/variable.rs +++ b/arrow-row/src/variable.rs @@ -85,7 +85,7 @@ pub fn encode<'a, I: Iterator>>( pub fn encode_one(out: &mut [u8], val: Option<&[u8]>, opts: SortOptions) -> usize { match val { - Some(val) if val.is_empty() => { + Some([]) => { out[0] = match opts.descending { true => !EMPTY_SENTINEL, false => EMPTY_SENTINEL,