From cc720cbec582816ebdde93f1f202abc01b46737c 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/list.rs | 4 +- arrow/src/array/equal/mod.rs | 59 +++++++++---------- arrow/src/array/equal/utils.rs | 16 ++--- 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 | 8 +-- arrow/src/compute/kernels/sort.rs | 10 +--- arrow/src/compute/kernels/take.rs | 21 ++----- arrow/src/compute/kernels/temporal.rs | 2 +- arrow/src/compute/kernels/zip.rs | 2 +- arrow/src/compute/util.rs | 8 +-- arrow/src/csv/reader.rs | 12 ++-- arrow/src/csv/writer.rs | 2 +- arrow/src/datatypes/datatype.rs | 10 ++-- arrow/src/datatypes/field.rs | 10 ++-- arrow/src/datatypes/mod.rs | 1 - arrow/src/datatypes/native.rs | 6 +- arrow/src/datatypes/schema.rs | 5 +- arrow/src/error.rs | 3 +- arrow/src/ffi.rs | 28 ++++----- arrow/src/ipc/convert.rs | 8 +-- 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 | 10 ++-- 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 +- .../auth_basic_proto.rs | 4 +- .../integration_test.rs | 2 +- integration-testing/src/lib.rs | 12 ++-- parquet/benches/arrow_writer.rs | 2 +- parquet/src/arrow/array_reader.rs | 2 +- parquet/src/arrow/arrow_array_reader.rs | 10 ++-- parquet/src/arrow/arrow_writer.rs | 44 +++++++------- parquet/src/arrow/levels.rs | 2 +- parquet/src/arrow/schema.rs | 2 +- parquet/src/column/page.rs | 6 +- parquet/src/column/reader.rs | 2 +- parquet/src/column/writer.rs | 4 +- parquet/src/data_type.rs | 16 +---- parquet/src/encodings/decoding.rs | 2 +- parquet/src/encodings/encoding.rs | 8 +-- parquet/src/file/serialized_reader.rs | 2 +- parquet/src/file/writer.rs | 8 +-- parquet/src/record/api.rs | 4 +- parquet/src/record/reader.rs | 14 ++--- parquet/src/schema/printer.rs | 10 ++-- parquet/src/schema/types.rs | 6 +- parquet/src/util/bit_util.rs | 7 +-- parquet/src/util/cursor.rs | 4 +- parquet/src/util/io.rs | 2 +- parquet/tests/boolean_writer.rs | 6 +- parquet_derive/src/parquet_field.rs | 15 ++--- 82 files changed, 328 insertions(+), 382 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/list.rs b/arrow/src/array/equal/list.rs index 331cdc7c614b..55f55d94bca5 100644 --- a/arrow/src/array/equal/list.rs +++ b/arrow/src/array/equal/list.rs @@ -123,9 +123,9 @@ pub(super) fn list_equal( // compute the child logical bitmap let child_lhs_nulls = - child_logical_null_buffer(lhs, lhs_nulls, lhs.child_data().get(0).unwrap()); + child_logical_null_buffer(lhs, lhs_nulls, lhs.child_data().first().unwrap()); let child_rhs_nulls = - child_logical_null_buffer(rhs, rhs_nulls, rhs.child_data().get(0).unwrap()); + child_logical_null_buffer(rhs, rhs_nulls, rhs.child_data().first().unwrap()); if lhs_null_count == 0 && rhs_null_count == 0 { lengths_equal( 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..01eed2e51d9c 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); } }); }); @@ -233,7 +233,7 @@ mod tests { let nulls = child_logical_null_buffer( &data, data.null_buffer(), - data.child_data().get(0).unwrap(), + data.child_data().first().unwrap(), ); let expected = Some(Buffer::from(vec![0b11100111, 0b00000101])); assert_eq!(nulls, expected); @@ -255,7 +255,7 @@ mod tests { let nulls = child_logical_null_buffer( &data, data.null_buffer(), - data.child_data().get(0).unwrap(), + data.child_data().first().unwrap(), ); let expected = Some(Buffer::from(vec![0b00101111])); 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..4d4e01c9d4c3 100644 --- a/arrow/src/compute/kernels/merge.rs +++ b/arrow/src/compute/kernels/merge.rs @@ -372,7 +372,7 @@ impl<'a> MergeRowCursor<'a> { impl<'a> PartialOrd for MergeRowCursor<'a> { fn partial_cmp(&self, other: &Self) -> Option { - Some(self.compare(other)) + Some(std::cmp::Ord::cmp(self, other)) } } @@ -385,7 +385,7 @@ impl<'a> PartialEq for MergeRowCursor<'a> { impl<'a> Eq for MergeRowCursor<'a> {} impl<'a> Ord for MergeRowCursor<'a> { fn cmp(&self, other: &Self) -> Ordering { - self.partial_cmp(other).unwrap() + self.compare(other) } } @@ -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) } } @@ -556,7 +556,7 @@ where pub fn new(arrays: &[&'a ArrayRef]) -> Self { Self { arrays: arrays - .into_iter() + .iter() .map(|array| array.as_any().downcast_ref::>().unwrap()) .collect(), } diff --git a/arrow/src/compute/kernels/sort.rs b/arrow/src/compute/kernels/sort.rs index 6f4cdbebd563..5c94034db0c8 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; @@ -945,11 +945,7 @@ pub(super) struct LexicographicalComparator<'a> { impl LexicographicalComparator<'_> { /// lexicographically compare values at the wrapped columns with given indices. - pub(super) fn compare<'a, 'b>( - &'a self, - a_idx: &'b usize, - b_idx: &'b usize, - ) -> Ordering { + pub(super) fn compare<'b>(&self, a_idx: &'b usize, b_idx: &'b usize) -> Ordering { for (data, comparator, sort_option) in &self.compare_items { match (data.is_valid(*a_idx), data.is_valid(*b_idx)) { (true, true) => { diff --git a/arrow/src/compute/kernels/take.rs b/arrow/src/compute/kernels/take.rs index 617036bfed88..8dc545ff8b78 100644 --- a/arrow/src/compute/kernels/take.rs +++ b/arrow/src/compute/kernels/take.rs @@ -287,7 +287,7 @@ where } /// Options that define how `take` should behave -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct TakeOptions { /// Perform bounds check before taking indices from values. /// If enabled, an `ArrowError` is returned if the indices are out of bounds. @@ -295,14 +295,6 @@ pub struct TakeOptions { pub check_bounds: bool, } -impl Default for TakeOptions { - fn default() -> Self { - Self { - check_bounds: false, - } - } -} - #[inline(always)] fn maybe_usize(index: I::Native) -> Result { index @@ -522,8 +514,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 +527,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 +549,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 +558,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/kernels/zip.rs b/arrow/src/compute/kernels/zip.rs index 0ee8e47bede0..c28529cf6762 100644 --- a/arrow/src/compute/kernels/zip.rs +++ b/arrow/src/compute/kernels/zip.rs @@ -44,7 +44,7 @@ pub fn zip( let falsy = falsy.data(); let truthy = truthy.data(); - let mut mutable = MutableArrayData::new(vec![&*truthy, &*falsy], false, truthy.len()); + let mut mutable = MutableArrayData::new(vec![truthy, falsy], false, truthy.len()); // the SlicesIterator slices only the true values. So the gaps left by this iterator we need to // fill with falsy values 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..bb6e4e07041a 100644 --- a/arrow/src/csv/reader.rs +++ b/arrow/src/csv/reader.rs @@ -126,7 +126,7 @@ fn infer_file_schema_with_csv_options( quote: Option, terminator: Option, ) -> Result<(Schema, usize)> { - let saved_offset = reader.seek(SeekFrom::Current(0))?; + let saved_offset = reader.stream_position()?; let (schema, records_count) = infer_reader_schema_with_csv_options( reader, @@ -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/datatype.rs b/arrow/src/datatypes/datatype.rs index b01ffd5e5e64..692de5cddab4 100644 --- a/arrow/src/datatypes/datatype.rs +++ b/arrow/src/datatypes/datatype.rs @@ -285,9 +285,9 @@ impl DataType { }, Some(s) if s == "decimalint" => match map.get("isSigned") { Some(&Value::Bool(true)) => match map.get("bitWidth") { - Some(&Value::Number(ref n)) => match n.as_u64() { + Some(Value::Number(n)) => match n.as_u64() { Some(64) => match map.get("scale") { - Some(&Value::Number(ref scale)) => match scale.as_u64() { + Some(Value::Number(scale)) => match scale.as_u64() { Some(scale) => { Ok(DataType::Int64Decimal(scale as usize)) } @@ -300,7 +300,7 @@ impl DataType { )), }, Some(96) => match map.get("scale") { - Some(&Value::Number(ref scale)) => match scale.as_u64() { + Some(Value::Number(scale)) => match scale.as_u64() { Some(scale) => { Ok(DataType::Int96Decimal(scale as usize)) } @@ -326,7 +326,7 @@ impl DataType { }, Some(s) if s == "int" => match map.get("isSigned") { Some(&Value::Bool(true)) => match map.get("bitWidth") { - Some(&Value::Number(ref n)) => match n.as_u64() { + Some(Value::Number(n)) => match n.as_u64() { Some(8) => Ok(DataType::Int8), Some(16) => Ok(DataType::Int16), Some(32) => Ok(DataType::Int32), @@ -341,7 +341,7 @@ impl DataType { )), }, Some(&Value::Bool(false)) => match map.get("bitWidth") { - Some(&Value::Number(ref n)) => match n.as_u64() { + Some(Value::Number(n)) => match n.as_u64() { Some(8) => Ok(DataType::UInt8), Some(16) => Ok(DataType::UInt16), Some(32) => Ok(DataType::UInt32), diff --git a/arrow/src/datatypes/field.rs b/arrow/src/datatypes/field.rs index a200a21380ec..51e50aea4226 100644 --- a/arrow/src/datatypes/field.rs +++ b/arrow/src/datatypes/field.rs @@ -131,7 +131,7 @@ impl Field { match *json { Value::Object(ref map) => { let name = match map.get("name") { - Some(&Value::String(ref name)) => name.to_string(), + Some(Value::String(name)) => name.to_string(), _ => { return Err(ArrowError::ParseError( "Field missing 'name' attribute".to_string(), @@ -157,7 +157,7 @@ impl Field { // Referenced example file: testing/data/arrow-ipc-stream/integration/1.0.0-littleendian/generated_custom_metadata.json.gz let metadata = match map.get("metadata") { - Some(&Value::Array(ref values)) => { + Some(Value::Array(values)) => { let mut res: BTreeMap = BTreeMap::new(); for value in values { match value.as_object() { @@ -195,7 +195,7 @@ impl Field { } // We also support map format, because Schema's metadata supports this. // See https://github.com/apache/arrow/pull/5907 - Some(&Value::Object(ref values)) => { + Some(Value::Object(values)) => { let mut res: BTreeMap = BTreeMap::new(); for (k, v) in values { if let Some(str_value) = v.as_str() { @@ -257,7 +257,7 @@ impl Field { DataType::Struct(mut fields) => match map.get("children") { Some(Value::Array(values)) => { let struct_fields: Result> = - values.iter().map(|v| Field::from(v)).collect(); + values.iter().map(Field::from).collect(); fields.append(&mut struct_fields?); DataType::Struct(fields) } @@ -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..03cfc187ce6c 100644 --- a/arrow/src/datatypes/native.rs +++ b/arrow/src/datatypes/native.rs @@ -346,10 +346,8 @@ pub trait ToByteSlice { 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::()) - } + let raw_ptr = self.as_ptr() as *const u8; + unsafe { std::slice::from_raw_parts(raw_ptr, std::mem::size_of_val(self)) } } } diff --git a/arrow/src/datatypes/schema.rs b/arrow/src/datatypes/schema.rs index 756028aa5223..ee18071ffa21 100644 --- a/arrow/src/datatypes/schema.rs +++ b/arrow/src/datatypes/schema.rs @@ -222,10 +222,7 @@ impl Schema { match *json { Value::Object(ref schema) => { let fields = if let Some(Value::Array(fields)) = schema.get("fields") { - fields - .iter() - .map(|f| Field::from(f)) - .collect::>()? + fields.iter().map(Field::from).collect::>()? } else { return Err(ArrowError::ParseError( "Schema fields should be an array".to_string(), 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/ffi.rs b/arrow/src/ffi.rs index 78d3f8fe34a5..85a114f0d852 100644 --- a/arrow/src/ffi.rs +++ b/arrow/src/ffi.rs @@ -248,18 +248,18 @@ fn bit_width(data_type: &DataType, i: usize) -> Result { (_, 0) => 1, // primitive types first buffer's size is given by the native types (DataType::Boolean, 1) => 1, - (DataType::UInt8, 1) => size_of::() * 8, - (DataType::UInt16, 1) => size_of::() * 8, - (DataType::UInt32, 1) => size_of::() * 8, - (DataType::UInt64, 1) => size_of::() * 8, - (DataType::Int8, 1) => size_of::() * 8, - (DataType::Int16, 1) => size_of::() * 8, - (DataType::Int32, 1) | (DataType::Date32, 1) | (DataType::Time32(_), 1) => size_of::() * 8, - (DataType::Int64, 1) | (DataType::Date64, 1) | (DataType::Time64(_), 1) => size_of::() * 8, + (DataType::UInt8, 1) => u8::BITS as usize, + (DataType::UInt16, 1) => u16::BITS as usize, + (DataType::UInt32, 1) => u32::BITS as usize, + (DataType::UInt64, 1) => u64::BITS as usize, + (DataType::Int8, 1) => i8::BITS as usize, + (DataType::Int16, 1) => i16::BITS as usize, + (DataType::Int32, 1) | (DataType::Date32, 1) | (DataType::Time32(_), 1) => i32::BITS as usize, + (DataType::Int64, 1) | (DataType::Date64, 1) | (DataType::Time64(_), 1) => i64::BITS as usize, (DataType::Float32, 1) => size_of::() * 8, (DataType::Float64, 1) => size_of::() * 8, - (DataType::Decimal(..), 1) => size_of::() * 8, - (DataType::Timestamp(..), 1) => size_of::() * 8, + (DataType::Decimal(..), 1) => i128::BITS as usize, + (DataType::Timestamp(..), 1) => i64::BITS as usize, // primitive types have a single buffer (DataType::Boolean, _) | (DataType::UInt8, _) | @@ -281,8 +281,8 @@ fn bit_width(data_type: &DataType, i: usize) -> Result { } // Variable-sized binaries: have two buffers. // "small": first buffer is i32, second is in bytes - (DataType::Utf8, 1) | (DataType::Binary, 1) | (DataType::List(_), 1) => size_of::() * 8, - (DataType::Utf8, 2) | (DataType::Binary, 2) | (DataType::List(_), 2) => size_of::() * 8, + (DataType::Utf8, 1) | (DataType::Binary, 1) | (DataType::List(_), 1) => i32::BITS as usize, + (DataType::Utf8, 2) | (DataType::Binary, 2) | (DataType::List(_), 2) => u8::BITS as usize, (DataType::Utf8, _) | (DataType::Binary, _) | (DataType::List(_), _)=> { return Err(ArrowError::CDataInterface(format!( "The datatype \"{:?}\" expects 3 buffers, but requested {}. Please verify that the C data interface is correctly implemented.", @@ -291,8 +291,8 @@ fn bit_width(data_type: &DataType, i: usize) -> Result { } // Variable-sized binaries: have two buffers. // LargeUtf8: first buffer is i64, second is in bytes - (DataType::LargeUtf8, 1) | (DataType::LargeBinary, 1) | (DataType::LargeList(_), 1) => size_of::() * 8, - (DataType::LargeUtf8, 2) | (DataType::LargeBinary, 2) | (DataType::LargeList(_), 2)=> size_of::() * 8, + (DataType::LargeUtf8, 1) | (DataType::LargeBinary, 1) | (DataType::LargeList(_), 1) => i64::BITS as usize, + (DataType::LargeUtf8, 2) | (DataType::LargeBinary, 2) | (DataType::LargeList(_), 2)=> u8::BITS as usize, (DataType::LargeUtf8, _) | (DataType::LargeBinary, _) | (DataType::LargeList(_), _)=> { return Err(ArrowError::CDataInterface(format!( "The datatype \"{:?}\" expects 3 buffers, but requested {}. Please verify that the C data interface is correctly implemented.", diff --git a/arrow/src/ipc/convert.rs b/arrow/src/ipc/convert.rs index a672f6388d6c..532b9a91e13e 100644 --- a/arrow/src/ipc/convert.rs +++ b/arrow/src/ipc/convert.rs @@ -398,7 +398,7 @@ pub(crate) fn build_field<'a>( /// Get the IPC type of a data type pub(crate) fn get_fb_field_type<'a>( data_type: &DataType, - is_nullable: bool, + _is_nullable: bool, fbb: &mut FlatBufferBuilder<'a>, ) -> FBFieldType<'a> { // some IPC implementations expect an empty list for child data, instead of a null value. @@ -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(), @@ -658,7 +658,7 @@ pub(crate) fn get_fb_field_type<'a>( // In this library, the dictionary "type" is a logical construct. Here we // pass through to the value type, as we've already captured the index // type in the DictionaryEncoding metadata in the parent field - get_fb_field_type(value_type, is_nullable, fbb) + get_fb_field_type(value_type, _is_nullable, fbb) } Decimal(precision, scale) => { let mut builder = ipc::DecimalBuilder::new(fbb); 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..a46a1d08df85 100644 --- a/arrow/src/tensor.rs +++ b/arrow/src/tensor.rs @@ -113,13 +113,13 @@ impl<'a, T: ArrowPrimitiveType> Tensor<'a, T> { )); } - if strides != None { + if strides.is_some() { return Err(ArrowError::InvalidArgumentError( "expected None strides for tensor with no shape".to_string(), )); } - if names != None { + if names.is_some() { return Err(ArrowError::InvalidArgumentError( "expected None names for tensor with no shape".to_string(), )); @@ -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/auth_basic_proto.rs b/integration-testing/src/flight_server_scenarios/auth_basic_proto.rs index ea7ad3c3385c..9a766b87f75a 100644 --- a/integration-testing/src/flight_server_scenarios/auth_basic_proto.rs +++ b/integration-testing/src/flight_server_scenarios/auth_basic_proto.rs @@ -41,7 +41,7 @@ pub async fn scenario_setup(port: &str) -> Result { let service = AuthBasicProtoScenarioImpl { username: AUTH_USERNAME.into(), password: AUTH_PASSWORD.into(), - peer_identity: Arc::new(Mutex::new(None)), + _peer_identity: Arc::new(Mutex::new(None)), }; let addr = super::listen_on(port).await?; let svc = FlightServiceServer::new(service); @@ -58,7 +58,7 @@ pub async fn scenario_setup(port: &str) -> Result { pub struct AuthBasicProtoScenarioImpl { username: Arc, password: Arc, - peer_identity: Arc>>, + _peer_identity: Arc>>, } impl AuthBasicProtoScenarioImpl { 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..773617e5c8cd 100644 --- a/integration-testing/src/lib.rs +++ b/integration-testing/src/lib.rs @@ -405,8 +405,8 @@ 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, - children.get(0).unwrap().clone(), + child_field, + children.first().unwrap().clone(), dictionaries, )?; let offsets: Vec = json_col @@ -428,8 +428,8 @@ 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, - children.get(0).unwrap().clone(), + child_field, + children.first().unwrap().clone(), dictionaries, )?; let offsets: Vec = json_col @@ -454,8 +454,8 @@ fn array_from_json( DataType::FixedSizeList(child_field, _) => { let children = json_col.children.clone().unwrap(); let child_array = array_from_json( - &child_field, - children.get(0).unwrap().clone(), + child_field, + children.first().unwrap().clone(), dictionaries, )?; let null_buf = create_null_buf(&json_col); 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/array_reader.rs b/parquet/src/arrow/array_reader.rs index 741650e97e6d..7d80b5ded2a4 100644 --- a/parquet/src/arrow/array_reader.rs +++ b/parquet/src/arrow/array_reader.rs @@ -1549,7 +1549,7 @@ impl<'a> ArrayReaderBuilder { column_desc, arrow_type ), - x => return Err(ArrowError(format!("Unsupported scale: {}", x))), + x => Err(ArrowError(format!("Unsupported scale: {}", x))), } } else if let Some(ArrowType::Timestamp(_, tz)) = arrow_type.as_ref() { // get the optional timezone information from arrow type diff --git a/parquet/src/arrow/arrow_array_reader.rs b/parquet/src/arrow/arrow_array_reader.rs index dd98583f8ba4..90b1ea42b71d 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()); @@ -492,7 +492,7 @@ impl<'a, C: ArrayConverter + 'a> ArrowArrayReader<'a, C> { values_buffer, num_values, )?)), - e => return Err(nyi_err!("Encoding {} is not supported", e)), + e => Err(nyi_err!("Encoding {} is not supported", e)), } } 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/levels.rs b/parquet/src/arrow/levels.rs index 61ea17d85647..b2d6b83ecbd0 100644 --- a/parquet/src/arrow/levels.rs +++ b/parquet/src/arrow/levels.rs @@ -194,7 +194,7 @@ impl LevelInfo { // Construct the child array of the list, and get its offset + mask let array_data = array.data(); - let child_data = array_data.child_data().get(0).unwrap(); + let child_data = array_data.child_data().first().unwrap(); let child_array = make_array(child_data.clone()); let (child_offsets, child_mask) = Self::get_array_offsets_and_masks( &child_array, 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/reader.rs b/parquet/src/column/reader.rs index 30b9a798ae39..e4d9dea8548e 100644 --- a/parquet/src/column/reader.rs +++ b/parquet/src/column/reader.rs @@ -419,7 +419,7 @@ impl ColumnReaderImpl { self.decoders.get_mut(&encoding).unwrap() }; - decoder.set_data(buffer_ptr.start_from(offset), len as usize)?; + decoder.set_data(buffer_ptr.start_from(offset), len)?; self.current_encoding = Some(encoding); Ok(()) } 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/data_type.rs b/parquet/src/data_type.rs index d4bda63f50fe..8a831f808d20 100644 --- a/parquet/src/data_type.rs +++ b/parquet/src/data_type.rs @@ -36,7 +36,7 @@ use crate::util::{ /// Rust representation for logical type INT96, value is backed by an array of `u32`. /// The type only takes 12 bytes, without extra padding. -#[derive(Clone, Debug, PartialOrd)] +#[derive(Clone, Debug, PartialOrd, Default)] pub struct Int96 { value: Option<[u32; 3]>, } @@ -96,12 +96,6 @@ impl Int96 { } } -impl Default for Int96 { - fn default() -> Self { - Self { value: None } - } -} - impl PartialEq for Int96 { fn eq(&self, other: &Int96) -> bool { match (&self.value, &other.value) { @@ -137,7 +131,7 @@ impl fmt::Display for Int96 { /// Rust representation for BYTE_ARRAY and FIXED_LEN_BYTE_ARRAY Parquet physical types. /// Value is backed by a byte buffer. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct ByteArray { data: Option, } @@ -242,12 +236,6 @@ impl From for ByteArray { } } -impl Default for ByteArray { - fn default() -> Self { - ByteArray { data: None } - } -} - impl PartialEq for ByteArray { fn eq(&self, other: &ByteArray) -> bool { match (&self.data, &other.data) { diff --git a/parquet/src/encodings/decoding.rs b/parquet/src/encodings/decoding.rs index 48fc108840e9..1db350695ab5 100644 --- a/parquet/src/encodings/decoding.rs +++ b/parquet/src/encodings/decoding.rs @@ -510,7 +510,7 @@ impl Decoder for DeltaBitPackDecoder { // e.g. i64::MAX - i64::MIN, so we use `wrapping_add` to "overflow" again and // restore original value. self.current_value = self.current_value.wrapping_add(self.min_delta); - self.current_value = self.current_value.wrapping_add(delta as i64); + self.current_value = self.current_value.wrapping_add(delta); self.set_decoded_value(buffer, i, self.current_value); self.values_current_mini_block -= 1; } diff --git a/parquet/src/encodings/encoding.rs b/parquet/src/encodings/encoding.rs index 944c2576adaa..191f01947f47 100644 --- a/parquet/src/encodings/encoding.rs +++ b/parquet/src/encodings/encoding.rs @@ -253,12 +253,12 @@ impl DictEncoder { pub fn write_indices(&mut self) -> Result { // TODO: the caller should allocate the buffer let buffer_len = self.estimated_data_encoded_size(); - let mut buffer: Vec = vec![0; buffer_len as usize]; - buffer[0] = self.bit_width() as u8; + let mut buffer: Vec = vec![0; buffer_len]; + buffer[0] = self.bit_width(); self.mem_tracker.alloc(buffer.capacity() as i64); // Write bit width in the first byte - buffer.write_all((self.bit_width() as u8).as_bytes())?; + buffer.write_all(self.bit_width().as_bytes())?; let mut encoder = RleEncoder::new_from_buf(self.bit_width(), buffer, 1); for index in self.buffered_indices.data() { if !encoder.put(*index as u64)? { @@ -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/file/writer.rs b/parquet/src/file/writer.rs index e37fca3fbef3..d984d7e8652d 100644 --- a/parquet/src/file/writer.rs +++ b/parquet/src/file/writer.rs @@ -19,7 +19,7 @@ //! using row group writers and column writers respectively. use std::{ - io::{Seek, SeekFrom, Write}, + io::{Seek, Write}, sync::Arc, }; @@ -181,7 +181,7 @@ impl SerializedFileWriter { let file_metadata = parquet::FileMetaData { version: self.props.writer_version().as_num(), schema: types::to_thrift(self.schema.as_ref())?, - num_rows: self.total_num_rows as i64, + num_rows: self.total_num_rows, row_groups: self .row_groups .as_slice() @@ -194,13 +194,13 @@ impl SerializedFileWriter { }; // Write file metadata - let start_pos = self.buf.seek(SeekFrom::Current(0))?; + let start_pos = self.buf.stream_position()?; { let mut protocol = TCompactOutputProtocol::new(&mut self.buf); file_metadata.write_to_out_protocol(&mut protocol)?; protocol.flush()?; } - let end_pos = self.buf.seek(SeekFrom::Current(0))?; + let end_pos = self.buf.stream_position()?; // Write footer let mut footer_buffer: [u8; FOOTER_SIZE] = [0; FOOTER_SIZE]; diff --git a/parquet/src/record/api.rs b/parquet/src/record/api.rs index 549132df8075..ad6500c18c86 100644 --- a/parquet/src/record/api.rs +++ b/parquet/src/record/api.rs @@ -227,7 +227,7 @@ pub fn make_row(fields: Vec<(String, Field)>) -> Row { impl fmt::Display for Row { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{{")?; - for (i, &(ref key, ref value)) in self.fields.iter().enumerate() { + for (i, (key, value)) in self.fields.iter().enumerate() { key.fmt(f)?; write!(f, ": ")?; value.fmt(f)?; @@ -757,7 +757,7 @@ impl fmt::Display for Field { Field::MapInternal(ref map) => { let entries = &map.entries; write!(f, "{{")?; - for (i, &(ref key, ref value)) in entries.iter().enumerate() { + for (i, (key, value)) in entries.iter().enumerate() { key.fmt(f)?; write!(f, " -> ")?; value.fmt(f)?; 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..fad42cd85ab7 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()); @@ -249,7 +249,7 @@ fn print_logical_and_converted( None => { // Also print converted type if it is available match converted_type { - ConvertedType::NONE => format!(""), + ConvertedType::NONE => String::new(), decimal @ ConvertedType::DECIMAL => { // For decimal type we should print precision and scale if they // are > 0, e.g. DECIMAL(9, 2) - @@ -259,7 +259,7 @@ fn print_logical_and_converted( format!("{}, {}", p, s) } (p, 0) if p > 0 => format!("{}", p), - _ => format!(""), + _ => String::new(), }; format!("{}{}", decimal, precision_scale) } @@ -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..c5e517b26476 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, } } @@ -1089,7 +1089,7 @@ fn from_thrift_helper( let mut fields = vec![]; let mut next_index = index + 1; for _ in 0..n { - let child_result = from_thrift_helper(elements, next_index as usize)?; + let child_result = from_thrift_helper(elements, next_index)?; next_index = child_result.0; fields.push(child_result.1); } diff --git a/parquet/src/util/bit_util.rs b/parquet/src/util/bit_util.rs index 0b1b0ff5b251..7b54347dbf8a 100644 --- a/parquet/src/util/bit_util.rs +++ b/parquet/src/util/bit_util.rs @@ -345,8 +345,7 @@ impl BitWriter { assert!(num_bits <= 64); assert_eq!(v.checked_shr(num_bits as u32).unwrap_or(0), 0); // covers case v >> 64 - if self.byte_offset * 8 + self.bit_offset + num_bits > self.max_bytes as usize * 8 - { + if self.byte_offset * 8 + self.bit_offset + num_bits > self.max_bytes * 8 { return false; } @@ -382,8 +381,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 } diff --git a/parquet/src/util/cursor.rs b/parquet/src/util/cursor.rs index eaed6c7010e6..f05e45d81868 100644 --- a/parquet/src/util/cursor.rs +++ b/parquet/src/util/cursor.rs @@ -103,8 +103,8 @@ impl Seek for SliceableCursor { fn seek(&mut self, pos: SeekFrom) -> io::Result { let new_pos = match pos { SeekFrom::Start(pos) => pos as i64, - SeekFrom::End(pos) => self.inner.len() as i64 + pos as i64, - SeekFrom::Current(pos) => self.pos as i64 + pos as i64, + SeekFrom::End(pos) => self.inner.len() as i64 + pos, + SeekFrom::Current(pos) => self.pos as i64 + pos, }; if new_pos < 0 { diff --git a/parquet/src/util/io.rs b/parquet/src/util/io.rs index 44e99ac0a779..c0cb419022bd 100644 --- a/parquet/src/util/io.rs +++ b/parquet/src/util/io.rs @@ -168,7 +168,7 @@ impl FileSink { /// Position is set to whatever position file has. pub fn new(buf: &W) -> Self { let mut owned_buf = buf.try_clone().unwrap(); - let pos = owned_buf.seek(SeekFrom::Current(0)).unwrap(); + let pos = owned_buf.stream_position().unwrap(); Self { buf: BufWriter::new(owned_buf), pos, diff --git a/parquet/tests/boolean_writer.rs b/parquet/tests/boolean_writer.rs index b9d757e71a8e..55f41a0c9eca 100644 --- a/parquet/tests/boolean_writer.rs +++ b/parquet/tests/boolean_writer.rs @@ -39,7 +39,7 @@ fn it_writes_data_without_hanging() { "; let schema = Arc::new(parse_message_type(message_type).expect("parse schema")); let props = Arc::new(WriterProperties::builder().build()); - let file = fs::File::create(&path).expect("create file"); + let file = fs::File::create(path).expect("create file"); let mut writer = SerializedFileWriter::new(file, schema, props).expect("create parquet writer"); for _group in 0..1 { @@ -75,14 +75,14 @@ fn it_writes_data_without_hanging() { } writer.close().expect("close writer"); - let bytes = fs::read(&path).expect("read file"); + let bytes = fs::read(path).expect("read file"); assert_eq!(&bytes[0..4], &[b'P', b'A', b'R', b'1']); // Now that we have written our data and are happy with it, make // sure we can read it back in < 5 seconds... let (sender, receiver) = mpsc::channel(); let _t = thread::spawn(move || { - let file = fs::File::open(&Path::new("it_writes_data_without_hanging.parquet")) + let file = fs::File::open(Path::new("it_writes_data_without_hanging.parquet")) .expect("open file"); let reader = SerializedFileReader::new(file).expect("get serialized reader"); let iter = reader.get_row_iter(None).expect("get iterator"); diff --git a/parquet_derive/src/parquet_field.rs b/parquet_derive/src/parquet_field.rs index 6f2fa0c7d4cb..7d02a0c5eadb 100644 --- a/parquet_derive/src/parquet_field.rs +++ b/parquet_derive/src/parquet_field.rs @@ -748,7 +748,7 @@ mod test { }; let fields = extract_fields(snippet); - let processed: Vec<_> = fields.iter().map(|field| Field::from(field)).collect(); + let processed: Vec<_> = fields.iter().map(Field::from).collect(); let column_writers: Vec<_> = processed .iter() @@ -779,7 +779,7 @@ mod test { }; let fields = extract_fields(snippet); - let processed: Vec<_> = fields.iter().map(|field| Field::from(field)).collect(); + let processed: Vec<_> = fields.iter().map(Field::from).collect(); assert_eq!(processed.len(), 3); assert_eq!( @@ -819,8 +819,7 @@ mod test { }; let fields = extract_fields(snippet); - let converted_fields: Vec<_> = - fields.iter().map(|field| Type::from(field)).collect(); + let converted_fields: Vec<_> = fields.iter().map(Type::from).collect(); let inner_types: Vec<_> = converted_fields .iter() .map(|field| field.inner_type()) @@ -857,8 +856,7 @@ mod test { }; let fields = extract_fields(snippet); - let converted_fields: Vec<_> = - fields.iter().map(|field| Type::from(field)).collect(); + let converted_fields: Vec<_> = fields.iter().map(Type::from).collect(); let physical_types: Vec<_> = converted_fields .iter() .map(|ty| ty.physical_type()) @@ -890,8 +888,7 @@ mod test { }; let fields = extract_fields(snippet); - let converted_fields: Vec<_> = - fields.iter().map(|field| Type::from(field)).collect(); + let converted_fields: Vec<_> = fields.iter().map(Type::from).collect(); assert_eq!( converted_fields, @@ -917,7 +914,7 @@ mod test { }; let fields = extract_fields(snippet); - let types: Vec<_> = fields.iter().map(|field| Type::from(field)).collect(); + let types: Vec<_> = fields.iter().map(Type::from).collect(); assert_eq!( types,