From 60529b5fec1c869c0d2f9e0386bf11b6d02f2f15 Mon Sep 17 00:00:00 2001 From: Mikhail Cheshkov Date: Mon, 26 Aug 2024 15:51:10 +0300 Subject: [PATCH] [WIP] Fix clippy warnings from toolchain bump --- arrow-flight/src/utils.rs | 4 +- arrow/benches/arithmetic_kernels.rs | 8 +-- arrow/benches/array_from_vec.rs | 8 +-- arrow/src/array/array.rs | 4 +- arrow/src/array/array_binary.rs | 2 +- arrow/src/array/array_boolean.rs | 2 +- arrow/src/array/array_dictionary.rs | 5 +- arrow/src/array/array_list.rs | 2 +- arrow/src/array/array_primitive.rs | 2 +- arrow/src/array/array_string.rs | 4 +- arrow/src/array/equal/mod.rs | 59 +++++++++---------- arrow/src/array/equal/utils.rs | 12 ++-- arrow/src/array/equal_json.rs | 40 ++++++------- arrow/src/array/ord.rs | 13 ++-- arrow/src/array/transform/boolean.rs | 2 +- arrow/src/array/transform/utils.rs | 2 +- arrow/src/buffer/immutable.rs | 6 +- arrow/src/buffer/mod.rs | 6 +- arrow/src/buffer/mutable.rs | 3 +- arrow/src/buffer/ops.rs | 10 ++-- arrow/src/compute/kernels/aggregate.rs | 4 +- arrow/src/compute/kernels/arithmetic.rs | 16 ++--- arrow/src/compute/kernels/boolean.rs | 8 +-- arrow/src/compute/kernels/cast.rs | 43 +++++++------- arrow/src/compute/kernels/cast_utils.rs | 11 ++-- arrow/src/compute/kernels/comparison.rs | 6 +- arrow/src/compute/kernels/concat.rs | 5 +- arrow/src/compute/kernels/filter.rs | 2 +- arrow/src/compute/kernels/merge.rs | 2 +- arrow/src/compute/kernels/sort.rs | 4 +- arrow/src/compute/kernels/take.rs | 11 ++-- arrow/src/compute/kernels/temporal.rs | 2 +- arrow/src/compute/util.rs | 8 +-- arrow/src/csv/reader.rs | 10 ++-- arrow/src/csv/writer.rs | 2 +- arrow/src/datatypes/field.rs | 2 +- arrow/src/datatypes/mod.rs | 1 - arrow/src/datatypes/native.rs | 4 +- arrow/src/error.rs | 3 +- arrow/src/ipc/convert.rs | 4 +- arrow/src/ipc/reader.rs | 6 +- arrow/src/ipc/writer.rs | 27 +++++---- arrow/src/json/reader.rs | 18 ++---- arrow/src/json/writer.rs | 4 +- arrow/src/tensor.rs | 6 +- arrow/src/util/bit_util.rs | 2 +- arrow/src/util/data_gen.rs | 2 +- arrow/src/util/display.rs | 2 +- arrow/src/util/integration_util.rs | 2 +- arrow/src/util/test_util.rs | 4 +- .../integration_test.rs | 4 +- .../integration_test.rs | 2 +- integration-testing/src/lib.rs | 6 +- parquet/benches/arrow_writer.rs | 2 +- parquet/src/arrow/arrow_array_reader.rs | 8 +-- parquet/src/arrow/arrow_writer.rs | 44 +++++++------- parquet/src/arrow/schema.rs | 2 +- parquet/src/column/page.rs | 6 +- parquet/src/column/writer.rs | 4 +- parquet/src/encodings/encoding.rs | 2 +- parquet/src/file/serialized_reader.rs | 2 +- parquet/src/record/reader.rs | 14 ++--- parquet/src/schema/printer.rs | 6 +- parquet/src/schema/types.rs | 4 +- parquet/src/util/bit_util.rs | 4 +- 65 files changed, 251 insertions(+), 274 deletions(-) diff --git a/arrow-flight/src/utils.rs b/arrow-flight/src/utils.rs index 0ebface03572..9232acc2aefb 100644 --- a/arrow-flight/src/utils.rs +++ b/arrow-flight/src/utils.rs @@ -36,7 +36,7 @@ pub fn flight_data_from_arrow_batch( let mut dictionary_tracker = writer::DictionaryTracker::new(false); let (encoded_dictionaries, encoded_batch) = data_gen - .encoded_batch(batch, &mut dictionary_tracker, &options) + .encoded_batch(batch, &mut dictionary_tracker, options) .expect("DictionaryTracker configured above to not error on replacement"); let flight_dictionaries = encoded_dictionaries.into_iter().map(Into::into).collect(); @@ -68,7 +68,7 @@ pub fn flight_data_to_arrow_batch( &data.data_body, batch, schema, - &dictionaries_by_field, + dictionaries_by_field, ) })? } diff --git a/arrow/benches/arithmetic_kernels.rs b/arrow/benches/arithmetic_kernels.rs index 721157e2846a..bbe412366988 100644 --- a/arrow/benches/arithmetic_kernels.rs +++ b/arrow/benches/arithmetic_kernels.rs @@ -44,24 +44,24 @@ fn bench_add(arr_a: &ArrayRef, arr_b: &ArrayRef) { fn bench_subtract(arr_a: &ArrayRef, arr_b: &ArrayRef) { let arr_a = arr_a.as_any().downcast_ref::().unwrap(); let arr_b = arr_b.as_any().downcast_ref::().unwrap(); - criterion::black_box(subtract(&arr_a, &arr_b).unwrap()); + criterion::black_box(subtract(arr_a, arr_b).unwrap()); } fn bench_multiply(arr_a: &ArrayRef, arr_b: &ArrayRef) { let arr_a = arr_a.as_any().downcast_ref::().unwrap(); let arr_b = arr_b.as_any().downcast_ref::().unwrap(); - criterion::black_box(multiply(&arr_a, &arr_b).unwrap()); + criterion::black_box(multiply(arr_a, arr_b).unwrap()); } fn bench_divide(arr_a: &ArrayRef, arr_b: &ArrayRef) { let arr_a = arr_a.as_any().downcast_ref::().unwrap(); let arr_b = arr_b.as_any().downcast_ref::().unwrap(); - criterion::black_box(divide(&arr_a, &arr_b).unwrap()); + criterion::black_box(divide(arr_a, arr_b).unwrap()); } fn bench_divide_scalar(array: &ArrayRef, divisor: f32) { let array = array.as_any().downcast_ref::().unwrap(); - criterion::black_box(divide_scalar(&array, divisor).unwrap()); + criterion::black_box(divide_scalar(array, divisor).unwrap()); } fn bench_limit(arr_a: &ArrayRef, max: usize) { diff --git a/arrow/benches/array_from_vec.rs b/arrow/benches/array_from_vec.rs index 7740c6bc34e0..01ddf3503236 100644 --- a/arrow/benches/array_from_vec.rs +++ b/arrow/benches/array_from_vec.rs @@ -97,22 +97,22 @@ fn criterion_benchmark(c: &mut Criterion) { let (field1, strings, field2, ints) = struct_array_values(128); c.bench_function("struct_array_from_vec 128", |b| { - b.iter(|| struct_array_from_vec(&field1, &strings, &field2, &ints)) + b.iter(|| struct_array_from_vec(field1, &strings, field2, &ints)) }); let (field1, strings, field2, ints) = struct_array_values(256); c.bench_function("struct_array_from_vec 256", |b| { - b.iter(|| struct_array_from_vec(&field1, &strings, &field2, &ints)) + b.iter(|| struct_array_from_vec(field1, &strings, field2, &ints)) }); let (field1, strings, field2, ints) = struct_array_values(512); c.bench_function("struct_array_from_vec 512", |b| { - b.iter(|| struct_array_from_vec(&field1, &strings, &field2, &ints)) + b.iter(|| struct_array_from_vec(field1, &strings, field2, &ints)) }); let (field1, strings, field2, ints) = struct_array_values(1024); c.bench_function("struct_array_from_vec 1024", |b| { - b.iter(|| struct_array_from_vec(&field1, &strings, &field2, &ints)) + b.iter(|| struct_array_from_vec(field1, &strings, field2, &ints)) }); } diff --git a/arrow/src/array/array.rs b/arrow/src/array/array.rs index baa89967c5b2..3b244b3d4eb5 100644 --- a/arrow/src/array/array.rs +++ b/arrow/src/array/array.rs @@ -623,7 +623,7 @@ where writeln!(f, " null,")?; } else { write!(f, " ")?; - print_item(&array, i, f)?; + print_item(array, i, f)?; writeln!(f, ",")?; } } @@ -639,7 +639,7 @@ where writeln!(f, " null,")?; } else { write!(f, " ")?; - print_item(&array, i, f)?; + print_item(array, i, f)?; writeln!(f, ",")?; } } diff --git a/arrow/src/array/array_binary.rs b/arrow/src/array/array_binary.rs index 415693c1e9e0..0b740190f859 100644 --- a/arrow/src/array/array_binary.rs +++ b/arrow/src/array/array_binary.rs @@ -174,7 +174,7 @@ impl GenericBinaryArray { impl<'a, T: BinaryOffsetSizeTrait> GenericBinaryArray { /// constructs a new iterator pub fn iter(&'a self) -> GenericBinaryIter<'a, T> { - GenericBinaryIter::<'a, T>::new(&self) + GenericBinaryIter::<'a, T>::new(self) } } diff --git a/arrow/src/array/array_boolean.rs b/arrow/src/array/array_boolean.rs index 37080fe5a8c7..ef0ef8cf6d5b 100644 --- a/arrow/src/array/array_boolean.rs +++ b/arrow/src/array/array_boolean.rs @@ -167,7 +167,7 @@ impl<'a> IntoIterator for &'a BooleanArray { impl<'a> BooleanArray { /// constructs a new iterator pub fn iter(&'a self) -> BooleanIter<'a> { - BooleanIter::<'a>::new(&self) + BooleanIter::<'a>::new(self) } } diff --git a/arrow/src/array/array_dictionary.rs b/arrow/src/array/array_dictionary.rs index 05b1dd333519..c61b669a6b33 100644 --- a/arrow/src/array/array_dictionary.rs +++ b/arrow/src/array/array_dictionary.rs @@ -68,7 +68,7 @@ pub struct DictionaryArray { is_ordered: bool, } -impl<'a, K: ArrowPrimitiveType> DictionaryArray { +impl DictionaryArray { /// Return an array view of the keys of this dictionary as a PrimitiveArray. pub fn keys(&self) -> &PrimitiveArray { &self.keys @@ -81,8 +81,7 @@ impl<'a, K: ArrowPrimitiveType> DictionaryArray { (0..rd_buf.len()) .position(|i| rd_buf.value(i) == value) - .map(K::Native::from_usize) - .flatten() + .and_then(K::Native::from_usize) } /// Returns a reference to the dictionary values array diff --git a/arrow/src/array/array_list.rs b/arrow/src/array/array_list.rs index 0efb65c99d5a..be3148a9ddef 100644 --- a/arrow/src/array/array_list.rs +++ b/arrow/src/array/array_list.rs @@ -110,7 +110,7 @@ impl GenericListArray { /// constructs a new iterator pub fn iter<'a>(&'a self) -> GenericListArrayIter<'a, OffsetSize> { - GenericListArrayIter::<'a, OffsetSize>::new(&self) + GenericListArrayIter::<'a, OffsetSize>::new(self) } #[inline] diff --git a/arrow/src/array/array_primitive.rs b/arrow/src/array/array_primitive.rs index 49f163a494fe..8c02525cbe62 100644 --- a/arrow/src/array/array_primitive.rs +++ b/arrow/src/array/array_primitive.rs @@ -300,7 +300,7 @@ impl<'a, T: ArrowPrimitiveType> IntoIterator for &'a PrimitiveArray { impl<'a, T: ArrowPrimitiveType> PrimitiveArray { /// constructs a new iterator pub fn iter(&'a self) -> PrimitiveIter<'a, T> { - PrimitiveIter::<'a, T>::new(&self) + PrimitiveIter::<'a, T>::new(self) } } diff --git a/arrow/src/array/array_string.rs b/arrow/src/array/array_string.rs index ec703e28f5ac..a5a79394dbcc 100644 --- a/arrow/src/array/array_string.rs +++ b/arrow/src/array/array_string.rs @@ -208,7 +208,7 @@ impl GenericStringArray { } } -impl<'a, Ptr, OffsetSize: StringOffsetSizeTrait> FromIterator> +impl FromIterator> for GenericStringArray where Ptr: AsRef, @@ -264,7 +264,7 @@ impl<'a, T: StringOffsetSizeTrait> IntoIterator for &'a GenericStringArray { impl<'a, T: StringOffsetSizeTrait> GenericStringArray { /// constructs a new iterator pub fn iter(&'a self) -> GenericStringIter<'a, T> { - GenericStringIter::<'a, T>::new(&self) + GenericStringIter::<'a, T>::new(self) } } diff --git a/arrow/src/array/equal/mod.rs b/arrow/src/array/equal/mod.rs index f87ad7ecb6e2..e169f8e2aca3 100644 --- a/arrow/src/array/equal/mod.rs +++ b/arrow/src/array/equal/mod.rs @@ -641,24 +641,22 @@ mod tests { #[test] fn test_list_equal() { - let a = create_list_array(&[Some(&[1, 2, 3]), Some(&[4, 5, 6])]); - let b = create_list_array(&[Some(&[1, 2, 3]), Some(&[4, 5, 6])]); + let a = create_list_array([Some(&[1, 2, 3]), Some(&[4, 5, 6])]); + let b = create_list_array([Some(&[1, 2, 3]), Some(&[4, 5, 6])]); test_equal(&a, &b, true); - let b = create_list_array(&[Some(&[1, 2, 3]), Some(&[4, 5, 7])]); + let b = create_list_array([Some(&[1, 2, 3]), Some(&[4, 5, 7])]); test_equal(&a, &b, false); } // Test the case where null_count > 0 #[test] fn test_list_null() { - let a = - create_list_array(&[Some(&[1, 2]), None, None, Some(&[3, 4]), None, None]); - let b = - create_list_array(&[Some(&[1, 2]), None, None, Some(&[3, 4]), None, None]); + let a = create_list_array([Some(&[1, 2]), None, None, Some(&[3, 4]), None, None]); + let b = create_list_array([Some(&[1, 2]), None, None, Some(&[3, 4]), None, None]); test_equal(&a, &b, true); - let b = create_list_array(&[ + let b = create_list_array([ Some(&[1, 2]), None, Some(&[5, 6]), @@ -668,8 +666,7 @@ mod tests { ]); test_equal(&a, &b, false); - let b = - create_list_array(&[Some(&[1, 2]), None, None, Some(&[3, 5]), None, None]); + let b = create_list_array([Some(&[1, 2]), None, None, Some(&[3, 5]), None, None]); test_equal(&a, &b, false); // a list where the nullness of values is determined by the list's bitmap @@ -711,10 +708,8 @@ mod tests { // Test the case where offset != 0 #[test] fn test_list_offsets() { - let a = - create_list_array(&[Some(&[1, 2]), None, None, Some(&[3, 4]), None, None]); - let b = - create_list_array(&[Some(&[1, 2]), None, None, Some(&[3, 5]), None, None]); + let a = create_list_array([Some(&[1, 2]), None, None, Some(&[3, 4]), None, None]); + let b = create_list_array([Some(&[1, 2]), None, None, Some(&[3, 5]), None, None]); let a_slice = a.slice(0, 3); let b_slice = b.slice(0, 3); @@ -746,32 +741,32 @@ mod tests { #[test] fn test_fixed_size_binary_equal() { - let a = create_fixed_size_binary_array(&[Some(b"hello"), Some(b"world")]); - let b = create_fixed_size_binary_array(&[Some(b"hello"), Some(b"world")]); + let a = create_fixed_size_binary_array([Some(b"hello"), Some(b"world")]); + let b = create_fixed_size_binary_array([Some(b"hello"), Some(b"world")]); test_equal(&a, &b, true); - let b = create_fixed_size_binary_array(&[Some(b"hello"), Some(b"arrow")]); + let b = create_fixed_size_binary_array([Some(b"hello"), Some(b"arrow")]); test_equal(&a, &b, false); } // Test the case where null_count > 0 #[test] fn test_fixed_size_binary_null() { - let a = create_fixed_size_binary_array(&[Some(b"hello"), None, Some(b"world")]); - let b = create_fixed_size_binary_array(&[Some(b"hello"), None, Some(b"world")]); + let a = create_fixed_size_binary_array([Some(b"hello"), None, Some(b"world")]); + let b = create_fixed_size_binary_array([Some(b"hello"), None, Some(b"world")]); test_equal(&a, &b, true); - let b = create_fixed_size_binary_array(&[Some(b"hello"), Some(b"world"), None]); + let b = create_fixed_size_binary_array([Some(b"hello"), Some(b"world"), None]); test_equal(&a, &b, false); - let b = create_fixed_size_binary_array(&[Some(b"hello"), None, Some(b"arrow")]); + let b = create_fixed_size_binary_array([Some(b"hello"), None, Some(b"arrow")]); test_equal(&a, &b, false); } #[test] fn test_fixed_size_binary_offsets() { // Test the case where offset != 0 - let a = create_fixed_size_binary_array(&[ + let a = create_fixed_size_binary_array([ Some(b"hello"), None, None, @@ -779,7 +774,7 @@ mod tests { None, None, ]); - let b = create_fixed_size_binary_array(&[ + let b = create_fixed_size_binary_array([ Some(b"hello"), None, None, @@ -918,18 +913,18 @@ mod tests { #[test] fn test_fixed_size_list_equal() { - let a = create_fixed_size_list_array(&[Some(&[1, 2, 3]), Some(&[4, 5, 6])]); - let b = create_fixed_size_list_array(&[Some(&[1, 2, 3]), Some(&[4, 5, 6])]); + let a = create_fixed_size_list_array([Some(&[1, 2, 3]), Some(&[4, 5, 6])]); + let b = create_fixed_size_list_array([Some(&[1, 2, 3]), Some(&[4, 5, 6])]); test_equal(&a, &b, true); - let b = create_fixed_size_list_array(&[Some(&[1, 2, 3]), Some(&[4, 5, 7])]); + let b = create_fixed_size_list_array([Some(&[1, 2, 3]), Some(&[4, 5, 7])]); test_equal(&a, &b, false); } // Test the case where null_count > 0 #[test] fn test_fixed_list_null() { - let a = create_fixed_size_list_array(&[ + let a = create_fixed_size_list_array([ Some(&[1, 2, 3]), None, None, @@ -937,7 +932,7 @@ mod tests { None, None, ]); - let b = create_fixed_size_list_array(&[ + let b = create_fixed_size_list_array([ Some(&[1, 2, 3]), None, None, @@ -947,7 +942,7 @@ mod tests { ]); test_equal(&a, &b, true); - let b = create_fixed_size_list_array(&[ + let b = create_fixed_size_list_array([ Some(&[1, 2, 3]), None, Some(&[7, 8, 9]), @@ -957,7 +952,7 @@ mod tests { ]); test_equal(&a, &b, false); - let b = create_fixed_size_list_array(&[ + let b = create_fixed_size_list_array([ Some(&[1, 2, 3]), None, None, @@ -971,7 +966,7 @@ mod tests { #[test] fn test_fixed_list_offsets() { // Test the case where offset != 0 - let a = create_fixed_size_list_array(&[ + let a = create_fixed_size_list_array([ Some(&[1, 2, 3]), None, None, @@ -979,7 +974,7 @@ mod tests { None, None, ]); - let b = create_fixed_size_list_array(&[ + let b = create_fixed_size_list_array([ Some(&[1, 2, 3]), None, None, diff --git a/arrow/src/array/equal/utils.rs b/arrow/src/array/equal/utils.rs index d0108d236491..6038d610985f 100644 --- a/arrow/src/array/equal/utils.rs +++ b/arrow/src/array/equal/utils.rs @@ -121,14 +121,14 @@ pub(super) fn child_logical_null_buffer( let array_offset = parent_data.offset(); let bitmap_len = bit_util::ceil(parent_len * len, 8); let mut buffer = MutableBuffer::from_len_zeroed(bitmap_len); - let mut null_slice = buffer.as_slice_mut(); + let null_slice = buffer.as_slice_mut(); (array_offset..parent_len + array_offset).for_each(|index| { let start = index * len; let end = start + len; let mask = parent_bitmap.is_set(index); (start..end).for_each(|child_index| { if mask && self_null_bitmap.is_set(child_index) { - bit_util::set_bit(&mut null_slice, child_index); + bit_util::set_bit(null_slice, child_index); } }); }); @@ -151,12 +151,12 @@ pub(super) fn child_logical_null_buffer( // slow path let array_offset = parent_data.offset(); let mut buffer = MutableBuffer::new_null(parent_len); - let mut null_slice = buffer.as_slice_mut(); + let null_slice = buffer.as_slice_mut(); (0..parent_len).for_each(|index| { if parent_bitmap.is_set(index + array_offset) && self_null_bitmap.is_set(index + array_offset) { - bit_util::set_bit(&mut null_slice, index); + bit_util::set_bit(null_slice, index); } }); Some(buffer.into()) @@ -182,7 +182,7 @@ fn logical_list_bitmap( let offset_start = offsets.first().unwrap().to_usize().unwrap(); let offset_len = offsets.get(parent_data.len()).unwrap().to_usize().unwrap(); let mut buffer = MutableBuffer::new_null(offset_len - offset_start); - let mut null_slice = buffer.as_slice_mut(); + let null_slice = buffer.as_slice_mut(); offsets .windows(2) @@ -194,7 +194,7 @@ fn logical_list_bitmap( let mask = parent_bitmap.is_set(index); (start..end).for_each(|child_index| { if mask && child_bitmap.is_set(child_index) { - bit_util::set_bit(&mut null_slice, child_index - offset_start); + bit_util::set_bit(null_slice, child_index - offset_start); } }); }); diff --git a/arrow/src/array/equal_json.rs b/arrow/src/array/equal_json.rs index 043174b9ac80..fd4bcda4ae48 100644 --- a/arrow/src/array/equal_json.rs +++ b/arrow/src/array/equal_json.rs @@ -66,7 +66,7 @@ impl JsonEqual for BooleanArray { impl PartialEq for PrimitiveArray { fn eq(&self, json: &Value) -> bool { match json { - Value::Array(array) => self.equals_json_values(&array), + Value::Array(array) => self.equals_json_values(array), _ => false, } } @@ -75,7 +75,7 @@ impl PartialEq for PrimitiveArray { impl PartialEq> for Value { fn eq(&self, arrow: &PrimitiveArray) -> bool { match self { - Value::Array(array) => arrow.equals_json_values(&array), + Value::Array(array) => arrow.equals_json_values(array), _ => false, } } @@ -204,7 +204,7 @@ impl JsonEqual for StructArray { impl PartialEq for StructArray { fn eq(&self, json: &Value) -> bool { match json { - Value::Array(json_array) => self.equals_json_values(&json_array), + Value::Array(json_array) => self.equals_json_values(json_array), _ => false, } } @@ -213,7 +213,7 @@ impl PartialEq for StructArray { impl PartialEq for Value { fn eq(&self, arrow: &StructArray) -> bool { match self { - Value::Array(json_array) => arrow.equals_json_values(&json_array), + Value::Array(json_array) => arrow.equals_json_values(json_array), _ => false, } } @@ -244,7 +244,7 @@ impl PartialEq { fn eq(&self, json: &Value) -> bool { match json { - Value::Array(json_array) => self.equals_json_values(&json_array), + Value::Array(json_array) => self.equals_json_values(json_array), _ => false, } } @@ -255,7 +255,7 @@ impl PartialEq { fn eq(&self, arrow: &GenericBinaryArray) -> bool { match self { - Value::Array(json_array) => arrow.equals_json_values(&json_array), + Value::Array(json_array) => arrow.equals_json_values(json_array), _ => false, } } @@ -280,7 +280,7 @@ impl PartialEq { fn eq(&self, json: &Value) -> bool { match json { - Value::Array(json_array) => self.equals_json_values(&json_array), + Value::Array(json_array) => self.equals_json_values(json_array), _ => false, } } @@ -291,7 +291,7 @@ impl PartialEq { fn eq(&self, arrow: &GenericStringArray) -> bool { match self { - Value::Array(json_array) => arrow.equals_json_values(&json_array), + Value::Array(json_array) => arrow.equals_json_values(json_array), _ => false, } } @@ -320,7 +320,7 @@ impl JsonEqual for FixedSizeBinaryArray { impl PartialEq for FixedSizeBinaryArray { fn eq(&self, json: &Value) -> bool { match json { - Value::Array(json_array) => self.equals_json_values(&json_array), + Value::Array(json_array) => self.equals_json_values(json_array), _ => false, } } @@ -329,7 +329,7 @@ impl PartialEq for FixedSizeBinaryArray { impl PartialEq for Value { fn eq(&self, arrow: &FixedSizeBinaryArray) -> bool { match self { - Value::Array(json_array) => arrow.equals_json_values(&json_array), + Value::Array(json_array) => arrow.equals_json_values(json_array), _ => false, } } @@ -357,7 +357,7 @@ impl JsonEqual for DecimalArray { impl PartialEq for DecimalArray { fn eq(&self, json: &Value) -> bool { match json { - Value::Array(json_array) => self.equals_json_values(&json_array), + Value::Array(json_array) => self.equals_json_values(json_array), _ => false, } } @@ -366,7 +366,7 @@ impl PartialEq for DecimalArray { impl PartialEq for Value { fn eq(&self, arrow: &DecimalArray) -> bool { match self { - Value::Array(json_array) => arrow.equals_json_values(&json_array), + Value::Array(json_array) => arrow.equals_json_values(json_array), _ => false, } } @@ -394,7 +394,7 @@ impl JsonEqual for NullArray { impl PartialEq for Value { fn eq(&self, arrow: &NullArray) -> bool { match self { - Value::Array(json_array) => arrow.equals_json_values(&json_array), + Value::Array(json_array) => arrow.equals_json_values(json_array), _ => false, } } @@ -403,7 +403,7 @@ impl PartialEq for Value { impl PartialEq for NullArray { fn eq(&self, json: &Value) -> bool { match json { - Value::Array(json_array) => self.equals_json_values(&json_array), + Value::Array(json_array) => self.equals_json_values(json_array), _ => false, } } @@ -510,7 +510,7 @@ mod tests { // Test equal case let arrow_array = create_list_array( &mut ListBuilder::new(Int32Builder::new(10)), - &[Some(&[1, 2, 3]), None, Some(&[4, 5, 6])], + [Some(&[1, 2, 3]), None, Some(&[4, 5, 6])], ) .unwrap(); let json_array: Value = serde_json::from_str( @@ -529,7 +529,7 @@ mod tests { // Test unequal case let arrow_array = create_list_array( &mut ListBuilder::new(Int32Builder::new(10)), - &[Some(&[1, 2, 3]), None, Some(&[4, 5, 6])], + [Some(&[1, 2, 3]), None, Some(&[4, 5, 6])], ) .unwrap(); let json_array: Value = serde_json::from_str( @@ -548,7 +548,7 @@ mod tests { // Test incorrect type case let arrow_array = create_list_array( &mut ListBuilder::new(Int32Builder::new(10)), - &[Some(&[1, 2, 3]), None, Some(&[4, 5, 6])], + [Some(&[1, 2, 3]), None, Some(&[4, 5, 6])], ) .unwrap(); let json_array: Value = serde_json::from_str( @@ -568,7 +568,7 @@ mod tests { // Test equal case let arrow_array = create_fixed_size_list_array( &mut FixedSizeListBuilder::new(Int32Builder::new(10), 3), - &[Some(&[1, 2, 3]), None, Some(&[4, 5, 6])], + [Some(&[1, 2, 3]), None, Some(&[4, 5, 6])], ) .unwrap(); let json_array: Value = serde_json::from_str( @@ -589,7 +589,7 @@ mod tests { // Test unequal case let arrow_array = create_fixed_size_list_array( &mut FixedSizeListBuilder::new(Int32Builder::new(10), 3), - &[Some(&[1, 2, 3]), None, Some(&[4, 5, 6])], + [Some(&[1, 2, 3]), None, Some(&[4, 5, 6])], ) .unwrap(); let json_array: Value = serde_json::from_str( @@ -608,7 +608,7 @@ mod tests { // Test incorrect type case let arrow_array = create_fixed_size_list_array( &mut FixedSizeListBuilder::new(Int32Builder::new(10), 3), - &[Some(&[1, 2, 3]), None, Some(&[4, 5, 6])], + [Some(&[1, 2, 3]), None, Some(&[4, 5, 6])], ) .unwrap(); let json_array: Value = serde_json::from_str( diff --git a/arrow/src/array/ord.rs b/arrow/src/array/ord.rs index 085201d575b2..75d4f2893e7d 100644 --- a/arrow/src/array/ord.rs +++ b/arrow/src/array/ord.rs @@ -56,14 +56,11 @@ where Box::new(move |i, j| left.value(i).total_cmp(right.value(j))) } -fn compare_string(left: &Array, right: &Array) -> DynComparator -where - T: StringOffsetSizeTrait, -{ +fn compare_string(left: &Array, right: &Array) -> DynComparator { let left: StringArray = StringArray::from(left.data().clone()); let right: StringArray = StringArray::from(right.data().clone()); - Box::new(move |i, j| left.value(i).cmp(&right.value(j))) + Box::new(move |i, j| left.value(i).cmp(right.value(j))) } fn compare_dict_string(left: &Array, right: &Array) -> DynComparator @@ -83,7 +80,7 @@ where let key_right = right_keys.value(j).to_usize().unwrap(); let left = left_values.value(key_left); let right = right_values.value(key_right); - left.cmp(&right) + left.cmp(right) }) } @@ -215,8 +212,8 @@ pub fn build_compare(left: &Array, right: &Array) -> Result { (Duration(Nanosecond), Duration(Nanosecond)) => { compare_primitives::(left, right) } - (Utf8, Utf8) => compare_string::(left, right), - (LargeUtf8, LargeUtf8) => compare_string::(left, right), + (Utf8, Utf8) => compare_string(left, right), + (LargeUtf8, LargeUtf8) => compare_string(left, right), ( Dictionary(key_type_lhs, value_type_lhs), Dictionary(key_type_rhs, value_type_rhs), diff --git a/arrow/src/array/transform/boolean.rs b/arrow/src/array/transform/boolean.rs index 182914971732..456fb6e5e14e 100644 --- a/arrow/src/array/transform/boolean.rs +++ b/arrow/src/array/transform/boolean.rs @@ -29,7 +29,7 @@ pub(super) fn build_extend(array: &ArrayData) -> Extend { let buffer = &mut mutable.buffer1; resize_for_bits(buffer, mutable.len + len); set_bits( - &mut buffer.as_slice_mut(), + buffer.as_slice_mut(), values, mutable.len, array.offset() + start, diff --git a/arrow/src/array/transform/utils.rs b/arrow/src/array/transform/utils.rs index 8c718c70c176..f19a5c2d01b9 100644 --- a/arrow/src/array/transform/utils.rs +++ b/arrow/src/array/transform/utils.rs @@ -51,7 +51,7 @@ pub(super) fn extend_offsets( mut last_offset: T, offsets: &[T], ) { - buffer.reserve(offsets.len() * std::mem::size_of::()); + buffer.reserve(std::mem::size_of_val(offsets)); offsets.windows(2).for_each(|offsets| { // compute the new offset let length = offsets[1] - offsets[0]; diff --git a/arrow/src/buffer/immutable.rs b/arrow/src/buffer/immutable.rs index f4aeae9c5ac0..8789a70dd085 100644 --- a/arrow/src/buffer/immutable.rs +++ b/arrow/src/buffer/immutable.rs @@ -55,7 +55,7 @@ impl Buffer { /// Initializes a [Buffer] from a slice of items. pub fn from_slice_ref>(items: &T) -> Self { let slice = items.as_ref(); - let capacity = slice.len() * std::mem::size_of::(); + let capacity = std::mem::size_of_val(slice); let mut buffer = MutableBuffer::with_capacity(capacity); buffer.extend_from_slice(slice); buffer.into() @@ -188,14 +188,14 @@ impl Buffer { return self.slice(offset / 8); } - bitwise_unary_op_helper(&self, offset, len, |a| a) + bitwise_unary_op_helper(self, offset, len, |a| a) } /// Returns a `BitChunks` instance which can be used to iterate over this buffers bits /// in larger chunks and starting at arbitrary bit offsets. /// Note that both `offset` and `length` are measured in bits. pub fn bit_chunks(&self, offset: usize, len: usize) -> BitChunks { - BitChunks::new(&self.as_slice(), offset, len) + BitChunks::new(self.as_slice(), offset, len) } /// Returns the number of 1-bits in this buffer. diff --git a/arrow/src/buffer/mod.rs b/arrow/src/buffer/mod.rs index cc5c63b1c373..d8f63958e4d9 100644 --- a/arrow/src/buffer/mod.rs +++ b/arrow/src/buffer/mod.rs @@ -39,7 +39,7 @@ impl<'a, 'b> BitAnd<&'b Buffer> for &'a Buffer { } let len_in_bits = self.len() * 8; - Ok(buffer_bin_and(&self, 0, &rhs, 0, len_in_bits)) + Ok(buffer_bin_and(self, 0, rhs, 0, len_in_bits)) } } @@ -55,7 +55,7 @@ impl<'a, 'b> BitOr<&'b Buffer> for &'a Buffer { let len_in_bits = self.len() * 8; - Ok(buffer_bin_or(&self, 0, &rhs, 0, len_in_bits)) + Ok(buffer_bin_or(self, 0, rhs, 0, len_in_bits)) } } @@ -64,6 +64,6 @@ impl Not for &Buffer { fn not(self) -> Buffer { let len_in_bits = self.len() * 8; - buffer_unary_not(&self, 0, len_in_bits) + buffer_unary_not(self, 0, len_in_bits) } } diff --git a/arrow/src/buffer/mutable.rs b/arrow/src/buffer/mutable.rs index 7d336e0a938f..862ad57c0b7c 100644 --- a/arrow/src/buffer/mutable.rs +++ b/arrow/src/buffer/mutable.rs @@ -296,8 +296,7 @@ impl MutableBuffer { /// ``` #[inline] pub fn extend_from_slice(&mut self, items: &[T]) { - let len = items.len(); - let additional = len * std::mem::size_of::(); + let additional = std::mem::size_of_val(items); self.reserve(additional); unsafe { let dst = self.data.as_ptr().add(self.len); diff --git a/arrow/src/buffer/ops.rs b/arrow/src/buffer/ops.rs index 9d88149ee96e..e3fd92ad0e63 100644 --- a/arrow/src/buffer/ops.rs +++ b/arrow/src/buffer/ops.rs @@ -278,7 +278,7 @@ pub fn buffer_bin_and( // Note: do not target specific features like x86 without considering // other targets like wasm32, as those would fail to build -#[cfg(all(not(any(feature = "simd", feature = "avx512"))))] +#[cfg(not(any(feature = "simd", feature = "avx512")))] pub fn buffer_bin_and( left: &Buffer, left_offset_in_bits: usize, @@ -287,7 +287,7 @@ pub fn buffer_bin_and( len_in_bits: usize, ) -> Buffer { bitwise_bin_op_helper( - &left, + left, left_offset_in_bits, right, right_offset_in_bits, @@ -387,7 +387,7 @@ pub fn buffer_bin_or( } } -#[cfg(all(not(any(feature = "simd", feature = "avx512"))))] +#[cfg(not(any(feature = "simd", feature = "avx512")))] pub fn buffer_bin_or( left: &Buffer, left_offset_in_bits: usize, @@ -396,7 +396,7 @@ pub fn buffer_bin_or( len_in_bits: usize, ) -> Buffer { bitwise_bin_op_helper( - &left, + left, left_offset_in_bits, right, right_offset_in_bits, @@ -424,6 +424,6 @@ pub fn buffer_unary_not( // Default implementation #[allow(unreachable_code)] { - bitwise_unary_op_helper(&left, offset_in_bits, len_in_bits, |a| !a) + bitwise_unary_op_helper(left, offset_in_bits, len_in_bits, |a| !a) } } diff --git a/arrow/src/compute/kernels/aggregate.rs b/arrow/src/compute/kernels/aggregate.rs index 2dd19c4bbd59..a385c674cbe7 100644 --- a/arrow/src/compute/kernels/aggregate.rs +++ b/arrow/src/compute/kernels/aggregate.rs @@ -48,7 +48,7 @@ fn min_max_string bool>( n = array.value(0); for i in 1..data.len() { let item = array.value(i); - if cmp(&n, item) { + if cmp(n, item) { n = item; } } @@ -58,7 +58,7 @@ fn min_max_string bool>( for i in 0..data.len() { let item = array.value(i); - if data.is_valid(i) && (!has_value || cmp(&n, item)) { + if data.is_valid(i) && (!has_value || cmp(n, item)) { has_value = true; n = item; } diff --git a/arrow/src/compute/kernels/arithmetic.rs b/arrow/src/compute/kernels/arithmetic.rs index e93ea51a4d8e..f0fb0c10b5ba 100644 --- a/arrow/src/compute/kernels/arithmetic.rs +++ b/arrow/src/compute/kernels/arithmetic.rs @@ -1081,9 +1081,9 @@ where + One, { #[cfg(feature = "simd")] - return simd_modulus(&left, &right); + return simd_modulus(left, right); #[cfg(not(feature = "simd"))] - return math_modulus(&left, &right); + return math_modulus(left, right); } /// Perform `left / right` operation on two arrays. If either left or right value is null @@ -1104,9 +1104,9 @@ where + One, { #[cfg(feature = "simd")] - return simd_divide(&left, &right); + return simd_divide(left, right); #[cfg(not(feature = "simd"))] - return math_divide(&left, &right); + return math_divide(left, right); } /// Modulus every value in an array by a scalar. If any value in the array is null then the @@ -1127,9 +1127,9 @@ where + One, { #[cfg(feature = "simd")] - return simd_modulus_scalar(&array, modulo); + return simd_modulus_scalar(array, modulo); #[cfg(not(feature = "simd"))] - return math_modulus_scalar(&array, modulo); + return math_modulus_scalar(array, modulo); } /// Divide every value in an array by a scalar. If any value in the array is null then the @@ -1150,9 +1150,9 @@ where + One, { #[cfg(feature = "simd")] - return simd_divide_scalar(&array, divisor); + return simd_divide_scalar(array, divisor); #[cfg(not(feature = "simd"))] - return math_divide_scalar(&array, divisor); + return math_divide_scalar(array, divisor); } #[cfg(test)] diff --git a/arrow/src/compute/kernels/boolean.rs b/arrow/src/compute/kernels/boolean.rs index c9c0bc3545f6..b5a91fc47c25 100644 --- a/arrow/src/compute/kernels/boolean.rs +++ b/arrow/src/compute/kernels/boolean.rs @@ -191,14 +191,14 @@ where let left_data = left.data_ref(); let right_data = right.data_ref(); - let null_bit_buffer = combine_option_bitmap(&left_data, &right_data, len)?; + let null_bit_buffer = combine_option_bitmap(left_data, right_data, len)?; let left_buffer = &left_data.buffers()[0]; let right_buffer = &right_data.buffers()[0]; let left_offset = left.offset(); let right_offset = right.offset(); - let values = op(&left_buffer, left_offset, &right_buffer, right_offset, len); + let values = op(left_buffer, left_offset, right_buffer, right_offset, len); let data = ArrayData::new( DataType::Boolean, @@ -230,7 +230,7 @@ where /// # } /// ``` pub fn and(left: &BooleanArray, right: &BooleanArray) -> Result { - binary_boolean_kernel(&left, &right, buffer_bin_and) + binary_boolean_kernel(left, right, buffer_bin_and) } /// Logical 'and' boolean values with Kleene logic @@ -300,7 +300,7 @@ pub fn and_kleene(left: &BooleanArray, right: &BooleanArray) -> Result Result { - binary_boolean_kernel(&left, &right, buffer_bin_or) + binary_boolean_kernel(left, right, buffer_bin_or) } /// Logical 'or' boolean values with Kleene logic diff --git a/arrow/src/compute/kernels/cast.rs b/arrow/src/compute/kernels/cast.rs index 58a6ab7a8e15..2ef8d95079ad 100644 --- a/arrow/src/compute/kernels/cast.rs +++ b/arrow/src/compute/kernels/cast.rs @@ -1453,9 +1453,9 @@ pub fn cast_with_options( // temporal casts (Int32, Date32) => cast_array_data::(array, to_type.clone()), (Int32, Date64) => cast_with_options( - &cast_with_options(array, &DataType::Date32, &cast_options)?, + &cast_with_options(array, &DataType::Date32, cast_options)?, &DataType::Date64, - &cast_options, + cast_options, ), (Int32, Time32(TimeUnit::Second)) => { cast_array_data::(array, to_type.clone()) @@ -1468,14 +1468,14 @@ pub fn cast_with_options( (Date32, Int64) => cast_with_options( &cast_with_options(array, &DataType::Int32, cast_options)?, &DataType::Int64, - &cast_options, + cast_options, ), (Time32(_), Int32) => cast_array_data::(array, to_type.clone()), (Int64, Date64) => cast_array_data::(array, to_type.clone()), (Int64, Date32) => cast_with_options( - &cast_with_options(array, &DataType::Int32, &cast_options)?, + &cast_with_options(array, &DataType::Int32, cast_options)?, &DataType::Date32, - &cast_options, + cast_options, ), // No support for second/milliseconds with i64 (Int64, Time64(TimeUnit::Microsecond)) => { @@ -1487,9 +1487,9 @@ pub fn cast_with_options( (Date64, Int64) => cast_array_data::(array, to_type.clone()), (Date64, Int32) => cast_with_options( - &cast_with_options(array, &DataType::Int64, &cast_options)?, + &cast_with_options(array, &DataType::Int64, cast_options)?, &DataType::Int32, - &cast_options, + cast_options, ), (Time64(_), Int64) => cast_array_data::(array, to_type.clone()), (Date32, Date64) => { @@ -1535,8 +1535,8 @@ pub fn cast_with_options( let time_array = Int32Array::from(array.data().clone()); // note: (numeric_cast + SIMD multiply) is faster than (cast & multiply) let c: Int64Array = numeric_cast(&time_array); - let from_size = time_unit_multiple(&from_unit); - let to_size = time_unit_multiple(&to_unit); + let from_size = time_unit_multiple(from_unit); + let to_size = time_unit_multiple(to_unit); // from is only smaller than to if 64milli/64second don't exist let mult = Int64Array::from(vec![to_size / from_size; array.len()]); let converted = multiply(&c, &mult)?; @@ -1576,19 +1576,19 @@ pub fn cast_with_options( } (Time64(from_unit), Time32(to_unit)) => { let time_array = Int64Array::from(array.data().clone()); - let from_size = time_unit_multiple(&from_unit); - let to_size = time_unit_multiple(&to_unit); + let from_size = time_unit_multiple(from_unit); + let to_size = time_unit_multiple(to_unit); let divisor = from_size / to_size; match to_unit { TimeUnit::Second => { let values = unary::<_, _, Time32SecondType>(&time_array, |x| { - (x as i64 / divisor) as i32 + (x / divisor) as i32 }); Ok(Arc::new(values) as ArrayRef) } TimeUnit::Millisecond => { let values = unary::<_, _, Time32MillisecondType>(&time_array, |x| { - (x as i64 / divisor) as i32 + (x / divisor) as i32 }); Ok(Arc::new(values) as ArrayRef) } @@ -1613,8 +1613,8 @@ pub fn cast_with_options( } (Timestamp(from_unit, _), Timestamp(to_unit, _)) => { let time_array = Int64Array::from(array.data().clone()); - let from_size = time_unit_multiple(&from_unit); - let to_size = time_unit_multiple(&to_unit); + let from_size = time_unit_multiple(from_unit); + let to_size = time_unit_multiple(to_unit); // we either divide or multiply, depending on size of each unit // units are never the same when the types are the same let converted = if from_size >= to_size { @@ -1650,7 +1650,7 @@ pub fn cast_with_options( } (Timestamp(from_unit, _), Date32) => { let time_array = Int64Array::from(array.data().clone()); - let from_size = time_unit_multiple(&from_unit) * SECONDS_IN_DAY; + let from_size = time_unit_multiple(from_unit) * SECONDS_IN_DAY; let mut b = Date32Builder::new(array.len()); for i in 0..array.len() { if array.is_null(i) { @@ -1663,7 +1663,7 @@ pub fn cast_with_options( Ok(Arc::new(b.finish()) as ArrayRef) } (Timestamp(from_unit, _), Date64) => { - let from_size = time_unit_multiple(&from_unit); + let from_size = time_unit_multiple(from_unit); let to_size = MILLISECONDS; // Scale time_array by (to_size / from_size) using a @@ -2178,9 +2178,9 @@ fn dictionary_cast( let keys_array: ArrayRef = Arc::new(PrimitiveArray::::from(dict_array.keys().data().clone())); let values_array = dict_array.values(); - let cast_keys = cast_with_options(&keys_array, to_index_type, &cast_options)?; + let cast_keys = cast_with_options(&keys_array, to_index_type, cast_options)?; let cast_values = - cast_with_options(values_array, to_value_type, &cast_options)?; + cast_with_options(values_array, to_value_type, cast_options)?; // Failure to cast keys (because they don't fit in the // target type) results in NULL values; @@ -2252,8 +2252,7 @@ where // attempt to cast the dict values to the target type // use the take kernel to expand out the dictionary - let cast_dict_values = - cast_with_options(&dict_array.values(), to_type, cast_options)?; + let cast_dict_values = cast_with_options(dict_array.values(), to_type, cast_options)?; // Note take requires first casting the indices to u32 let keys_array: ArrayRef = @@ -2344,7 +2343,7 @@ where V: ArrowNumericType, { // attempt to cast the source array values to the target value type (the dictionary values type) - let cast_values = cast_with_options(array, &dict_value_type, cast_options)?; + let cast_values = cast_with_options(array, dict_value_type, cast_options)?; let values = cast_values .as_any() .downcast_ref::>() diff --git a/arrow/src/compute/kernels/cast_utils.rs b/arrow/src/compute/kernels/cast_utils.rs index 386dd3293ae7..9b874fcd0929 100644 --- a/arrow/src/compute/kernels/cast_utils.rs +++ b/arrow/src/compute/kernels/cast_utils.rs @@ -197,12 +197,11 @@ fn try_parse_prefix(s: &mut &str) -> Option { return None; } - let separator_is_space; - match rest[0] { - b' ' => separator_is_space = true, - b'T' => separator_is_space = false, + let separator_is_space = match rest[0] { + b' ' => true, + b'T' => false, _ => return None, - } + }; rest = &rest[1..]; let hour = try_parse_num(&mut rest)?; @@ -246,7 +245,7 @@ fn try_parse_num(s: &mut &[u8]) -> Option { .parse() .ok(); *s = &s[i..]; - return res; + res } #[must_use] diff --git a/arrow/src/compute/kernels/comparison.rs b/arrow/src/compute/kernels/comparison.rs index fa433608fa78..7653ef3726cb 100644 --- a/arrow/src/compute/kernels/comparison.rs +++ b/arrow/src/compute/kernels/comparison.rs @@ -43,10 +43,11 @@ macro_rules! compare_op { )); } + let op = $op; let null_bit_buffer = combine_option_bitmap($left.data_ref(), $right.data_ref(), $left.len())?; - let comparison = (0..$left.len()).map(|i| $op($left.value(i), $right.value(i))); + let comparison = (0..$left.len()).map(|i| op($left.value(i), $right.value(i))); // same size as $left.len() and $right.len() let buffer = unsafe { MutableBuffer::from_trusted_len_iter_bool(comparison) }; @@ -120,9 +121,10 @@ macro_rules! compare_op_primitive { macro_rules! compare_op_scalar { ($left: expr, $right:expr, $op:expr) => {{ + let op = $op; let null_bit_buffer = $left.data().null_buffer().cloned(); - let comparison = (0..$left.len()).map(|i| $op($left.value(i), $right)); + let comparison = (0..$left.len()).map(|i| op($left.value(i), $right)); // same as $left.len() let buffer = unsafe { MutableBuffer::from_trusted_len_iter_bool(comparison) }; diff --git a/arrow/src/compute/kernels/concat.rs b/arrow/src/compute/kernels/concat.rs index 5526432f8d8a..d64f76a2b9a7 100644 --- a/arrow/src/compute/kernels/concat.rs +++ b/arrow/src/compute/kernels/concat.rs @@ -295,10 +295,7 @@ mod tests { let array_result = concat(&[&list1_array, &list2_array, &list3_array])?; - let expected = list1 - .into_iter() - .chain(list2.into_iter()) - .chain(list3.into_iter()); + let expected = list1.into_iter().chain(list2).chain(list3); let array_expected = ListArray::from_iter_primitive::(expected); assert_eq!(array_result.as_ref(), &array_expected as &dyn Array); diff --git a/arrow/src/compute/kernels/filter.rs b/arrow/src/compute/kernels/filter.rs index 1bee44a76607..8754864f9630 100644 --- a/arrow/src/compute/kernels/filter.rs +++ b/arrow/src/compute/kernels/filter.rs @@ -293,7 +293,7 @@ pub fn filter_record_batch( let filtered_arrays = record_batch .columns() .iter() - .map(|a| make_array(filter(&a.data()))) + .map(|a| make_array(filter(a.data()))) .collect(); RecordBatch::try_new(record_batch.schema(), filtered_arrays) } diff --git a/arrow/src/compute/kernels/merge.rs b/arrow/src/compute/kernels/merge.rs index bd90f1759cc6..4817c3f831a7 100644 --- a/arrow/src/compute/kernels/merge.rs +++ b/arrow/src/compute/kernels/merge.rs @@ -457,7 +457,7 @@ impl<'a> ArrayComparator for StringComparator<'a> { } else { let left_value = left.value(left_row_index); let right_value = right.value(right_row_index); - left_value.cmp(&right_value) + left_value.cmp(right_value) } } diff --git a/arrow/src/compute/kernels/sort.rs b/arrow/src/compute/kernels/sort.rs index 6f4cdbebd563..79f8929d4df7 100644 --- a/arrow/src/compute/kernels/sort.rs +++ b/arrow/src/compute/kernels/sort.rs @@ -674,7 +674,7 @@ fn sort_string_dictionary( let keys: &PrimitiveArray = values.keys(); let dict = values.values(); - let dict: &StringArray = as_string_array(&dict); + let dict: &StringArray = as_string_array(dict); sort_string_helper( keys, @@ -704,7 +704,7 @@ where { let mut valids = value_indices .into_iter() - .map(|index| (index, value_fn(&values, index))) + .map(|index| (index, value_fn(values, index))) .collect::>(); let mut nulls = null_indices; let descending = options.descending; diff --git a/arrow/src/compute/kernels/take.rs b/arrow/src/compute/kernels/take.rs index 617036bfed88..2bb7b0a59692 100644 --- a/arrow/src/compute/kernels/take.rs +++ b/arrow/src/compute/kernels/take.rs @@ -522,8 +522,7 @@ where let null_count = values.null_count(); - let nulls; - if null_count == 0 && indices.null_count() == 0 { + let nulls = if null_count == 0 && indices.null_count() == 0 { (0..data_len).try_for_each::<_, Result<()>>(|i| { let index = ToPrimitive::to_usize(&indices.value(i)).ok_or_else(|| { ArrowError::ComputeError("Cast to usize failed".to_string()) @@ -536,7 +535,7 @@ where Ok(()) })?; - nulls = indices.data_ref().null_buffer().cloned(); + indices.data_ref().null_buffer().cloned() } else { let mut null_buf = MutableBuffer::new(num_byte).with_bitset(num_byte, true); let null_slice = null_buf.as_slice_mut(); @@ -558,7 +557,7 @@ where Ok(()) })?; - nulls = match indices.data_ref().null_buffer() { + match indices.data_ref().null_buffer() { Some(buffer) => Some(buffer_bin_and( buffer, indices.offset(), @@ -567,8 +566,8 @@ where indices.len(), )), None => Some(null_buf.into()), - }; - } + } + }; let data = ArrayData::new( DataType::Boolean, diff --git a/arrow/src/compute/kernels/temporal.rs b/arrow/src/compute/kernels/temporal.rs index 5db0dfb6a664..a93f7da5fb4b 100644 --- a/arrow/src/compute/kernels/temporal.rs +++ b/arrow/src/compute/kernels/temporal.rs @@ -81,7 +81,7 @@ where b.append_null()?; } else { match array.value_as_datetime(i) { - Some(dt) => b.append_value(dt.year() as i32)?, + Some(dt) => b.append_value(dt.year())?, None => b.append_null()?, } } diff --git a/arrow/src/compute/util.rs b/arrow/src/compute/util.rs index 56de59483016..6d4d0e40a9b4 100644 --- a/arrow/src/compute/util.rs +++ b/arrow/src/compute/util.rs @@ -48,9 +48,9 @@ pub(super) fn combine_option_bitmap( None => Ok(Some(l.bit_slice(left_offset_in_bits, len_in_bits))), Some(r) => Ok(Some(buffer_bin_and( - &l, + l, left_offset_in_bits, - &r, + r, right_offset_in_bits, len_in_bits, ))), @@ -82,9 +82,9 @@ pub(super) fn compare_option_bitmap( None => Ok(Some(l.bit_slice(left_offset_in_bits, len_in_bits))), Some(r) => Ok(Some(buffer_bin_or( - &l, + l, left_offset_in_bits, - &r, + r, right_offset_in_bits, len_in_bits, ))), diff --git a/arrow/src/csv/reader.rs b/arrow/src/csv/reader.rs index 753a3ca6533c..95c3501e1411 100644 --- a/arrow/src/csv/reader.rs +++ b/arrow/src/csv/reader.rs @@ -236,7 +236,7 @@ fn infer_reader_schema_with_csv_options( match possibilities.len() { 1 => { for dtype in possibilities.iter() { - fields.push(Field::new(&field_name, dtype.clone(), has_nulls)); + fields.push(Field::new(field_name, dtype.clone(), has_nulls)); } } 2 => { @@ -244,13 +244,13 @@ fn infer_reader_schema_with_csv_options( && possibilities.contains(&DataType::Float64) { // we have an integer and double, fall down to double - fields.push(Field::new(&field_name, DataType::Float64, has_nulls)); + fields.push(Field::new(field_name, DataType::Float64, has_nulls)); } else { // default to Utf8 for conflicting datatypes (e.g bool and int) - fields.push(Field::new(&field_name, DataType::Utf8, has_nulls)); + fields.push(Field::new(field_name, DataType::Utf8, has_nulls)); } } - _ => fields.push(Field::new(&field_name, DataType::Utf8, has_nulls)), + _ => fields.push(Field::new(field_name, DataType::Utf8, has_nulls)), } } @@ -480,7 +480,7 @@ impl Iterator for Reader { // parse the batches into a RecordBatch let result = parse( &self.batch_records[..read_records], - &self.schema.fields(), + self.schema.fields(), Some(self.schema.metadata.clone()), &self.projection, self.line_number, diff --git a/arrow/src/csv/writer.rs b/arrow/src/csv/writer.rs index 0b90d02d90de..540ebbb4bf2d 100644 --- a/arrow/src/csv/writer.rs +++ b/arrow/src/csv/writer.rs @@ -281,7 +281,7 @@ impl Writer { .iter() .map(|array| match array.data_type() { DataType::Dictionary(_, value_type) => { - crate::compute::kernels::cast::cast(array, &value_type) + crate::compute::kernels::cast::cast(array, value_type) .expect("cannot cast dictionary to underlying values") } _ => array.clone(), diff --git a/arrow/src/datatypes/field.rs b/arrow/src/datatypes/field.rs index a200a21380ec..bdc16698adc3 100644 --- a/arrow/src/datatypes/field.rs +++ b/arrow/src/datatypes/field.rs @@ -409,7 +409,7 @@ impl Field { continue; } is_new_field = false; - self_field.try_merge(&from_field)?; + self_field.try_merge(from_field)?; } if is_new_field { nested_fields.push(from_field.clone()); diff --git a/arrow/src/datatypes/mod.rs b/arrow/src/datatypes/mod.rs index 6eef22c1b237..b2bb9867b1b1 100644 --- a/arrow/src/datatypes/mod.rs +++ b/arrow/src/datatypes/mod.rs @@ -37,7 +37,6 @@ pub use types::*; mod datatype; pub use datatype::*; mod ffi; -pub use ffi::*; /// A reference-counted reference to a [`Schema`](crate::datatypes::Schema). pub type SchemaRef = Arc; diff --git a/arrow/src/datatypes/native.rs b/arrow/src/datatypes/native.rs index 50f1ba1de06f..4d0e2242128f 100644 --- a/arrow/src/datatypes/native.rs +++ b/arrow/src/datatypes/native.rs @@ -347,9 +347,7 @@ impl ToByteSlice for [T] { #[inline] fn to_byte_slice(&self) -> &[u8] { let raw_ptr = self.as_ptr() as *const T as *const u8; - unsafe { - std::slice::from_raw_parts(raw_ptr, self.len() * std::mem::size_of::()) - } + unsafe { std::slice::from_raw_parts(raw_ptr, std::mem::size_of_val(self)) } } } diff --git a/arrow/src/error.rs b/arrow/src/error.rs index 86896c016882..577fe368d119 100644 --- a/arrow/src/error.rs +++ b/arrow/src/error.rs @@ -64,8 +64,7 @@ impl From for ArrowError { match error.kind() { csv_crate::ErrorKind::Io(error) => ArrowError::CsvError(error.to_string()), csv_crate::ErrorKind::Utf8 { pos: _, err } => ArrowError::CsvError(format!( - "Encountered UTF-8 error while reading CSV file: {}", - err.to_string() + "Encountered UTF-8 error while reading CSV file: {err}", )), csv_crate::ErrorKind::UnequalLengths { expected_len, len, .. diff --git a/arrow/src/ipc/convert.rs b/arrow/src/ipc/convert.rs index a672f6388d6c..4d98ec3a0b96 100644 --- a/arrow/src/ipc/convert.rs +++ b/arrow/src/ipc/convert.rs @@ -503,7 +503,7 @@ pub(crate) fn get_fb_field_type<'a>( }, FixedSizeBinary(len) => { let mut builder = ipc::FixedSizeBinaryBuilder::new(fbb); - builder.add_byteWidth(*len as i32); + builder.add_byteWidth(*len); FBFieldType { type_type: ipc::Type::FixedSizeBinary, type_: builder.finish().as_union_value(), @@ -621,7 +621,7 @@ pub(crate) fn get_fb_field_type<'a>( FixedSizeList(ref list_type, len) => { let child = build_field(fbb, list_type); let mut builder = ipc::FixedSizeListBuilder::new(fbb); - builder.add_listSize(*len as i32); + builder.add_listSize(*len); FBFieldType { type_type: ipc::Type::FixedSizeList, type_: builder.finish().as_union_value(), diff --git a/arrow/src/ipc/reader.rs b/arrow/src/ipc/reader.rs index df825cb506b1..523fb6de47a4 100644 --- a/arrow/src/ipc/reader.rs +++ b/arrow/src/ipc/reader.rs @@ -421,7 +421,7 @@ pub fn read_record_batch( let triple = create_array( field_nodes, field.data_type(), - &buf, + buf, buffers, dictionaries, node_index, @@ -467,10 +467,10 @@ pub fn read_dictionary( }; // Read a single column let record_batch = read_record_batch( - &buf, + buf, batch.data().unwrap(), Arc::new(schema), - &dictionaries_by_field, + dictionaries_by_field, )?; Some(record_batch.column(0).clone()) } diff --git a/arrow/src/ipc/writer.rs b/arrow/src/ipc/writer.rs index 53dc6fea4f07..febc89fcc6f4 100644 --- a/arrow/src/ipc/writer.rs +++ b/arrow/src/ipc/writer.rs @@ -190,7 +190,7 @@ impl IpcDataGenerator { for array in batch.columns() { let array_data = array.data(); offset = write_array_data( - &array_data, + array_data, &mut buffers, &mut arrow_data, &mut nodes, @@ -243,7 +243,7 @@ impl IpcDataGenerator { let mut arrow_data: Vec = vec![]; write_array_data( - &array_data, + array_data, &mut buffers, &mut arrow_data, &mut nodes, @@ -666,9 +666,10 @@ impl MemStreamWriter { let writer = self.writer; - Ok(writer + let writer = writer .into_inner() - .map_err(|e| ArrowError::IoError(e.to_string()))?) + .map_err(|e| ArrowError::IoError(e.to_string()))?; + Ok(writer) } } @@ -705,7 +706,7 @@ pub fn write_message( write_continuation( &mut writer, - &write_options, + write_options, (aligned_size - prefix_size) as i32, )?; @@ -781,9 +782,9 @@ fn write_continuation( /// Write array data to a vector of bytes fn write_array_data( array_data: &ArrayData, - mut buffers: &mut Vec, - mut arrow_data: &mut Vec, - mut nodes: &mut Vec, + buffers: &mut Vec, + arrow_data: &mut Vec, + nodes: &mut Vec, offset: i64, num_rows: usize, null_count: usize, @@ -804,11 +805,11 @@ fn write_array_data( Some(buffer) => buffer.clone(), }; - offset = write_buffer(&null_buffer, &mut buffers, &mut arrow_data, offset); + offset = write_buffer(&null_buffer, buffers, arrow_data, offset); } array_data.buffers().iter().for_each(|buffer| { - offset = write_buffer(buffer, &mut buffers, &mut arrow_data, offset); + offset = write_buffer(buffer, buffers, arrow_data, offset); }); if !matches!(array_data.data_type(), DataType::Dictionary(_, _)) { @@ -817,9 +818,9 @@ fn write_array_data( // write the nested data (e.g list data) offset = write_array_data( data_ref, - &mut buffers, - &mut arrow_data, - &mut nodes, + buffers, + arrow_data, + nodes, offset, data_ref.len(), data_ref.null_count(), diff --git a/arrow/src/json/reader.rs b/arrow/src/json/reader.rs index 6d93d445db41..adb32055e20c 100644 --- a/arrow/src/json/reader.rs +++ b/arrow/src/json/reader.rs @@ -644,7 +644,7 @@ impl Decoder { } let rows = &rows[..]; - let projection = self.projection.clone().unwrap_or_else(Vec::new); + let projection = self.projection.clone().unwrap_or_default(); let arrays = self.build_struct_array(rows, self.schema.fields(), &projection); let projected_fields: Vec = if projection.is_empty() { @@ -652,8 +652,7 @@ impl Decoder { } else { projection .iter() - .map(|name| self.schema.column_with_name(name)) - .flatten() + .filter_map(|name| self.schema.column_with_name(name)) .map(|(_, field)| field.clone()) .collect() }; @@ -899,7 +898,7 @@ impl Decoder { fn build_boolean_array(&self, rows: &[Value], col_name: &str) -> Result { let mut builder = BooleanBuilder::new(rows.len()); for row in rows { - if let Some(value) = row.get(&col_name) { + if let Some(value) = row.get(col_name) { if let Some(boolean) = value.as_bool() { builder.append_value(boolean)? } else { @@ -925,7 +924,7 @@ impl Decoder { Ok(Arc::new( rows.iter() .map(|row| { - row.get(&col_name) + row.get(col_name) .and_then(|value| value.as_f64()) .and_then(num::cast::cast) }) @@ -1253,12 +1252,7 @@ impl Decoder { .iter() .enumerate() .map(|(i, row)| { - ( - i, - row.as_object() - .map(|v| v.get(field.name())) - .flatten(), - ) + (i, row.as_object().and_then(|v| v.get(field.name()))) }) .map(|(i, v)| match v { // we want the field as an object, if it's not, we treat as null @@ -1305,7 +1299,7 @@ impl Decoder { let mut builder: StringDictionaryBuilder = self.build_string_dictionary_builder(rows.len())?; for row in rows { - if let Some(value) = row.get(&col_name) { + if let Some(value) = row.get(col_name) { if let Some(str_v) = value.as_str() { builder.append(str_v).map(drop)? } else { diff --git a/arrow/src/json/writer.rs b/arrow/src/json/writer.rs index 51bef2b1038d..49cc29e50643 100644 --- a/arrow/src/json/writer.rs +++ b/arrow/src/json/writer.rs @@ -447,7 +447,7 @@ fn set_column_for_json_rows( struct_array_to_jsonmap_array(as_struct_array(array), row_count); rows.iter_mut() .take(row_count) - .zip(inner_objs.into_iter()) + .zip(inner_objs) .for_each(|(row, obj)| { row.insert(col_name.to_string(), Value::Object(obj)); }); @@ -482,7 +482,7 @@ fn set_column_for_json_rows( } DataType::Dictionary(_, value_type) => { let slice = array.slice(0, row_count); - let hydrated = crate::compute::kernels::cast::cast(&slice, &value_type) + let hydrated = crate::compute::kernels::cast::cast(&slice, value_type) .expect("cannot cast dictionary to underlying values"); set_column_for_json_rows(rows, row_count, &hydrated, col_name) } diff --git a/arrow/src/tensor.rs b/arrow/src/tensor.rs index 3a8133888ffd..b8d07f83fb90 100644 --- a/arrow/src/tensor.rs +++ b/arrow/src/tensor.rs @@ -196,7 +196,7 @@ impl<'a, T: ArrowPrimitiveType> Tensor<'a, T> { names: Option>, ) -> Result { if let Some(ref s) = shape { - let strides = Some(compute_row_major_strides::(&s)?); + let strides = Some(compute_row_major_strides::(s)?); Self::try_new(buffer, shape, strides, names) } else { @@ -213,7 +213,7 @@ impl<'a, T: ArrowPrimitiveType> Tensor<'a, T> { names: Option>, ) -> Result { if let Some(ref s) = shape { - let strides = Some(compute_column_major_strides::(&s)?); + let strides = Some(compute_column_major_strides::(s)?); Self::try_new(buffer, shape, strides, names) } else { @@ -258,7 +258,7 @@ impl<'a, T: ArrowPrimitiveType> Tensor<'a, T> { /// The name of dimension i pub fn dim_name(&self, i: usize) -> Option<&'a str> { - self.names.as_ref().map(|ref names| names[i]) + self.names.as_ref().map(|names| names[i]) } /// The total number of elements in the `Tensor` diff --git a/arrow/src/util/bit_util.rs b/arrow/src/util/bit_util.rs index f643d593fabd..ace63275b1b3 100644 --- a/arrow/src/util/bit_util.rs +++ b/arrow/src/util/bit_util.rs @@ -281,7 +281,7 @@ mod tests { } #[test] - #[cfg(all(any(target_arch = "x86", target_arch = "x86_64")))] + #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] fn test_ceil() { assert_eq!(ceil(0, 1), 0); assert_eq!(ceil(1, 1), 1); diff --git a/arrow/src/util/data_gen.rs b/arrow/src/util/data_gen.rs index 08624ae86ee8..4c7acd3595c3 100644 --- a/arrow/src/util/data_gen.rs +++ b/arrow/src/util/data_gen.rs @@ -185,7 +185,7 @@ fn create_random_list_array( // Create list's child data let child_array = - create_random_array(list_field, child_len as usize, null_density, true_density)?; + create_random_array(list_field, child_len, null_density, true_density)?; let child_data = child_array.data(); // Create list's null buffers, if it is nullable let null_buffer = match field.is_nullable() { diff --git a/arrow/src/util/display.rs b/arrow/src/util/display.rs index 72402641c58d..1849633cd379 100644 --- a/arrow/src/util/display.rs +++ b/arrow/src/util/display.rs @@ -312,5 +312,5 @@ fn dict_array_value_to_string( )) })?; - array_value_to_string(&dict_array.values(), dict_index) + array_value_to_string(dict_array.values(), dict_index) } diff --git a/arrow/src/util/integration_util.rs b/arrow/src/util/integration_util.rs index 161798014d6c..7321f73e2147 100644 --- a/arrow/src/util/integration_util.rs +++ b/arrow/src/util/integration_util.rs @@ -217,7 +217,7 @@ impl ArrowJsonBatch { if &col.name != field.name() { return false; } - let json_array: Vec = json_from_col(&col, field.data_type()); + let json_array: Vec = json_from_col(col, field.data_type()); match field.data_type() { DataType::Null => { let arr: &NullArray = diff --git a/arrow/src/util/test_util.rs b/arrow/src/util/test_util.rs index 4b193f774178..9323a3b9d190 100644 --- a/arrow/src/util/test_util.rs +++ b/arrow/src/util/test_util.rs @@ -124,7 +124,7 @@ fn get_data_dir(udf_env: &str, submodule_data: &str) -> Result Result Result { let (dictionary_flight_data, mut batch_flight_data) = - arrow_flight::utils::flight_data_from_arrow_batch(batch, &options); + arrow_flight::utils::flight_data_from_arrow_batch(batch, options); upload_tx .send_all(&mut stream::iter(dictionary_flight_data).map(Ok)) @@ -166,7 +166,7 @@ async fn verify_data( consume_flight_location( location, ticket.clone(), - &expected_data, + expected_data, expected_schema.clone(), ) .await?; diff --git a/integration-testing/src/flight_server_scenarios/integration_test.rs b/integration-testing/src/flight_server_scenarios/integration_test.rs index 9f8424cc5349..ae370b6f8366 100644 --- a/integration-testing/src/flight_server_scenarios/integration_test.rs +++ b/integration-testing/src/flight_server_scenarios/integration_test.rs @@ -294,7 +294,7 @@ async fn record_batch_from_message( data_body, ipc_batch, schema_ref, - &dictionaries_by_field, + dictionaries_by_field, ); arrow_batch_result.map_err(|e| { diff --git a/integration-testing/src/lib.rs b/integration-testing/src/lib.rs index 22eed0395c5b..6db3fce91e0d 100644 --- a/integration-testing/src/lib.rs +++ b/integration-testing/src/lib.rs @@ -405,7 +405,7 @@ fn array_from_json( let null_buf = create_null_buf(&json_col); let children = json_col.children.clone().unwrap(); let child_array = array_from_json( - &child_field, + child_field, children.get(0).unwrap().clone(), dictionaries, )?; @@ -428,7 +428,7 @@ fn array_from_json( let null_buf = create_null_buf(&json_col); let children = json_col.children.clone().unwrap(); let child_array = array_from_json( - &child_field, + child_field, children.get(0).unwrap().clone(), dictionaries, )?; @@ -454,7 +454,7 @@ fn array_from_json( DataType::FixedSizeList(child_field, _) => { let children = json_col.children.clone().unwrap(); let child_array = array_from_json( - &child_field, + child_field, children.get(0).unwrap().clone(), dictionaries, )?; diff --git a/parquet/benches/arrow_writer.rs b/parquet/benches/arrow_writer.rs index 069ed39d1039..34ea2d2d8e1a 100644 --- a/parquet/benches/arrow_writer.rs +++ b/parquet/benches/arrow_writer.rs @@ -142,7 +142,7 @@ fn write_batch(batch: &RecordBatch) -> Result<()> { let cursor = InMemoryWriteableCursor::default(); let mut writer = ArrowWriter::try_new(cursor, batch.schema(), None)?; - writer.write(&batch)?; + writer.write(batch)?; writer.close()?; Ok(()) } diff --git a/parquet/src/arrow/arrow_array_reader.rs b/parquet/src/arrow/arrow_array_reader.rs index dd98583f8ba4..b6cbf43f6301 100644 --- a/parquet/src/arrow/arrow_array_reader.rs +++ b/parquet/src/arrow/arrow_array_reader.rs @@ -314,7 +314,7 @@ impl<'a, C: ArrayConverter + 'a> ArrowArrayReader<'a, C> { let mut buffer_ptr = buf; // create rep level decoder iterator let rep_level_iter: Box = - if Self::rep_levels_available(&column_desc) { + if Self::rep_levels_available(column_desc) { let mut rep_decoder = LevelDecoder::v1( rep_level_encoding, column_desc.max_rep_level(), @@ -331,7 +331,7 @@ impl<'a, C: ArrayConverter + 'a> ArrowArrayReader<'a, C> { }; // create def level decoder iterator let def_level_iter: Box = - if Self::def_levels_available(&column_desc) { + if Self::def_levels_available(column_desc) { let mut def_decoder = LevelDecoder::v1( def_level_encoding, column_desc.max_def_level(), @@ -370,7 +370,7 @@ impl<'a, C: ArrayConverter + 'a> ArrowArrayReader<'a, C> { let mut offset = 0; // create rep level decoder iterator let rep_level_iter: Box = - if Self::rep_levels_available(&column_desc) { + if Self::rep_levels_available(column_desc) { let rep_levels_byte_len = rep_levels_byte_len as usize; let mut rep_decoder = LevelDecoder::v2(column_desc.max_rep_level()); @@ -389,7 +389,7 @@ impl<'a, C: ArrayConverter + 'a> ArrowArrayReader<'a, C> { }; // create def level decoder iterator let def_level_iter: Box = - if Self::def_levels_available(&column_desc) { + if Self::def_levels_available(column_desc) { let def_levels_byte_len = def_levels_byte_len as usize; let mut def_decoder = LevelDecoder::v2(column_desc.max_def_level()); diff --git a/parquet/src/arrow/arrow_writer.rs b/parquet/src/arrow/arrow_writer.rs index 603c58f7c416..cccb01ecfefc 100644 --- a/parquet/src/arrow/arrow_writer.rs +++ b/parquet/src/arrow/arrow_writer.rs @@ -144,9 +144,9 @@ fn get_col_writer( #[allow(clippy::borrowed_box)] fn write_leaves( - mut row_group_writer: &mut Box, + row_group_writer: &mut Box, array: &arrow_array::ArrayRef, - mut levels: &mut Vec, + levels: &mut Vec, ) -> Result<()> { match array.data_type() { ArrowDataType::Null @@ -177,7 +177,7 @@ fn write_leaves( | ArrowDataType::LargeUtf8 | ArrowDataType::Decimal(_, _) | ArrowDataType::FixedSizeBinary(_) => { - let mut col_writer = get_col_writer(&mut row_group_writer)?; + let mut col_writer = get_col_writer(row_group_writer)?; write_leaf( &mut col_writer, array, @@ -190,7 +190,7 @@ fn write_leaves( // write the child list let data = array.data(); let child_array = arrow_array::make_array(data.child_data()[0].clone()); - write_leaves(&mut row_group_writer, &child_array, &mut levels)?; + write_leaves(row_group_writer, &child_array, levels)?; Ok(()) } ArrowDataType::Struct(_) => { @@ -199,7 +199,7 @@ fn write_leaves( .downcast_ref::() .expect("Unable to get struct array"); for field in struct_array.columns() { - write_leaves(&mut row_group_writer, field, &mut levels)?; + write_leaves(row_group_writer, field, levels)?; } Ok(()) } @@ -207,7 +207,7 @@ fn write_leaves( // cast dictionary to a primitive let array = arrow::compute::cast(array, value_type)?; - let mut col_writer = get_col_writer(&mut row_group_writer)?; + let mut col_writer = get_col_writer(row_group_writer)?; write_leaf( &mut col_writer, &array, @@ -254,7 +254,7 @@ fn write_leaf( .as_any() .downcast_ref::() .expect("Unable to get int32 array"); - get_numeric_array_slice::(&array, &indices) + get_numeric_array_slice::(array, &indices) } ArrowDataType::UInt32 => { // follow C++ implementation and use overflow/reinterpret cast from u32 to i32 which will map @@ -275,7 +275,7 @@ fn write_leaf( .as_any() .downcast_ref::() .expect("Unable to get i32 array"); - get_numeric_array_slice::(&array, &indices) + get_numeric_array_slice::(array, &indices) } }; typed.write_batch( @@ -290,7 +290,7 @@ fn write_leaf( .downcast_ref::() .expect("Unable to get boolean array"); typed.write_batch( - get_bool_array_slice(&array, &indices).as_slice(), + get_bool_array_slice(array, &indices).as_slice(), Some(levels.definition.as_slice()), levels.repetition.as_deref(), )? @@ -302,7 +302,7 @@ fn write_leaf( .as_any() .downcast_ref::() .expect("Unable to get i64 array"); - get_numeric_array_slice::(&array, &indices) + get_numeric_array_slice::(array, &indices) } ArrowDataType::Int64Decimal(_) => { // If we call `cast` we loose the fractional part of decimal. @@ -328,7 +328,7 @@ fn write_leaf( .as_any() .downcast_ref::() .expect("Unable to get i64 array"); - get_numeric_array_slice::(&array, &indices) + get_numeric_array_slice::(array, &indices) } }; typed.write_batch( @@ -344,7 +344,7 @@ fn write_leaf( .as_any() .downcast_ref::() .expect("Unable to get i128 array"); - get_numeric_array_slice::(&array, &indices) + get_numeric_array_slice::(array, &indices) } ArrowDataType::Int96Decimal(_) => { let array = Int96Array::from(column.data().clone()); @@ -366,7 +366,7 @@ fn write_leaf( .downcast_ref::() .expect("Unable to get Float32 array"); typed.write_batch( - get_numeric_array_slice::(&array, &indices).as_slice(), + get_numeric_array_slice::(array, &indices).as_slice(), Some(levels.definition.as_slice()), levels.repetition.as_deref(), )? @@ -377,7 +377,7 @@ fn write_leaf( .downcast_ref::() .expect("Unable to get Float64 array"); typed.write_batch( - get_numeric_array_slice::(&array, &indices).as_slice(), + get_numeric_array_slice::(array, &indices).as_slice(), Some(levels.definition.as_slice()), levels.repetition.as_deref(), )? @@ -389,7 +389,7 @@ fn write_leaf( .downcast_ref::() .expect("Unable to get BinaryArray array"); typed.write_batch( - get_binary_array(&array).as_slice(), + get_binary_array(array).as_slice(), Some(levels.definition.as_slice()), levels.repetition.as_deref(), )? @@ -400,7 +400,7 @@ fn write_leaf( .downcast_ref::() .expect("Unable to get LargeBinaryArray array"); typed.write_batch( - get_string_array(&array).as_slice(), + get_string_array(array).as_slice(), Some(levels.definition.as_slice()), levels.repetition.as_deref(), )? @@ -411,7 +411,7 @@ fn write_leaf( .downcast_ref::() .expect("Unable to get LargeBinaryArray array"); typed.write_batch( - get_large_binary_array(&array).as_slice(), + get_large_binary_array(array).as_slice(), Some(levels.definition.as_slice()), levels.repetition.as_deref(), )? @@ -422,7 +422,7 @@ fn write_leaf( .downcast_ref::() .expect("Unable to get LargeUtf8 array"); typed.write_batch( - get_large_string_array(&array).as_slice(), + get_large_string_array(array).as_slice(), Some(levels.definition.as_slice()), levels.repetition.as_deref(), )? @@ -437,14 +437,14 @@ fn write_leaf( .as_any() .downcast_ref::() .unwrap(); - get_interval_ym_array_slice(&array, &indices) + get_interval_ym_array_slice(array, &indices) } IntervalUnit::DayTime => { let array = column .as_any() .downcast_ref::() .unwrap(); - get_interval_dt_array_slice(&array, &indices) + get_interval_dt_array_slice(array, &indices) } }, ArrowDataType::FixedSizeBinary(_) => { @@ -452,14 +452,14 @@ fn write_leaf( .as_any() .downcast_ref::() .unwrap(); - get_fsb_array_slice(&array, &indices) + get_fsb_array_slice(array, &indices) } ArrowDataType::Decimal(_, _) => { let array = column .as_any() .downcast_ref::() .unwrap(); - get_decimal_array_slice(&array, &indices) + get_decimal_array_slice(array, &indices) } _ => { return Err(ParquetError::NYI( diff --git a/parquet/src/arrow/schema.rs b/parquet/src/arrow/schema.rs index 2033bff90336..be2e15e069ef 100644 --- a/parquet/src/arrow/schema.rs +++ b/parquet/src/arrow/schema.rs @@ -216,7 +216,7 @@ fn get_arrow_schema_from_metadata(encoded_meta: &str) -> Result { fn encode_arrow_schema(schema: &Schema) -> String { let options = writer::IpcWriteOptions::default(); let data_gen = arrow::ipc::writer::IpcDataGenerator::default(); - let mut serialized_schema = data_gen.schema_to_bytes(&schema, &options); + let mut serialized_schema = data_gen.schema_to_bytes(schema, &options); // manually prepending the length to the schema as arrow uses the legacy IPC format // TODO: change after addressing ARROW-9777 diff --git a/parquet/src/column/page.rs b/parquet/src/column/page.rs index b75d3b5028bb..acbf3eba410e 100644 --- a/parquet/src/column/page.rs +++ b/parquet/src/column/page.rs @@ -70,9 +70,9 @@ impl Page { /// Returns internal byte buffer reference for this page. pub fn buffer(&self) -> &ByteBufferPtr { match self { - Page::DataPage { ref buf, .. } => &buf, - Page::DataPageV2 { ref buf, .. } => &buf, - Page::DictionaryPage { ref buf, .. } => &buf, + Page::DataPage { ref buf, .. } => buf, + Page::DataPageV2 { ref buf, .. } => buf, + Page::DictionaryPage { ref buf, .. } => buf, } } diff --git a/parquet/src/column/writer.rs b/parquet/src/column/writer.rs index 910a9ed5dcaf..d5b845756da2 100644 --- a/parquet/src/column/writer.rs +++ b/parquet/src/column/writer.rs @@ -807,7 +807,7 @@ impl ColumnWriterImpl { ) -> Result> { let size = max_buffer_size(encoding, max_level, levels.len()); let mut encoder = LevelEncoder::v1(encoding, max_level, vec![0; size]); - encoder.put(&levels)?; + encoder.put(levels)?; encoder.consume() } @@ -817,7 +817,7 @@ impl ColumnWriterImpl { fn encode_levels_v2(&self, levels: &[i16], max_level: i16) -> Result> { let size = max_buffer_size(Encoding::RLE, max_level, levels.len()); let mut encoder = LevelEncoder::v2(max_level, vec![0; size]); - encoder.put(&levels)?; + encoder.put(levels)?; encoder.consume() } diff --git a/parquet/src/encodings/encoding.rs b/parquet/src/encodings/encoding.rs index 944c2576adaa..1db4160c18ff 100644 --- a/parquet/src/encodings/encoding.rs +++ b/parquet/src/encodings/encoding.rs @@ -359,7 +359,7 @@ impl Encoder for DictEncoder { #[inline] fn put(&mut self, values: &[T::T]) -> Result<()> { for i in values { - self.put_one(&i)? + self.put_one(i)? } Ok(()) } diff --git a/parquet/src/file/serialized_reader.rs b/parquet/src/file/serialized_reader.rs index d0158852d938..b0eddf3899d3 100644 --- a/parquet/src/file/serialized_reader.rs +++ b/parquet/src/file/serialized_reader.rs @@ -208,7 +208,7 @@ impl<'a, R: ChunkReader> SerializedRowGroupReader<'a, R> { impl<'a, R: 'static + ChunkReader> RowGroupReader for SerializedRowGroupReader<'a, R> { fn metadata(&self) -> &RowGroupMetaData { - &self.metadata + self.metadata } fn num_columns(&self) -> usize { diff --git a/parquet/src/record/reader.rs b/parquet/src/record/reader.rs index 691afe8c2034..9632e562a5cd 100644 --- a/parquet/src/record/reader.rs +++ b/parquet/src/record/reader.rs @@ -106,7 +106,7 @@ impl TreeBuilder { fn reader_tree( &self, field: TypePtr, - mut path: &mut Vec, + path: &mut Vec, mut curr_def_level: i16, mut curr_rep_level: i16, paths: &HashMap, @@ -160,7 +160,7 @@ impl TreeBuilder { // Support for backward compatible lists let reader = self.reader_tree( repeated_field, - &mut path, + path, curr_def_level, curr_rep_level, paths, @@ -180,7 +180,7 @@ impl TreeBuilder { let reader = self.reader_tree( child_field, - &mut path, + path, curr_def_level + 1, curr_rep_level + 1, paths, @@ -235,7 +235,7 @@ impl TreeBuilder { ); let key_reader = self.reader_tree( key_type.clone(), - &mut path, + path, curr_def_level + 1, curr_rep_level + 1, paths, @@ -245,7 +245,7 @@ impl TreeBuilder { let value_type = &key_value_type.get_fields()[1]; let value_reader = self.reader_tree( value_type.clone(), - &mut path, + path, curr_def_level + 1, curr_rep_level + 1, paths, @@ -278,7 +278,7 @@ impl TreeBuilder { let reader = self.reader_tree( Arc::new(required_field), - &mut path, + path, curr_def_level, curr_rep_level, paths, @@ -298,7 +298,7 @@ impl TreeBuilder { for child in field.get_fields() { let reader = self.reader_tree( child.clone(), - &mut path, + path, curr_def_level, curr_rep_level, paths, diff --git a/parquet/src/schema/printer.rs b/parquet/src/schema/printer.rs index b1e739f77b4b..9f7a28b7ce10 100644 --- a/parquet/src/schema/printer.rs +++ b/parquet/src/schema/printer.rs @@ -55,7 +55,7 @@ use crate::schema::types::Type; /// information. #[allow(unused_must_use)] pub fn print_parquet_metadata(out: &mut dyn io::Write, metadata: &ParquetMetaData) { - print_file_metadata(out, &metadata.file_metadata()); + print_file_metadata(out, metadata.file_metadata()); writeln!(out); writeln!(out); writeln!(out, "num of row groups: {}", metadata.num_row_groups()); @@ -135,7 +135,7 @@ fn print_column_chunk_metadata( writeln!(out, "encodings: {}", encoding_strs.join(" ")); let file_path_str = match cc_metadata.file_path() { None => "N/A", - Some(ref fp) => *fp, + Some(fp) => fp, }; writeln!(out, "file path: {}", file_path_str); writeln!(out, "file offset: {}", cc_metadata.file_offset()); @@ -340,7 +340,7 @@ impl<'a> Printer<'a> { self.indent += INDENT_WIDTH; for c in fields { - self.print(&c); + self.print(c); writeln!(self.output); } self.indent -= INDENT_WIDTH; diff --git a/parquet/src/schema/types.rs b/parquet/src/schema/types.rs index 4747360440c2..1773cebcb017 100644 --- a/parquet/src/schema/types.rs +++ b/parquet/src/schema/types.rs @@ -72,8 +72,8 @@ impl Type { /// Returns [`BasicTypeInfo`] information about the type. pub fn get_basic_info(&self) -> &BasicTypeInfo { match *self { - Type::PrimitiveType { ref basic_info, .. } => &basic_info, - Type::GroupType { ref basic_info, .. } => &basic_info, + Type::PrimitiveType { ref basic_info, .. } => basic_info, + Type::GroupType { ref basic_info, .. } => basic_info, } } diff --git a/parquet/src/util/bit_util.rs b/parquet/src/util/bit_util.rs index 0b1b0ff5b251..dac807737294 100644 --- a/parquet/src/util/bit_util.rs +++ b/parquet/src/util/bit_util.rs @@ -382,8 +382,8 @@ impl BitWriter { // TODO: should we return `Result` for this func? return false; } - let mut ptr = result.unwrap(); - memcpy_value(&val, num_bytes, &mut ptr); + let ptr = result.unwrap(); + memcpy_value(&val, num_bytes, ptr); true }