From 525a3fc536c07a938444d43f7a8d0361b2c6c836 Mon Sep 17 00:00:00 2001 From: "Jorge C. Leitao" Date: Sun, 18 Dec 2022 12:39:03 +0000 Subject: [PATCH] Clippy --- src/array/fixed_size_binary/ffi.rs | 2 +- src/array/fixed_size_binary/mod.rs | 4 ++-- src/array/fixed_size_binary/mutable.rs | 2 +- src/array/fixed_size_list/mod.rs | 12 +++++------- src/array/growable/fixed_size_list.rs | 2 +- src/compute/cast/primitive_to.rs | 8 ++------ src/compute/comparison/primitive.rs | 13 +++++-------- src/compute/sort/binary.rs | 2 +- src/compute/sort/utf8.rs | 2 +- src/compute/substring.rs | 2 +- src/compute/window.rs | 2 +- src/io/avro/read/deserialize.rs | 12 ++++++------ src/io/ipc/read/stream.rs | 8 ++++---- src/io/ipc/read/stream_async.rs | 8 ++++---- src/io/ipc/write/common.rs | 2 +- src/io/odbc/read/schema.rs | 2 +- src/io/parquet/read/deserialize/simple.rs | 6 +++--- src/io/parquet/read/row_group.rs | 7 ++----- src/io/parquet/read/statistics/mod.rs | 10 +++++----- src/io/parquet/write/nested/def.rs | 4 ++-- 20 files changed, 49 insertions(+), 61 deletions(-) diff --git a/src/array/fixed_size_binary/ffi.rs b/src/array/fixed_size_binary/ffi.rs index f1775e74d51..444f3c3996e 100644 --- a/src/array/fixed_size_binary/ffi.rs +++ b/src/array/fixed_size_binary/ffi.rs @@ -16,7 +16,7 @@ unsafe impl ToFfi for FixedSizeBinaryArray { } fn offset(&self) -> Option { - let offset = self.values.offset() / self.size as usize; + let offset = self.values.offset() / self.size; if let Some(bitmap) = self.validity.as_ref() { if bitmap.offset() == offset { Some(offset) diff --git a/src/array/fixed_size_binary/mod.rs b/src/array/fixed_size_binary/mod.rs index 8eea1c6c191..9806262db84 100644 --- a/src/array/fixed_size_binary/mod.rs +++ b/src/array/fixed_size_binary/mod.rs @@ -160,7 +160,7 @@ impl FixedSizeBinaryArray { /// Returns the length of this array #[inline] pub fn len(&self) -> usize { - self.values.len() / self.size as usize + self.values.len() / self.size } /// The optional validity. @@ -329,6 +329,6 @@ impl FixedSizeBinaryValues for FixedSizeBinaryArray { #[inline] fn size(&self) -> usize { - self.size as usize + self.size } } diff --git a/src/array/fixed_size_binary/mutable.rs b/src/array/fixed_size_binary/mutable.rs index b6d60bade58..9009f2702df 100644 --- a/src/array/fixed_size_binary/mutable.rs +++ b/src/array/fixed_size_binary/mutable.rs @@ -146,7 +146,7 @@ impl MutableFixedSizeBinaryArray { /// Returns the length of this array #[inline] pub fn len(&self) -> usize { - self.values.len() / self.size as usize + self.values.len() / self.size } /// Pop the last entry from [`MutableFixedSizeBinaryArray`]. diff --git a/src/array/fixed_size_list/mod.rs b/src/array/fixed_size_list/mod.rs index 298f11716dc..5b8df559ee7 100644 --- a/src/array/fixed_size_list/mod.rs +++ b/src/array/fixed_size_list/mod.rs @@ -140,7 +140,7 @@ impl FixedSizeListArray { let values = self .values .clone() - .slice_unchecked(offset * self.size as usize, length * self.size as usize); + .slice_unchecked(offset * self.size, length * self.size); Self { data_type: self.data_type.clone(), size: self.size, @@ -174,7 +174,7 @@ impl FixedSizeListArray { /// Returns the length of this array #[inline] pub fn len(&self) -> usize { - self.values.len() / self.size as usize + self.values.len() / self.size } /// The optional validity. @@ -193,8 +193,7 @@ impl FixedSizeListArray { /// panics iff `i >= self.len()` #[inline] pub fn value(&self, i: usize) -> Box { - self.values - .slice(i * self.size as usize, self.size as usize) + self.values.slice(i * self.size, self.size) } /// Returns the `Vec` at position `i`. @@ -202,8 +201,7 @@ impl FixedSizeListArray { /// Caller must ensure that `i < self.len()` #[inline] pub unsafe fn value_unchecked(&self, i: usize) -> Box { - self.values - .slice_unchecked(i * self.size as usize, self.size as usize) + self.values.slice_unchecked(i * self.size, self.size) } } @@ -214,7 +212,7 @@ impl FixedSizeListArray { if *size == 0 { return Err(Error::oos("FixedSizeBinaryArray expects a positive size")); } - Ok((child.as_ref(), *size as usize)) + Ok((child.as_ref(), *size)) } _ => Err(Error::oos( "FixedSizeListArray expects DataType::FixedSizeList", diff --git a/src/array/growable/fixed_size_list.rs b/src/array/growable/fixed_size_list.rs index 26344f4c96a..6fb88233a77 100644 --- a/src/array/growable/fixed_size_list.rs +++ b/src/array/growable/fixed_size_list.rs @@ -40,7 +40,7 @@ impl<'a> GrowableFixedSizeList<'a> { let size = if let DataType::FixedSizeList(_, size) = &arrays[0].data_type().to_logical_type() { - *size as usize + *size } else { unreachable!("`GrowableFixedSizeList` expects `DataType::FixedSizeList`") }; diff --git a/src/compute/cast/primitive_to.rs b/src/compute/cast/primitive_to.rs index 4feb5aaba6c..585e826cddb 100644 --- a/src/compute/cast/primitive_to.rs +++ b/src/compute/cast/primitive_to.rs @@ -38,7 +38,7 @@ pub fn primitive_to_binary( let len = lexical_core::write_unchecked(*x, bytes).len(); offset += len; - offsets.push(O::from_usize(offset as usize).unwrap()); + offsets.push(O::from_usize(offset).unwrap()); } values.set_len(offset); values.shrink_to_fit(); @@ -398,11 +398,7 @@ pub fn time64_to_time32( let from_size = time_unit_multiple(from_unit); let to_size = time_unit_multiple(to_unit); let divisor = from_size / to_size; - unary( - from, - |x| (x as i64 / divisor) as i32, - DataType::Time32(to_unit), - ) + unary(from, |x| (x / divisor) as i32, DataType::Time32(to_unit)) } /// Conversion of timestamp diff --git a/src/compute/comparison/primitive.rs b/src/compute/comparison/primitive.rs index 05e5254f44a..e0df8b12186 100644 --- a/src/compute/comparison/primitive.rs +++ b/src/compute/comparison/primitive.rs @@ -335,10 +335,7 @@ mod tests { let b = Int64Array::from_slice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); let c = b.slice(5, 5); let d = eq(&c, &a); - assert_eq!( - d, - BooleanArray::from_slice(&vec![true, true, true, false, true]) - ); + assert_eq!(d, BooleanArray::from_slice([true, true, true, false, true])); } #[test] @@ -584,11 +581,11 @@ mod tests { #[test] fn test_length_of_result_buffer() { // `item_count` is chosen to not be a multiple of 64. - let item_count = 130; + const ITEM_COUNT: usize = 130; - let array_a = Int8Array::from_slice(&vec![1; item_count]); - let array_b = Int8Array::from_slice(&vec![2; item_count]); - let expected = BooleanArray::from_slice(&vec![false; item_count]); + let array_a = Int8Array::from_slice([1; ITEM_COUNT]); + let array_b = Int8Array::from_slice([2; ITEM_COUNT]); + let expected = BooleanArray::from_slice([false; ITEM_COUNT]); let result = gt_eq(&array_a, &array_b); assert_eq!(result, expected) diff --git a/src/compute/sort/binary.rs b/src/compute/sort/binary.rs index cf0992b4b99..8110e8dae6c 100644 --- a/src/compute/sort/binary.rs +++ b/src/compute/sort/binary.rs @@ -10,7 +10,7 @@ pub(super) fn indices_sorted_unstable_by( options: &SortOptions, limit: Option, ) -> PrimitiveArray { - let get = |idx| unsafe { array.value_unchecked(idx as usize) }; + let get = |idx| unsafe { array.value_unchecked(idx) }; let cmp = |lhs: &&[u8], rhs: &&[u8]| lhs.cmp(rhs); common::indices_sorted_unstable_by(array.validity(), get, cmp, array.len(), options, limit) } diff --git a/src/compute/sort/utf8.rs b/src/compute/sort/utf8.rs index 0d7190eb23f..adba92ea2de 100644 --- a/src/compute/sort/utf8.rs +++ b/src/compute/sort/utf8.rs @@ -10,7 +10,7 @@ pub(super) fn indices_sorted_unstable_by( options: &SortOptions, limit: Option, ) -> PrimitiveArray { - let get = |idx| unsafe { array.value_unchecked(idx as usize) }; + let get = |idx| unsafe { array.value_unchecked(idx) }; let cmp = |lhs: &&str, rhs: &&str| lhs.cmp(rhs); common::indices_sorted_unstable_by(array.validity(), get, cmp, array.len(), options, limit) } diff --git a/src/compute/substring.rs b/src/compute/substring.rs index 95618c6a007..7a20114ed10 100644 --- a/src/compute/substring.rs +++ b/src/compute/substring.rs @@ -90,7 +90,7 @@ fn binary_substring( } else { length_i + start }; - let start = start.max(windows[0]).min(windows[1]); + let start = start.clamp(windows[0], windows[1]); let length: O = length .unwrap_or(length_i) diff --git a/src/compute/window.rs b/src/compute/window.rs index 7752759f379..fb999318e60 100644 --- a/src/compute/window.rs +++ b/src/compute/window.rs @@ -52,7 +52,7 @@ pub fn shift(array: &dyn Array, offset: i64) -> Result> { let slice = array.slice(slice_offset, length); // Generate array with remaining `null` items - let nulls = abs(offset as i64) as usize; + let nulls = abs(offset) as usize; let null_array = new_null_array(array.data_type().clone(), nulls); diff --git a/src/io/avro/read/deserialize.rs b/src/io/avro/read/deserialize.rs index 54b7950a771..6d95fe19145 100644 --- a/src/io/avro/read/deserialize.rs +++ b/src/io/avro/read/deserialize.rs @@ -51,10 +51,10 @@ fn make_mutable( capacity, )) as Box } - DataType::FixedSizeBinary(size) => Box::new(MutableFixedSizeBinaryArray::with_capacity( - *size as usize, - capacity, - )) as Box, + DataType::FixedSizeBinary(size) => { + Box::new(MutableFixedSizeBinaryArray::with_capacity(*size, capacity)) + as Box + } DataType::Struct(fields) => { let values = fields .iter() @@ -195,7 +195,7 @@ fn deserialize_value<'a>( array.push(Some(value)) } PrimitiveType::Int64 => { - let value = util::zigzag_i64(&mut block)? as i64; + let value = util::zigzag_i64(&mut block)?; let array = array .as_mut_any() .downcast_mut::>() @@ -274,7 +274,7 @@ fn deserialize_value<'a>( .as_mut_any() .downcast_mut::>() .unwrap(); - array.push(Some(data as i128)) + array.push(Some(data)) } _ => unreachable!(), }, diff --git a/src/io/ipc/read/stream.rs b/src/io/ipc/read/stream.rs index cea6e08825f..6cf0e2904b7 100644 --- a/src/io/ipc/read/stream.rs +++ b/src/io/ipc/read/stream.rs @@ -48,7 +48,7 @@ pub fn read_stream_metadata(reader: &mut R) -> Result { .map_err(|_| Error::from(OutOfSpecKind::NegativeFooterLength))?; let mut buffer = vec![]; - buffer.try_reserve(length as usize)?; + buffer.try_reserve(length)?; reader .by_ref() .take(length as u64) @@ -135,7 +135,7 @@ fn read_next( } message_buffer.clear(); - message_buffer.try_reserve(meta_length as usize)?; + message_buffer.try_reserve(meta_length)?; reader .by_ref() .take(meta_length as u64) @@ -158,7 +158,7 @@ fn read_next( match header { arrow_format::ipc::MessageHeaderRef::RecordBatch(batch) => { data_buffer.clear(); - data_buffer.try_reserve(block_length as usize)?; + data_buffer.try_reserve(block_length)?; reader .by_ref() .take(block_length as u64) @@ -193,7 +193,7 @@ fn read_next( } arrow_format::ipc::MessageHeaderRef::DictionaryBatch(batch) => { data_buffer.clear(); - data_buffer.try_reserve(block_length as usize)?; + data_buffer.try_reserve(block_length)?; reader .by_ref() .take(block_length as u64) diff --git a/src/io/ipc/read/stream_async.rs b/src/io/ipc/read/stream_async.rs index 4c8556f0ea1..a1ba5f530db 100644 --- a/src/io/ipc/read/stream_async.rs +++ b/src/io/ipc/read/stream_async.rs @@ -58,7 +58,7 @@ pub async fn read_stream_metadata_async( .map_err(|_| Error::from(OutOfSpecKind::NegativeFooterLength))?; let mut meta_buffer = vec![]; - meta_buffer.try_reserve(meta_len as usize)?; + meta_buffer.try_reserve(meta_len)?; reader .take(meta_len as u64) .read_to_end(&mut meta_buffer) @@ -109,7 +109,7 @@ async fn maybe_next( } state.message_buffer.clear(); - state.message_buffer.try_reserve(meta_length as usize)?; + state.message_buffer.try_reserve(meta_length)?; (&mut state.reader) .take(meta_length as u64) .read_to_end(&mut state.message_buffer) @@ -132,7 +132,7 @@ async fn maybe_next( match header { arrow_format::ipc::MessageHeaderRef::RecordBatch(batch) => { state.data_buffer.clear(); - state.data_buffer.try_reserve(block_length as usize)?; + state.data_buffer.try_reserve(block_length)?; (&mut state.reader) .take(block_length as u64) .read_to_end(&mut state.data_buffer) @@ -155,7 +155,7 @@ async fn maybe_next( } arrow_format::ipc::MessageHeaderRef::DictionaryBatch(batch) => { state.data_buffer.clear(); - state.data_buffer.try_reserve(block_length as usize)?; + state.data_buffer.try_reserve(block_length)?; (&mut state.reader) .take(block_length as u64) .read_to_end(&mut state.data_buffer) diff --git a/src/io/ipc/write/common.rs b/src/io/ipc/write/common.rs index 1672d69bc01..e2bff77a7d5 100644 --- a/src/io/ipc/write/common.rs +++ b/src/io/ipc/write/common.rs @@ -371,7 +371,7 @@ pub struct EncodedData { /// Calculate an 8-byte boundary and return the number of bytes needed to pad to 8 bytes #[inline] pub(crate) fn pad_to_64(len: usize) -> usize { - (((len + 63) & !63) - len) as usize + ((len + 63) & !63) - len } /// An array [`Chunk`] with optional accompanying IPC fields. diff --git a/src/io/odbc/read/schema.rs b/src/io/odbc/read/schema.rs index dba4c233738..c679500b7ae 100644 --- a/src/io/odbc/read/schema.rs +++ b/src/io/odbc/read/schema.rs @@ -23,7 +23,7 @@ pub fn infer_schema(resut_set_metadata: &impl ResultSetMetadata) -> Result Field { Field::new( - &column_description + column_description .name_to_string() .expect("Column name must be representable in utf8"), column_to_data_type(&column_description.data_type), diff --git a/src/io/parquet/read/deserialize/simple.rs b/src/io/parquet/read/deserialize/simple.rs index 28dfaa4812e..8b8ad6db452 100644 --- a/src/io/parquet/read/deserialize/simple.rs +++ b/src/io/parquet/read/deserialize/simple.rs @@ -127,7 +127,7 @@ pub fn page_iter_to_arrays<'a, I: Pages + 'a>( data_type, num_rows, chunk_size, - |x: i32| x as i32, + |x: i32| x, ))), Timestamp(time_unit, _) => { @@ -255,7 +255,7 @@ pub fn page_iter_to_arrays<'a, I: Pages + 'a>( data_type, num_rows, chunk_size, - |x: i64| x as i64, + |x: i64| x, ))), UInt64 => dyn_iter(iden(primitive::IntegerIter::new( pages, @@ -493,7 +493,7 @@ fn dict_read<'a, K: DictionaryKey, I: Pages + 'a>( data_type, num_rows, chunk_size, - |x: i32| x as i32, + |x: i32| x, )) } diff --git a/src/io/parquet/read/row_group.rs b/src/io/parquet/read/row_group.rs index ed4d724b639..e17dba30fed 100644 --- a/src/io/parquet/read/row_group.rs +++ b/src/io/parquet/read/row_group.rs @@ -134,10 +134,7 @@ where let mut chunk = vec![]; chunk.try_reserve(length as usize)?; - reader - .by_ref() - .take(length as u64) - .read_to_end(&mut chunk)?; + reader.by_ref().take(length).read_to_end(&mut chunk)?; Ok((meta, chunk)) } @@ -155,7 +152,7 @@ where let mut chunk = vec![]; chunk.try_reserve(length as usize)?; - reader.take(length as u64).read_to_end(&mut chunk).await?; + reader.take(length).read_to_end(&mut chunk).await?; Result::Ok((meta, chunk)) } diff --git a/src/io/parquet/read/statistics/mod.rs b/src/io/parquet/read/statistics/mod.rs index ad30859cfa5..599fa0102f1 100644 --- a/src/io/parquet/read/statistics/mod.rs +++ b/src/io/parquet/read/statistics/mod.rs @@ -441,7 +441,7 @@ fn push( Boolean => boolean::push(from, min, max), Int8 => primitive::push(from, min, max, |x: i32| Ok(x as i8)), Int16 => primitive::push(from, min, max, |x: i32| Ok(x as i16)), - Date32 | Time32(_) => primitive::push(from, min, max, |x: i32| Ok(x as i32)), + Date32 | Time32(_) => primitive::push::(from, min, max, Ok), Interval(IntervalUnit::YearMonth) => fixlen::push_year_month(from, min, max), Interval(IntervalUnit::DayTime) => fixlen::push_days_ms(from, min, max), UInt8 => primitive::push(from, min, max, |x: i32| Ok(x as u8)), @@ -455,9 +455,9 @@ fn push( other ))), }, - Int32 => primitive::push(from, min, max, |x: i32| Ok(x as i32)), + Int32 => primitive::push::(from, min, max, Ok), Int64 | Date64 | Time64(_) | Duration(_) => { - primitive::push(from, min, max, |x: i64| Ok(x as i64)) + primitive::push::(from, min, max, Ok) } UInt64 => primitive::push(from, min, max, |x: i64| Ok(x as u64)), Timestamp(time_unit, _) => { @@ -498,8 +498,8 @@ fn push( }) } } - Float32 => primitive::push(from, min, max, |x: f32| Ok(x as f32)), - Float64 => primitive::push(from, min, max, |x: f64| Ok(x as f64)), + Float32 => primitive::push::(from, min, max, Ok), + Float64 => primitive::push::(from, min, max, Ok), Decimal(_, _) => match physical_type { ParquetPhysicalType::Int32 => primitive::push(from, min, max, |x: i32| Ok(x as i128)), ParquetPhysicalType::Int64 => primitive::push(from, min, max, |x: i64| Ok(x as i128)), diff --git a/src/io/parquet/write/nested/def.rs b/src/io/parquet/write/nested/def.rs index 4e82ad88af3..395f73b913e 100644 --- a/src/io/parquet/write/nested/def.rs +++ b/src/io/parquet/write/nested/def.rs @@ -117,7 +117,7 @@ impl<'a> Iterator for DefLevelsIter<'a> { if *self.remaining.last().unwrap() > 0 { *self.remaining.last_mut().unwrap() -= 1; - let primitive = self.primitive_validity.next()?.0 as u32; + let primitive = self.primitive_validity.next()?.0; let r = Some(self.total + primitive); for level in 0..self.current_level - 1 { @@ -130,7 +130,7 @@ impl<'a> Iterator for DefLevelsIter<'a> { } if self.remaining[0] == 0 { self.current_level -= 1; - self.total -= self.validity[0] as u32; + self.total -= self.validity[0]; } self.remaining_values -= 1; return r;