diff --git a/arrow-array/src/array/binary_array.rs b/arrow-array/src/array/binary_array.rs index 259d949d42a5..2ca8a061a6fa 100644 --- a/arrow-array/src/array/binary_array.rs +++ b/arrow-array/src/array/binary_array.rs @@ -655,7 +655,7 @@ mod tests { #[test] #[should_panic(expected = "LargeBinaryArray expects DataType::LargeBinary")] fn test_binary_array_validation() { - let array = BinaryArray::from_iter_values(&[&[1, 2]]); + let array = BinaryArray::from_iter_values([&[1, 2]]); let _ = LargeBinaryArray::from(array.into_data()); } diff --git a/arrow-schema/src/field.rs b/arrow-schema/src/field.rs index adafbfa9b72c..e414d2834275 100644 --- a/arrow-schema/src/field.rs +++ b/arrow-schema/src/field.rs @@ -200,12 +200,12 @@ impl Field { /// within `self` contained within this field (including `self`) pub(crate) fn fields(&self) -> Vec<&Field> { let mut collected_fields = vec![self]; - collected_fields.append(&mut self._fields(&self.data_type)); + collected_fields.append(&mut Field::_fields(&self.data_type)); collected_fields } - fn _fields<'a>(&'a self, dt: &'a DataType) -> Vec<&Field> { + fn _fields(dt: &DataType) -> Vec<&Field> { match dt { DataType::Struct(fields) | DataType::Union(fields, _, _) => { fields.iter().flat_map(|f| f.fields()).collect() @@ -214,7 +214,7 @@ impl Field { | DataType::LargeList(field) | DataType::FixedSizeList(field, _) | DataType::Map(field, _) => field.fields(), - DataType::Dictionary(_, value_field) => self._fields(value_field.as_ref()), + DataType::Dictionary(_, value_field) => Field::_fields(value_field.as_ref()), _ => vec![], } } diff --git a/arrow/benches/lexsort.rs b/arrow/benches/lexsort.rs index 3820007231ab..aebb588cf9cc 100644 --- a/arrow/benches/lexsort.rs +++ b/arrow/benches/lexsort.rs @@ -162,8 +162,8 @@ fn add_benchmark(c: &mut Criterion) { ]; for case in cases { - do_bench(c, *case, 4096); - do_bench(c, *case, 4096 * 8); + do_bench(c, case, 4096); + do_bench(c, case, 4096 * 8); } } diff --git a/arrow/src/compute/kernels/partition.rs b/arrow/src/compute/kernels/partition.rs index e3a1497b8d27..0e48e627e655 100644 --- a/arrow/src/compute/kernels/partition.rs +++ b/arrow/src/compute/kernels/partition.rs @@ -174,33 +174,24 @@ mod tests { let median = input[input.len() / 2]; assert_eq!( 9, - partition_point( - 0, - input.len(), - &(|i: usize| input[i].cmp(&median) != Ordering::Greater) - ) + partition_point(0, input.len(), |i: usize| input[i].cmp(&median) + != Ordering::Greater) ); } { let search = input[9]; assert_eq!( 12, - partition_point( - 9, - input.len(), - &(|i: usize| input[i].cmp(&search) != Ordering::Greater) - ) + partition_point(9, input.len(), |i: usize| input[i].cmp(&search) + != Ordering::Greater) ); } { let search = input[0]; assert_eq!( 3, - partition_point( - 0, - 9, - &(|i: usize| input[i].cmp(&search) != Ordering::Greater) - ) + partition_point(0, 9, |i: usize| input[i].cmp(&search) + != Ordering::Greater) ); } let input = &[1, 2, 2, 2, 2, 2, 2, 2, 9]; @@ -208,11 +199,8 @@ mod tests { let search = input[5]; assert_eq!( 8, - partition_point( - 5, - 9, - &(|i: usize| input[i].cmp(&search) != Ordering::Greater) - ) + partition_point(5, 9, |i: usize| input[i].cmp(&search) + != Ordering::Greater) ); } } diff --git a/arrow/src/csv/reader.rs b/arrow/src/csv/reader.rs index 123c5e1c6716..ff6df5514983 100644 --- a/arrow/src/csv/reader.rs +++ b/arrow/src/csv/reader.rs @@ -1690,7 +1690,7 @@ mod tests { let actual = result.unwrap_err().to_string(); assert!( - actual.contains(&expected), + actual.contains(expected), "actual: '{}', expected: '{}'", actual, expected diff --git a/arrow/src/ffi.rs b/arrow/src/ffi.rs index 77d277afa300..95e6dce3c5fd 100644 --- a/arrow/src/ffi.rs +++ b/arrow/src/ffi.rs @@ -474,11 +474,7 @@ impl FFI_ArrowArray { // If the layout has a null buffer by Arrow spec. // Note that even the array doesn't have a null buffer because it has // no null value, we still need to count 1 here to follow the spec. - if data_layout.can_contain_null_mask { - 1 - } else { - 0 - } + usize::from(data_layout.can_contain_null_mask) } } as i64; diff --git a/arrow/src/ipc/convert.rs b/arrow/src/ipc/convert.rs index 9f6cda37c650..0f5d246bcce5 100644 --- a/arrow/src/ipc/convert.rs +++ b/arrow/src/ipc/convert.rs @@ -437,7 +437,7 @@ pub(crate) fn build_field<'a>( }; let fb_field_name = fbb.create_string(field.name().as_str()); - let field_type = get_fb_field_type(field.data_type(), field.is_nullable(), fbb); + let field_type = get_fb_field_type(field.data_type(), fbb); let fb_dictionary = if let Dictionary(index_type, _) = field.data_type() { Some(get_fb_dictionary( @@ -477,7 +477,6 @@ 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, fbb: &mut FlatBufferBuilder<'a>, ) -> FBFieldType<'a> { // some IPC implementations expect an empty list for child data, instead of a null value. @@ -717,7 +716,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, fbb) } Decimal128(precision, scale) => { let mut builder = ipc::DecimalBuilder::new(fbb); diff --git a/arrow/src/json/reader.rs b/arrow/src/json/reader.rs index d15894024809..a7382128e1c8 100644 --- a/arrow/src/json/reader.rs +++ b/arrow/src/json/reader.rs @@ -962,7 +962,7 @@ impl Decoder { fn build_boolean_array(&self, rows: &[Value], col_name: &str) -> Result { let mut builder = BooleanBuilder::with_capacity(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 { @@ -993,7 +993,7 @@ impl Decoder { Ok(Arc::new( rows.iter() .map(|row| { - row.get(&col_name).and_then(|value| { + row.get(col_name).and_then(|value| { if value.is_i64() { value.as_i64().and_then(num::cast::cast) } else if value.is_u64() { @@ -1496,7 +1496,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/tensor.rs b/arrow/src/tensor.rs index b8d07f83fb90..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(), )); diff --git a/arrow/src/util/pretty.rs b/arrow/src/util/pretty.rs index 8d811223cbb5..63d5977e21c5 100644 --- a/arrow/src/util/pretty.rs +++ b/arrow/src/util/pretty.rs @@ -64,7 +64,7 @@ fn create_table(results: &[RecordBatch]) -> Result { let mut header = Vec::new(); for field in schema.fields() { - header.push(Cell::new(&field.name())); + header.push(Cell::new(field.name())); } table.set_header(header); @@ -317,9 +317,9 @@ mod tests { let mut builder = FixedSizeBinaryBuilder::with_capacity(3, 3); - builder.append_value(&[1, 2, 3]).unwrap(); + builder.append_value([1, 2, 3]).unwrap(); builder.append_null(); - builder.append_value(&[7, 8, 9]).unwrap(); + builder.append_value([7, 8, 9]).unwrap(); let array = Arc::new(builder.finish()); diff --git a/arrow/tests/array_equal.rs b/arrow/tests/array_equal.rs index a5f3f42a1dfd..d24a24e2ea48 100644 --- a/arrow/tests/array_equal.rs +++ b/arrow/tests/array_equal.rs @@ -386,11 +386,11 @@ fn create_list_array, T: AsRef<[Option]>>(data: T) -> ArrayDa #[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); } @@ -448,11 +448,11 @@ fn test_empty_offsets_list_equal() { // 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]), @@ -462,7 +462,7 @@ fn test_list_null() { ]); 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 @@ -506,8 +506,8 @@ fn test_list_null() { // 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); @@ -539,32 +539,32 @@ fn create_fixed_size_binary_array, T: AsRef<[Option]>>( #[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, @@ -572,7 +572,7 @@ fn test_fixed_size_binary_offsets() { None, None, ]); - let b = create_fixed_size_binary_array(&[ + let b = create_fixed_size_binary_array([ Some(b"hello"), None, None, @@ -706,18 +706,18 @@ fn create_fixed_size_list_array, T: AsRef<[Option]>>( #[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, @@ -725,7 +725,7 @@ fn test_fixed_list_null() { None, None, ]); - let b = create_fixed_size_list_array(&[ + let b = create_fixed_size_list_array([ Some(&[1, 2, 3]), None, None, @@ -735,7 +735,7 @@ fn test_fixed_list_null() { ]); 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]), @@ -745,7 +745,7 @@ fn test_fixed_list_null() { ]); 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, @@ -755,7 +755,7 @@ fn test_fixed_list_null() { ]); test_equal(&a, &b, false); - let b = create_fixed_size_list_array(&[None, Some(&[4, 5, 6]), None, None]); + let b = create_fixed_size_list_array([None, Some(&[4, 5, 6]), None, None]); test_equal(&a.slice(2, 4), &b, true); test_equal(&a.slice(3, 3), &b.slice(1, 3), true); @@ -764,7 +764,7 @@ fn test_fixed_list_null() { #[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, @@ -772,7 +772,7 @@ fn test_fixed_list_offsets() { 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/parquet/src/bin/parquet-read.rs b/parquet/src/bin/parquet-read.rs index 733e56173aa2..cf8009956e2e 100644 --- a/parquet/src/bin/parquet-read.rs +++ b/parquet/src/bin/parquet-read.rs @@ -78,7 +78,7 @@ fn main() { ) } else { let path = Path::new(&filename); - let file = File::open(&path).expect("Unable to open file"); + let file = File::open(path).expect("Unable to open file"); Box::new(SerializedFileReader::new(file).expect("Failed to create reader")) }; diff --git a/parquet/src/bin/parquet-schema.rs b/parquet/src/bin/parquet-schema.rs index 68c52def7c44..cd8e7692203d 100644 --- a/parquet/src/bin/parquet-schema.rs +++ b/parquet/src/bin/parquet-schema.rs @@ -57,7 +57,7 @@ fn main() { let args = Args::parse(); let filename = args.file_path; let path = Path::new(&filename); - let file = File::open(&path).expect("Unable to open file"); + let file = File::open(path).expect("Unable to open file"); let verbose = args.verbose; match SerializedFileReader::new(file) { diff --git a/parquet/src/record/api.rs b/parquet/src/record/api.rs index 22b8a79780ab..d7e1e7550f00 100644 --- a/parquet/src/record/api.rs +++ b/parquet/src/record/api.rs @@ -835,7 +835,7 @@ fn convert_decimal_to_string(decimal: &Decimal) -> String { let num = BigInt::from_signed_bytes_be(decimal.data()); // Offset of the first digit in a string. - let negative = if num.sign() == Sign::Minus { 1 } else { 0 }; + let negative = i32::from(num.sign() == Sign::Minus); let mut num_str = num.to_string(); let mut point = num_str.len() as i32 - decimal.scale() - negative; diff --git a/parquet/src/schema/types.rs b/parquet/src/schema/types.rs index da6419424490..9f8023c91262 100644 --- a/parquet/src/schema/types.rs +++ b/parquet/src/schema/types.rs @@ -2075,7 +2075,7 @@ mod tests { let mut thrift_schema = to_thrift(&expected_schema).unwrap(); // Change all of None to Some(0) for mut elem in &mut thrift_schema[..] { - if elem.num_children == None { + if elem.num_children.is_none() { elem.num_children = Some(0); } } diff --git a/parquet/tests/boolean_writer.rs b/parquet/tests/boolean_writer.rs index dc2eccfbf3c3..8c3d50d8fde8 100644 --- a/parquet/tests/boolean_writer.rs +++ b/parquet/tests/boolean_writer.rs @@ -38,7 +38,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 { @@ -64,14 +64,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 82e3b5112fe0..06bcc0aca924 100644 --- a/parquet_derive/src/parquet_field.rs +++ b/parquet_derive/src/parquet_field.rs @@ -362,21 +362,20 @@ impl Type { /// Useful in determining the physical type of a field and the /// definition levels. fn leaf_type_recursive(&self) -> &Type { - self.leaf_type_recursive_helper(self, None) + Type::leaf_type_recursive_helper(self, None) } fn leaf_type_recursive_helper<'a>( - &'a self, ty: &'a Type, parent_ty: Option<&'a Type>, - ) -> &Type { + ) -> &'a Type { match ty { Type::TypePath(_) => parent_ty.unwrap_or(ty), Type::Option(ref first_type) | Type::Vec(ref first_type) | Type::Array(ref first_type) | Type::Reference(_, ref first_type) => { - self.leaf_type_recursive_helper(first_type, Some(ty)) + Type::leaf_type_recursive_helper(first_type, Some(ty)) } } }