diff --git a/examples/parquet.rs b/examples/parquet.rs index 9ad7a2d..a263c6f 100644 --- a/examples/parquet.rs +++ b/examples/parquet.rs @@ -78,7 +78,7 @@ fn main() { let output = narrow_array.clone().into_iter().collect::>(); assert_eq!(input.as_slice(), output); - let record_batch = RecordBatch::from(narrow_array); + let record_batch: RecordBatch = narrow_array.into(); println!("From narrow StructArray to Arrow RecordBatch"); pretty::print_batches(&[record_batch.clone()]).unwrap(); @@ -94,7 +94,7 @@ fn main() { assert_eq!(record_batch, read.clone()); let round_trip: StructArray = read.into(); - let arrow_struct_array_round_trip = arrow_array::StructArray::from(round_trip); + let arrow_struct_array_round_trip: arrow_array::StructArray = round_trip.into(); let record_batch_round_trip = arrow_array::RecordBatch::from(arrow_struct_array_round_trip); println!( "From Arrow RecordBatch (via Parquet) to narrow StructArray and back to Arrow RecordBatch" diff --git a/narrow-derive/src/enum.rs b/narrow-derive/src/enum.rs index 3789dc4..02f53d1 100644 --- a/narrow-derive/src/enum.rs +++ b/narrow-derive/src/enum.rs @@ -1087,13 +1087,11 @@ impl<'a> Enum<'a> { let (_, self_ty_generics, _) = self.generics.split_for_impl(); generics.make_where_clause().predicates.extend( self.variant_indices().map::(|idx| { - parse_quote!(::std::sync::Arc: From< - <<#self_ident #self_ty_generics as #narrow::array::union::EnumVariant<#idx>>::Data as #narrow::array::ArrayType<<#self_ident #self_ty_generics as #narrow::array::union::EnumVariant<#idx>>::Data>>::Array< + parse_quote!(<<#self_ident #self_ty_generics as #narrow::array::union::EnumVariant<#idx>>::Data as #narrow::array::ArrayType<<#self_ident #self_ty_generics as #narrow::array::union::EnumVariant<#idx>>::Data>>::Array< Buffer, OffsetItem, UnionLayout, - >, - >) + >: Into<::std::sync::Arc>) }), ); @@ -1101,11 +1099,11 @@ impl<'a> Enum<'a> { let (_, ty_generics, _) = generics.split_for_impl(); let idx = self.variant_indices(); let tokens = quote! { - impl #impl_generics ::std::convert::From<#ident #ty_generics> for ::std::vec::Vec<::std::sync::Arc> #where_clause { - fn from(value: #ident #ty_generics) -> Self { + impl #impl_generics ::std::convert::Into<::std::vec::Vec<::std::sync::Arc>> for #ident #ty_generics #where_clause { + fn into(self) -> ::std::vec::Vec<::std::sync::Arc> { vec![ #( - value.#idx.into(), + self.#idx.into(), )* ] } diff --git a/narrow-derive/src/struct.rs b/narrow-derive/src/struct.rs index e43fc81..505cf93 100644 --- a/narrow-derive/src/struct.rs +++ b/narrow-derive/src/struct.rs @@ -332,7 +332,7 @@ impl Struct<'_> { let field_ident = self.field_idents(); quote!( #( - value.#field_ident.into(), + self.#field_ident.into(), )* ) } @@ -344,19 +344,20 @@ impl Struct<'_> { .map(|(idx, _)| Index::from(idx)); quote!( #( - value.#field_idx.into(), + self.#field_idx.into(), )* ) } Fields::Unit => { - quote!(value.0.into()) + quote!(self.0.into()) } }; let ident = self.array_struct_ident(); let tokens = quote! { - impl #impl_generics ::std::convert::From<#ident #ty_generics> for ::std::vec::Vec<::std::sync::Arc> #where_clause { - fn from(value: #ident #ty_generics) -> Self { + #[allow(clippy::from_over_into)] + impl #impl_generics std::convert::Into<::std::vec::Vec<::std::sync::Arc>> for #ident #ty_generics #where_clause { + fn into(self) -> ::std::vec::Vec<::std::sync::Arc> { vec![ #field_arrays ] diff --git a/src/arrow/array/boolean.rs b/src/arrow/array/boolean.rs index 25bea53..73f4c7b 100644 --- a/src/arrow/array/boolean.rs +++ b/src/arrow/array/boolean.rs @@ -23,32 +23,35 @@ impl crate::arrow::Array } } -impl From> for arrow_array::BooleanArray +#[allow(clippy::from_over_into)] +impl Into for BooleanArray where - arrow_buffer::BooleanBuffer: From>, + Bitmap: Into, { - fn from(value: BooleanArray) -> Self { - arrow_array::BooleanArray::new(value.0.into(), None) + fn into(self) -> arrow_array::BooleanArray { + arrow_array::BooleanArray::new(self.0.into(), None) } } -impl From> for arrow_array::BooleanArray +#[allow(clippy::from_over_into)] +impl Into for BooleanArray where - arrow_buffer::BooleanBuffer: From>, - arrow_buffer::NullBuffer: From>, + Bitmap: Into, + Bitmap: Into, { - fn from(value: BooleanArray) -> Self { - arrow_array::BooleanArray::new(value.0.data.into(), Some(value.0.validity.into())) + fn into(self) -> arrow_array::BooleanArray { + arrow_array::BooleanArray::new(self.0.data.into(), Some(self.0.validity.into())) } } -impl From> - for Arc +#[allow(clippy::from_over_into)] +impl Into> + for BooleanArray where - arrow_array::BooleanArray: From>, + BooleanArray: Into, { - fn from(value: BooleanArray) -> Self { - Arc::new(arrow_array::BooleanArray::from(value)) + fn into(self) -> Arc { + Arc::new(self.into()) } } diff --git a/src/arrow/array/fixed_size_binary.rs b/src/arrow/array/fixed_size_binary.rs index 7b7a72d..abffcab 100644 --- a/src/arrow/array/fixed_size_binary.rs +++ b/src/arrow/array/fixed_size_binary.rs @@ -44,12 +44,13 @@ where } } -impl From> - for arrow_array::FixedSizeBinaryArray +#[allow(clippy::from_over_into)] +impl Into + for FixedSizeBinaryArray where - arrow_buffer::Buffer: From>, + FixedSizePrimitiveArray: Into, { - fn from(value: FixedSizeBinaryArray) -> Self { + fn into(self) -> arrow_array::FixedSizeBinaryArray { // todo(mbrobbel): const_assert assert!(N <= 0x7FFF_FFFF); // i32::MAX #[allow( @@ -59,29 +60,31 @@ where )] arrow_array::FixedSizeBinaryArray::new( i32::try_from(N).expect("overflow"), - value.0 .0.into(), + self.0 .0.into(), None, ) } } -impl - From> for Arc +#[allow(clippy::from_over_into)] +impl Into> + for FixedSizeBinaryArray where - arrow_array::FixedSizeBinaryArray: From>, + FixedSizeBinaryArray: Into, { - fn from(value: FixedSizeBinaryArray) -> Self { - Arc::new(arrow_array::FixedSizeBinaryArray::from(value)) + fn into(self) -> Arc { + Arc::new(self.into()) } } -impl From> - for arrow_array::FixedSizeBinaryArray +#[allow(clippy::from_over_into)] +impl Into + for FixedSizeBinaryArray where - arrow_buffer::Buffer: From>, + FixedSizePrimitiveArray: Into, Bitmap: Into, { - fn from(value: FixedSizeBinaryArray) -> Self { + fn into(self) -> arrow_array::FixedSizeBinaryArray { // todo(mbrobbel): const_assert assert!(N <= 0x7FFF_FFFF); // i32::MAX #[allow( @@ -91,8 +94,8 @@ where )] arrow_array::FixedSizeBinaryArray::new( i32::try_from(N).expect("overflow"), - value.0 .0.data.into(), - Some(value.0 .0.validity.into()), + self.0 .0.data.into(), + Some(self.0 .0.validity.into()), ) } } @@ -148,7 +151,7 @@ mod tests { fn from() { let fixed_size_binary_array = INPUT.into_iter().collect::>(); assert_eq!( - arrow_array::FixedSizeBinaryArray::from(fixed_size_binary_array) + Into::::into(fixed_size_binary_array) .iter() .flatten() .flatten() @@ -161,7 +164,7 @@ mod tests { .into_iter() .collect::>(); assert_eq!( - arrow_array::FixedSizeBinaryArray::from(fixed_size_binary_array_nullable) + Into::::into(fixed_size_binary_array_nullable) .iter() .flatten() .flatten() @@ -206,7 +209,7 @@ mod tests { .into_iter() .collect::>(); let fixed_size_binary_array_nullable = - arrow_array::FixedSizeBinaryArray::from(fixed_size_binary_array_nullable_input); + Into::::into(fixed_size_binary_array_nullable_input); assert_eq!( FixedSizeBinaryArray::<2, Nullable>::from(fixed_size_binary_array_nullable) .into_iter() diff --git a/src/arrow/array/fixed_size_list.rs b/src/arrow/array/fixed_size_list.rs index eef373c..aac6df0 100644 --- a/src/arrow/array/fixed_size_list.rs +++ b/src/arrow/array/fixed_size_list.rs @@ -48,43 +48,46 @@ where } } -impl - From> for Arc +#[allow(clippy::from_over_into)] +impl Into> + for FixedSizeListArray where T: crate::arrow::Array + Into>, { - fn from(value: FixedSizeListArray) -> Self { + fn into(self) -> Arc { Arc::new(arrow_array::FixedSizeListArray::new( Arc::new(T::as_field("item")), i32::try_from(N).expect("overflow"), - value.0.into(), + self.0.into(), None, )) } } -impl From> - for Arc +#[allow(clippy::from_over_into)] +impl Into> + for FixedSizeListArray where T: crate::arrow::Array + Into>, Bitmap: Into, { - fn from(value: FixedSizeListArray) -> Self { + fn into(self) -> Arc { Arc::new(arrow_array::FixedSizeListArray::new( Arc::new(T::as_field("item")), i32::try_from(N).expect("overflow"), - value.0.data.into(), - Some(value.0.validity.into()), + self.0.data.into(), + Some(self.0.validity.into()), )) } } +#[allow(clippy::from_over_into)] impl - From> for arrow_array::FixedSizeListArray + Into for FixedSizeListArray where - ::Array: From + 'static, + T: Into<::Array> + 'static, { - fn from(value: FixedSizeListArray) -> Self { + fn into(self) -> arrow_array::FixedSizeListArray { // todo(mbrobbel): const_assert assert!(N <= 0x7FFF_FFFF); // i32::MAX #[allow( @@ -95,19 +98,20 @@ where arrow_array::FixedSizeListArray::new( Arc::new(T::as_field("item")), i32::try_from(N).expect("overflow"), - Arc::<::Array>::new(value.0.into()), + Arc::<::Array>::new(self.0.into()), None, ) } } +#[allow(clippy::from_over_into)] impl - From> for arrow_array::FixedSizeListArray + Into for FixedSizeListArray where - ::Array: From + 'static, + T: Into<::Array> + 'static, Bitmap: Into, { - fn from(value: FixedSizeListArray) -> Self { + fn into(self) -> arrow_array::FixedSizeListArray { // todo(mbrobbel): const_assert assert!(N <= 0x7FFF_FFFF); // i32::MAX #[allow( @@ -118,8 +122,8 @@ where arrow_array::FixedSizeListArray::new( Arc::new(T::as_field("item")), i32::try_from(N).expect("overflow"), - Arc::<::Array>::new(value.0.data.into()), - Some(value.0.validity.into()), + Arc::<::Array>::new(self.0.data.into()), + Some(self.0.validity.into()), ) } } @@ -183,7 +187,7 @@ mod tests { .into_iter() .collect::>(); assert_eq!( - arrow_array::FixedSizeListArray::from(fixed_size_list_array) + Into::::into(fixed_size_list_array) .iter() .flatten() .flat_map(|dyn_array| { @@ -199,7 +203,7 @@ mod tests { .into_iter() .collect::>(); assert_eq!( - arrow_array::FixedSizeListArray::from(fixed_size_list_array_nullable) + Into::::into(fixed_size_list_array_nullable) .iter() .flatten() .flat_map(|dyn_array| { @@ -281,8 +285,8 @@ mod tests { let fixed_size_list_array_nullable_input = INPUT_NULLABLE .into_iter() .collect::>(); - let fixed_size_list_array_nullable = - arrow_array::FixedSizeListArray::from(fixed_size_list_array_nullable_input); + let fixed_size_list_array_nullable: arrow_array::FixedSizeListArray = + fixed_size_list_array_nullable_input.into(); assert_eq!( FixedSizeListArray::< diff --git a/src/arrow/array/fixed_size_primitive.rs b/src/arrow/array/fixed_size_primitive.rs index a98137a..8eed264 100644 --- a/src/arrow/array/fixed_size_primitive.rs +++ b/src/arrow/array/fixed_size_primitive.rs @@ -9,7 +9,6 @@ use arrow_array::{ }, Array as _, }; -use arrow_buffer::ScalarBuffer; use crate::{ array::FixedSizePrimitiveArray, @@ -71,39 +70,43 @@ impl cra } } +#[allow(clippy::from_over_into)] impl, Buffer: BufferType> - From> for arrow_array::PrimitiveArray + Into> for FixedSizePrimitiveArray where - arrow_buffer::ScalarBuffer: From<::Buffer>, + ::Buffer: Into>, { - fn from(value: FixedSizePrimitiveArray) -> Self { - arrow_array::PrimitiveArray::new(value.0.into(), None) + fn into(self) -> arrow_array::PrimitiveArray { + arrow_array::PrimitiveArray::new(self.0.into(), None) } } +#[allow(clippy::from_over_into)] impl, Buffer: BufferType> - From> for arrow_array::PrimitiveArray + Into> for FixedSizePrimitiveArray where - arrow_buffer::ScalarBuffer: From<::Buffer>, - arrow_buffer::NullBuffer: From>, + ::Buffer: Into>, + Bitmap: Into, { - fn from(value: FixedSizePrimitiveArray) -> Self { - arrow_array::PrimitiveArray::new(value.0.data.into(), Some(value.0.validity.into())) + fn into(self) -> arrow_array::PrimitiveArray { + arrow_array::PrimitiveArray::new(self.0.data.into(), Some(self.0.validity.into())) } } -impl - From> for Arc +#[allow(clippy::from_over_into)] +impl Into> + for FixedSizePrimitiveArray where - arrow_array::PrimitiveArray<::ArrowPrimitiveType>: - From>, + FixedSizePrimitiveArray: + Into::ArrowPrimitiveType>>, { - fn from(value: FixedSizePrimitiveArray) -> Self { - Arc::new(arrow_array::PrimitiveArray::from(value)) + fn into(self) -> Arc { + Arc::new(self.into()) } } /// Panics when there are nulls. +#[allow(clippy::from_over_into)] impl, Buffer: BufferType> From> for FixedSizePrimitiveArray where @@ -150,30 +153,32 @@ where impl From> for FixedSizePrimitiveArray where - ::Buffer: From>, + ::Buffer: From>, { fn from(value: arrow_buffer::ScalarBuffer) -> Self { Self(value.into()) } } -impl From> - for ScalarBuffer +#[allow(clippy::from_over_into)] +impl Into> + for FixedSizePrimitiveArray where - ::Buffer: Into>, + ::Buffer: Into>, { - fn from(value: FixedSizePrimitiveArray) -> Self { - value.0.into() + fn into(self) -> arrow_buffer::ScalarBuffer { + self.0.into() } } -impl From> - for arrow_buffer::Buffer +#[allow(clippy::from_over_into)] +impl Into + for FixedSizePrimitiveArray where ::Buffer: Into, { - fn from(value: FixedSizePrimitiveArray) -> Self { - value.0.into() + fn into(self) -> arrow_buffer::Buffer { + self.0.into() } } diff --git a/src/arrow/array/logical.rs b/src/arrow/array/logical.rs index 8735ef1..c2ba323 100644 --- a/src/arrow/array/logical.rs +++ b/src/arrow/array/logical.rs @@ -60,14 +60,15 @@ where } } +#[allow(clippy::from_over_into)] impl< T: LogicalArrayType, Nullable: Nullability, Buffer: BufferType, OffsetItem: Offset, UnionLayout: UnionType, - > From> - for Arc + > Into> + for LogicalArray where Option: ArrayType, Nullable::Item: ArrayType, @@ -77,59 +78,58 @@ where UnionLayout, >: Into>, { - fn from(value: LogicalArray) -> Self { - Arc::new(value.0.into()) + fn into(self) -> Arc { + Arc::new(self.0.into()) } } +#[allow(clippy::from_over_into)] impl< T: LogicalArrayType, Nullable: Nullability, Buffer: BufferType, OffsetItem: Offset, UnionLayout: UnionType, - > From> - for arrow_array::FixedSizeListArray + > Into + for LogicalArray where Option: ArrayType, Nullable::Item: ArrayType, - arrow_array::FixedSizeListArray: From< - as ArrayType>::Array< - Buffer, - OffsetItem, - UnionLayout, - >, - >, + as ArrayType>::Array< + Buffer, + OffsetItem, + UnionLayout, + >: Into, { - fn from(value: LogicalArray) -> Self { - value.0.into() + fn into(self) -> arrow_array::FixedSizeListArray { + self.0.into() } } +#[allow(clippy::from_over_into)] impl< T: LogicalArrayType, Nullable: Nullability, Buffer: BufferType, OffsetItem: Offset, UnionLayout: UnionType, - > From> - for arrow_array::FixedSizeBinaryArray + > Into + for LogicalArray where Option: ArrayType, Nullable::Item: ArrayType, - arrow_array::FixedSizeBinaryArray: From< - as ArrayType>::Array< - Buffer, - OffsetItem, - UnionLayout, - >, - >, + as ArrayType>::Array< + Buffer, + OffsetItem, + UnionLayout, + >: Into, { - fn from(value: LogicalArray) -> Self { - value.0.into() + fn into(self) -> arrow_array::FixedSizeBinaryArray { + self.0.into() } } +#[allow(clippy::from_over_into)] impl< T: LogicalArrayType, Nullable: Nullability, @@ -137,21 +137,19 @@ impl< OffsetItem: Offset, UnionLayout: UnionType, O: OffsetSizeTrait, - > From> - for arrow_array::GenericListArray + > Into> + for LogicalArray where Option: ArrayType, Nullable::Item: ArrayType, - arrow_array::GenericListArray: From< - as ArrayType>::Array< - Buffer, - OffsetItem, - UnionLayout, - >, - >, + as ArrayType>::Array< + Buffer, + OffsetItem, + UnionLayout, + >: Into>, { - fn from(value: LogicalArray) -> Self { - value.0.into() + fn into(self) -> arrow_array::GenericListArray { + self.0.into() } } @@ -169,7 +167,7 @@ mod tests { let input = [Foo { items: None }]; let array = input.into_iter().collect::>(); - let record_batch = arrow_array::RecordBatch::from(array); + let record_batch: arrow_array::RecordBatch = array.into(); assert_eq!(record_batch.num_rows(), 1); } } diff --git a/src/arrow/array/null.rs b/src/arrow/array/null.rs index 5df937f..0705861 100644 --- a/src/arrow/array/null.rs +++ b/src/arrow/array/null.rs @@ -35,21 +35,23 @@ where } } -impl From> - for Arc +#[allow(clippy::from_over_into)] +impl Into> + for NullArray where - arrow_array::NullArray: From>, + NullArray: Into, { - fn from(value: NullArray) -> Self { - Arc::new(arrow_array::NullArray::from(value)) + fn into(self) -> Arc { + Arc::new(self.into()) } } -impl From> - for arrow_array::NullArray +#[allow(clippy::from_over_into)] +impl Into + for NullArray { - fn from(value: NullArray) -> Self { - arrow_array::NullArray::new(value.len()) + fn into(self) -> arrow_array::NullArray { + arrow_array::NullArray::new(self.len()) } } @@ -83,7 +85,7 @@ mod tests { let input = [Unit; 4]; let array = input.into_iter().collect::>(); - let arrow_array = arrow_array::NullArray::from(array); + let arrow_array: arrow_array::NullArray = array.into(); assert!(arrow_array.data_type().is_null()); let narrow_array = NullArray::::from(arrow_array); assert_eq!(narrow_array.len(), 4); @@ -92,7 +94,7 @@ mod tests { let array_nested = input_nested .into_iter() .collect::>(); - let arrow_array_nested = arrow_array::StructArray::from(array_nested); + let arrow_array_nested: arrow_array::StructArray = array_nested.into(); assert!(arrow_array_nested .column(0) .as_struct() diff --git a/src/arrow/array/string.rs b/src/arrow/array/string.rs index 268b0a9..e83db38 100644 --- a/src/arrow/array/string.rs +++ b/src/arrow/array/string.rs @@ -46,63 +46,67 @@ where } } -impl - From> for Arc +#[allow(clippy::from_over_into)] +impl Into> + for StringArray where ::Buffer: Into>, FixedSizePrimitiveArray: Into>, { - fn from(value: StringArray) -> Self { - let array: arrow_array::GenericStringArray = value.into(); + fn into(self) -> Arc { + let array: arrow_array::GenericStringArray = self.into(); Arc::new(array) } } -impl - From> for Arc +#[allow(clippy::from_over_into)] +impl Into> + for StringArray where ::Buffer: Into>, FixedSizePrimitiveArray: Into>, Bitmap: Into, { - fn from(value: StringArray) -> Self { - let array: arrow_array::GenericStringArray = value.into(); + fn into(self) -> Arc { + let array: arrow_array::GenericStringArray = self.into(); Arc::new(array) } } +#[allow(clippy::from_over_into)] impl - From> - for arrow_array::GenericStringArray + Into> + for StringArray where ::Buffer: Into>, FixedSizePrimitiveArray: Into>, { - fn from(value: StringArray) -> Self { + fn into(self) -> arrow_array::GenericStringArray { arrow_array::GenericStringArray::new( // Safety: // - The narrow offfset buffer contains valid offset data - unsafe { OffsetBuffer::new_unchecked(value.0 .0.offsets.into()) }, - value.0 .0.data.into().into_inner(), + unsafe { OffsetBuffer::new_unchecked(self.0 .0.offsets.into()) }, + self.0 .0.data.into().into_inner(), None, ) } } +#[allow(clippy::from_over_into)] impl - From> for arrow_array::GenericStringArray + Into> for StringArray where ::Buffer: Into>, FixedSizePrimitiveArray: Into>, Bitmap: Into, { - fn from(value: StringArray) -> Self { + fn into(self) -> arrow_array::GenericStringArray { arrow_array::GenericStringArray::new( // Safety: // - The narrow offfset buffer contains valid offset data - unsafe { OffsetBuffer::new_unchecked(value.0 .0.offsets.data.into()) }, - value.0 .0.data.into().into_inner(), - Some(value.0 .0.offsets.validity.into()), + unsafe { OffsetBuffer::new_unchecked(self.0 .0.offsets.data.into()) }, + self.0 .0.data.into().into_inner(), + Some(self.0 .0.offsets.validity.into()), ) } } @@ -168,7 +172,7 @@ mod tests { fn from() { let string_array = INPUT.into_iter().collect::(); assert_eq!( - arrow_array::StringArray::from(string_array) + Into::::into(string_array) .into_iter() .flatten() .collect::>(), @@ -179,7 +183,7 @@ mod tests { .into_iter() .collect::>(); assert_eq!( - arrow_array::GenericStringArray::::from(string_array_nullable) + Into::>::into(string_array_nullable) .into_iter() .collect::>(), INPUT_NULLABLE diff --git a/src/arrow/array/struct.rs b/src/arrow/array/struct.rs index fb6a5c3..c32b0a4 100644 --- a/src/arrow/array/struct.rs +++ b/src/arrow/array/struct.rs @@ -49,50 +49,53 @@ where } } +#[allow(clippy::from_over_into)] impl - From> for Arc + Into> for StructArray where - arrow_array::StructArray: From>, + StructArray: Into, { - fn from(value: StructArray) -> Self { - Arc::new(arrow_array::StructArray::from(value)) + fn into(self) -> Arc { + Arc::new(self.into()) } } -impl From> - for arrow_array::StructArray +#[allow(clippy::from_over_into)] +impl Into + for StructArray where ::Array: StructArrayTypeFields + Into>>, { - fn from(value: StructArray) -> Self { + fn into(self) -> arrow_array::StructArray { // Safety: // - struct arrays are valid by construction unsafe { arrow_array::StructArray::new_unchecked( <::Array as StructArrayTypeFields>::fields(), - value.0.into(), + self.0.into(), None, ) } } } -impl From> - for arrow_array::StructArray +#[allow(clippy::from_over_into)] +impl Into + for StructArray where ::Array: StructArrayTypeFields + Into>>, Bitmap: Into, { - fn from(value: StructArray) -> Self { + fn into(self) -> arrow_array::StructArray { // Safety: // - struct arrays are valid by construction unsafe { arrow_array::StructArray::new_unchecked( <::Array as StructArrayTypeFields>::fields(), - value.0.data.into(), - Some(value.0.validity.into()), + self.0.data.into(), + Some(self.0.validity.into()), ) } } @@ -154,13 +157,15 @@ where } } -impl - From> for arrow_array::RecordBatch +#[allow(clippy::from_over_into)] +impl Into + for StructArray where - arrow_array::StructArray: From>, + StructArray: Into, { - fn from(value: StructArray) -> Self { - Self::from(arrow_array::StructArray::from(value)) + fn into(self) -> arrow_array::RecordBatch { + let arrow_struct_array: arrow_array::StructArray = self.into(); + arrow_array::RecordBatch::from(arrow_struct_array) } } @@ -318,13 +323,13 @@ mod tests { let struct_array = [Foo { a: 1 }, Foo { a: 2 }] .into_iter() .collect::>(); - let struct_array_arrow = arrow_array::StructArray::from(struct_array); + let struct_array_arrow: arrow_array::StructArray = struct_array.into(); assert_eq!(struct_array_arrow.len(), 2); let struct_array_nullable = [Some(Foo { a: 1234 }), None] .into_iter() .collect::>(); - let struct_array_arrow_nullable = arrow_array::StructArray::from(struct_array_nullable); + let struct_array_arrow_nullable: arrow_array::StructArray = struct_array_nullable.into(); assert_eq!(struct_array_arrow_nullable.len(), 2); assert!(struct_array_arrow_nullable.is_valid(0)); assert!(struct_array_arrow_nullable.is_null(1)); @@ -348,7 +353,7 @@ mod tests { let struct_array = [Foo { a: 1 }, Foo { a: 2 }] .into_iter() .collect::>(); - let struct_array_arrow = arrow_array::StructArray::from(struct_array); + let struct_array_arrow: arrow_array::StructArray = struct_array.into(); assert!(!StructArray::::from(struct_array_arrow).any_null()); } @@ -358,7 +363,7 @@ mod tests { let struct_array_nullable = [Some(Foo { a: 1234 }), None] .into_iter() .collect::>(); - let struct_array_arrow_nullable = arrow_array::StructArray::from(struct_array_nullable); + let struct_array_arrow_nullable: arrow_array::StructArray = struct_array_nullable.into(); let _ = StructArray::::from(struct_array_arrow_nullable); } @@ -367,7 +372,7 @@ mod tests { let struct_array = [Foo { a: 1 }, Foo { a: 2 }] .into_iter() .collect::>(); - let struct_array_arrow = arrow_array::StructArray::from(struct_array); + let struct_array_arrow: arrow_array::StructArray = struct_array.into(); assert_eq!( StructArray::::from(struct_array_arrow) .0 @@ -378,7 +383,7 @@ mod tests { let struct_array_nullable = [Some(Foo { a: 1234 }), None] .into_iter() .collect::>(); - let struct_array_arrow_nullable = arrow_array::StructArray::from(struct_array_nullable); + let struct_array_arrow_nullable: arrow_array::StructArray = struct_array_nullable.into(); assert_eq!( StructArray::::from(struct_array_arrow_nullable) .0 @@ -420,7 +425,7 @@ mod tests { let struct_array = [Foo(1_i32, 2), Foo(3, 4)] .into_iter() .collect::, NonNullable>>(); - let struct_array_arrow = arrow_array::StructArray::from(struct_array); + let struct_array_arrow: arrow_array::StructArray = struct_array.into(); assert_eq!(struct_array_arrow.len(), 2); let struct_array_roundtrip: StructArray> = struct_array_arrow.into(); @@ -490,14 +495,14 @@ mod tests { .into_iter() .collect::>(); - let arrow_array = arrow_array::StructArray::from(foo_array); + let arrow_array: arrow_array::StructArray = foo_array.into(); let bar_array = StructArray::::from(arrow_array); assert_eq!( bar_array.clone().into_iter().collect::>(), [Bar { b: false, a: 1 }, Bar { b: true, a: 2 }] ); - let bar_arrow_array = arrow_array::StructArray::from(bar_array); + let bar_arrow_array: arrow_array::StructArray = bar_array.into(); let _ = StructArray::::from(bar_arrow_array); } } diff --git a/src/arrow/array/union.rs b/src/arrow/array/union.rs index 56358f5..6527ae5 100644 --- a/src/arrow/array/union.rs +++ b/src/arrow/array/union.rs @@ -70,20 +70,21 @@ where } } +#[allow(clippy::from_over_into)] impl< T: UnionArrayType, const VARIANTS: usize, Buffer: BufferType, OffsetItem: Offset, - > From> for arrow_array::UnionArray + > Into for UnionArray where for<'a> i8: From<&'a T>, >::Array: UnionArrayTypeFields + Into>>, - arrow_buffer::ScalarBuffer: From>, + FixedSizePrimitiveArray: Into>, UnionArray: crate::arrow::Array, { - fn from(value: UnionArray) -> Self { + fn into(self) -> arrow_array::UnionArray { let union_fields = match < UnionArray as crate::arrow::Array>::as_field("").data_type() { &DataType::Union(ref fields, _mode) => fields.to_owned(), _ => unreachable!(), @@ -93,48 +94,50 @@ where unsafe { arrow_array::UnionArray::new_unchecked( union_fields, - arrow_buffer::ScalarBuffer::from(value.0.types), + Into::>::into(self.0.types), None, - value.0.variants.into(), + self.0.variants.into(), ) } } } +#[allow(clippy::from_over_into)] impl< T: UnionArrayType, const VARIANTS: usize, Buffer: BufferType, OffsetItem: Offset, - > From> - for Arc + > Into> + for UnionArray where for<'a> i8: From<&'a T>, >::Array: UnionArrayTypeFields + Into>>, - arrow_buffer::ScalarBuffer: From>, + FixedSizePrimitiveArray: Into>, UnionArray: crate::arrow::Array, { - fn from(value: UnionArray) -> Self { - Arc::new(arrow_array::UnionArray::from(value)) + fn into(self) -> Arc { + Arc::new(Into::::into(self)) } } +#[allow(clippy::from_over_into)] impl< T: UnionArrayType, const VARIANTS: usize, Buffer: BufferType, OffsetItem: Offset, - > From> for arrow_array::UnionArray + > Into for UnionArray where for<'a> i8: From<&'a T>, >::Array: UnionArrayTypeFields + Into>>, - arrow_buffer::ScalarBuffer: From>, - arrow_buffer::ScalarBuffer: From>, + FixedSizePrimitiveArray: Into>, + FixedSizePrimitiveArray: Into>, UnionArray: crate::arrow::Array, { - fn from(value: UnionArray) -> Self { + fn into(self) -> arrow_array::UnionArray { let union_fields = match < UnionArray as crate::arrow::Array>::as_field("").data_type() { &DataType::Union(ref fields, _mode) => fields.to_owned(), _ => unreachable!(), @@ -144,30 +147,33 @@ where unsafe { arrow_array::UnionArray::new_unchecked( union_fields, - arrow_buffer::ScalarBuffer::from(value.0.types), - Some(arrow_buffer::ScalarBuffer::::from(value.0.offsets)), - value.0.variants.into(), + Into::>::into(self.0.types), + Some(Into::>::into( + self.0.offsets, + )), + self.0.variants.into(), ) } } } +#[allow(clippy::from_over_into)] impl< T: UnionArrayType, const VARIANTS: usize, Buffer: BufferType, OffsetItem: Offset, - > From> for Arc + > Into> for UnionArray where for<'a> i8: From<&'a T>, >::Array: UnionArrayTypeFields + Into>>, - arrow_buffer::ScalarBuffer: From>, - arrow_buffer::ScalarBuffer: From>, + FixedSizePrimitiveArray: Into>, + FixedSizePrimitiveArray: Into>, UnionArray: crate::arrow::Array, { - fn from(value: UnionArray) -> Self { - Arc::new(arrow_array::UnionArray::from(value)) + fn into(self) -> Arc { + Arc::new(Into::::into(self)) } } @@ -282,7 +288,7 @@ mod tests { fn via_dyn_array() { let input = [Wrap(FooBar::Foo), Wrap(FooBar::Bar(123))]; let struct_array = input.clone().into_iter().collect::>(); - let record_batch = RecordBatch::from(struct_array); + let record_batch: RecordBatch = struct_array.into(); let read = StructArray::::from(record_batch); assert_eq!(read.into_iter().collect::>(), input); } @@ -300,14 +306,14 @@ mod tests { .into_iter() .collect::>(); assert_eq!(sparse_union_array.len(), 4); - let union_array_arrow = arrow_array::UnionArray::from(sparse_union_array); + let union_array_arrow: arrow_array::UnionArray = sparse_union_array.into(); assert_eq!(arrow_array::Array::len(&union_array_arrow), 4); let dense_union_array = input .into_iter() .collect::>(); assert_eq!(dense_union_array.len(), 4); - let dense_union_array_arrow = arrow_array::UnionArray::from(dense_union_array); + let dense_union_array_arrow: arrow_array::UnionArray = dense_union_array.into(); assert_eq!(arrow_array::Array::len(&dense_union_array_arrow), 4); } @@ -323,14 +329,14 @@ mod tests { .clone() .into_iter() .collect::>(); - let union_array_arrow = arrow_array::UnionArray::from(sparse_union_array); + let union_array_arrow: arrow_array::UnionArray = sparse_union_array.into(); let narrow_union_array: UnionArray = union_array_arrow.into(); assert_eq!(narrow_union_array.len(), 4); let dense_union_array = input .into_iter() .collect::>(); - let dense_union_array_arrow = arrow_array::UnionArray::from(dense_union_array); + let dense_union_array_arrow: arrow_array::UnionArray = dense_union_array.into(); let narrow_dense_union_array: UnionArray = dense_union_array_arrow.into(); assert_eq!(narrow_dense_union_array.len(), 4); @@ -349,7 +355,7 @@ mod tests { .clone() .into_iter() .collect::>(); - let union_array_arrow = arrow_array::UnionArray::from(union_array); + let union_array_arrow: arrow_array::UnionArray = union_array.into(); let _: UnionArray = union_array_arrow.into(); } @@ -366,7 +372,7 @@ mod tests { .clone() .into_iter() .collect::>(); - let union_array_arrow = arrow_array::UnionArray::from(union_array); + let union_array_arrow: arrow_array::UnionArray = union_array.into(); let _array: UnionArray = union_array_arrow.into(); } @@ -388,7 +394,7 @@ mod tests { .clone() .into_iter() .collect::>(); - let union_array_arrow = arrow_array::UnionArray::from(union_array); + let union_array_arrow: arrow_array::UnionArray = union_array.into(); let _array: UnionArray = union_array_arrow.into(); } @@ -412,7 +418,7 @@ mod tests { let union_array = input .into_iter() .collect::>(); - let union_array_arrow = arrow_array::UnionArray::from(union_array); + let union_array_arrow: arrow_array::UnionArray = union_array.into(); let _array: UnionArray = union_array_arrow.into(); } } diff --git a/src/arrow/array/variable_size_binary.rs b/src/arrow/array/variable_size_binary.rs index 4452ade..2002d84 100644 --- a/src/arrow/array/variable_size_binary.rs +++ b/src/arrow/array/variable_size_binary.rs @@ -46,64 +46,68 @@ where } } -impl - From> for Arc +#[allow(clippy::from_over_into)] +impl Into> + for VariableSizeBinaryArray where ::Buffer: Into>, FixedSizePrimitiveArray: Into>, { - fn from(value: VariableSizeBinaryArray) -> Self { - let array: arrow_array::GenericBinaryArray = value.into(); + fn into(self) -> Arc { + let array: arrow_array::GenericBinaryArray = self.into(); Arc::new(array) } } -impl - From> for Arc +#[allow(clippy::from_over_into)] +impl Into> + for VariableSizeBinaryArray where ::Buffer: Into>, FixedSizePrimitiveArray: Into>, Bitmap: Into, { - fn from(value: VariableSizeBinaryArray) -> Self { - let array: arrow_array::GenericBinaryArray = value.into(); + fn into(self) -> Arc { + let array: arrow_array::GenericBinaryArray = self.into(); Arc::new(array) } } +#[allow(clippy::from_over_into)] impl - From> - for arrow_array::GenericBinaryArray + Into> + for VariableSizeBinaryArray where ::Buffer: Into>, FixedSizePrimitiveArray: Into>, { - fn from(value: VariableSizeBinaryArray) -> Self { + fn into(self) -> arrow_array::GenericBinaryArray { arrow_array::GenericBinaryArray::new( // Safety: // - The narrow offset buffer contains valid offset data - unsafe { OffsetBuffer::new_unchecked(value.0.offsets.into()) }, - value.0.data.into().into_inner(), + unsafe { OffsetBuffer::new_unchecked(self.0.offsets.into()) }, + self.0.data.into().into_inner(), None, ) } } +#[allow(clippy::from_over_into)] impl - From> - for arrow_array::GenericBinaryArray + Into> + for VariableSizeBinaryArray where ::Buffer: Into>, FixedSizePrimitiveArray: Into>, Bitmap: Into, { - fn from(value: VariableSizeBinaryArray) -> Self { + fn into(self) -> arrow_array::GenericBinaryArray { arrow_array::GenericBinaryArray::new( // Safety: // - The narrow offset buffer contains valid offset data - unsafe { OffsetBuffer::new_unchecked(value.0.offsets.data.into()) }, - value.0.data.into().into_inner(), - Some(value.0.offsets.validity.into()), + unsafe { OffsetBuffer::new_unchecked(self.0.offsets.data.into()) }, + self.0.data.into().into_inner(), + Some(self.0.offsets.validity.into()), ) } } @@ -173,7 +177,7 @@ mod tests { fn from() { let vsb_array = input().into_iter().collect::(); assert_eq!( - arrow_array::BinaryArray::from(vsb_array) + Into::::into(vsb_array) .into_iter() .flatten() .collect::>(), @@ -184,7 +188,7 @@ mod tests { .into_iter() .collect::>(); assert_eq!( - arrow_array::GenericBinaryArray::::from(vsb_array_nullable) + Into::>::into(vsb_array_nullable) .into_iter() .map(|o| o.map(<[u8]>::to_vec)) .collect::>(), diff --git a/src/arrow/array/variable_size_list.rs b/src/arrow/array/variable_size_list.rs index 359f38f..11c11c6 100644 --- a/src/arrow/array/variable_size_list.rs +++ b/src/arrow/array/variable_size_list.rs @@ -50,66 +50,70 @@ where } } +#[allow(clippy::from_over_into)] impl - From> for Arc + Into> for VariableSizeListArray where ::Buffer: Into>, - ::Array: From + 'static, + T: Into<::Array> + 'static, { - fn from(value: VariableSizeListArray) -> Self { - let array: arrow_array::GenericListArray = value.into(); + fn into(self) -> Arc { + let array: arrow_array::GenericListArray = self.into(); Arc::new(array) } } +#[allow(clippy::from_over_into)] impl - From> for Arc + Into> for VariableSizeListArray where ::Buffer: Into>, Bitmap: Into, - ::Array: From + 'static, + T: Into<::Array> + 'static, { - fn from(value: VariableSizeListArray) -> Self { - let array: arrow_array::GenericListArray = value.into(); + fn into(self) -> Arc { + let array: arrow_array::GenericListArray = self.into(); Arc::new(array) } } +#[allow(clippy::from_over_into)] impl - From> - for arrow_array::GenericListArray + Into> + for VariableSizeListArray where ::Buffer: Into>, - ::Array: From + 'static, + T: Into<::Array> + 'static, { - fn from(value: VariableSizeListArray) -> Self { + fn into(self) -> arrow_array::GenericListArray { arrow_array::GenericListArray::new( Arc::new(T::as_field("item")), // Safety: // - The narrow offfset buffer contains valid offset data - unsafe { OffsetBuffer::new_unchecked(value.0.offsets.into()) }, - Arc::<::Array>::new(value.0.data.into()), + unsafe { OffsetBuffer::new_unchecked(self.0.offsets.into()) }, + Arc::<::Array>::new(self.0.data.into()), None, ) } } +#[allow(clippy::from_over_into)] impl - From> - for arrow_array::GenericListArray + Into> + for VariableSizeListArray where ::Buffer: Into>, Bitmap: Into, - ::Array: From + 'static, + T: Into<::Array> + 'static, { - fn from(value: VariableSizeListArray) -> Self { + fn into(self) -> arrow_array::GenericListArray { arrow_array::GenericListArray::new( Arc::new(T::as_field("item")), // Safety: // - The narrow offfset buffer contains valid offset data - unsafe { OffsetBuffer::new_unchecked(value.0.offsets.data.into()) }, - Arc::<::Array>::new(value.0.data.into()), - Some(value.0.offsets.validity.into()), + unsafe { OffsetBuffer::new_unchecked(self.0.offsets.data.into()) }, + Arc::<::Array>::new(self.0.data.into()), + Some(self.0.offsets.validity.into()), ) } } @@ -187,13 +191,13 @@ mod tests { let variable_size_list_array = INPUT .into_iter() .collect::>(); - let list_array = arrow_array::ListArray::from(variable_size_list_array); + let list_array: arrow_array::ListArray = variable_size_list_array.into(); assert_eq!(list_array.len(), INPUT.len()); let variable_size_list_array_nullable = INPUT_NULLABLE .into_iter() .collect::>(); - let list_array_nullable = arrow_array::ListArray::from(variable_size_list_array_nullable); + let list_array_nullable: arrow_array::ListArray = variable_size_list_array_nullable.into(); assert_eq!(list_array_nullable.len(), INPUT_NULLABLE.len()); } diff --git a/src/arrow/bitmap.rs b/src/arrow/bitmap.rs index 2a23ead..2ede0c6 100644 --- a/src/arrow/bitmap.rs +++ b/src/arrow/bitmap.rs @@ -2,21 +2,23 @@ use crate::{bitmap::Bitmap, buffer::BufferType, Length}; -impl From> for arrow_buffer::BooleanBuffer +#[allow(clippy::from_over_into)] +impl Into for Bitmap where ::Buffer: Into, { - fn from(value: Bitmap) -> Self { - Self::new(value.buffer.into(), value.offset, value.bits) + fn into(self) -> arrow_buffer::BooleanBuffer { + arrow_buffer::BooleanBuffer::new(self.buffer.into(), self.offset, self.bits) } } -impl From> for arrow_buffer::NullBuffer +#[allow(clippy::from_over_into)] +impl Into for Bitmap where - arrow_buffer::BooleanBuffer: From>, + Bitmap: Into, { - fn from(value: Bitmap) -> Self { - Self::new(value.into()) + fn into(self) -> arrow_buffer::NullBuffer { + arrow_buffer::NullBuffer::new(self.into()) } }