diff --git a/arrow/src/array/array.rs b/arrow/src/array/array.rs index 76b29d37239f..3a4d90cee27d 100644 --- a/arrow/src/array/array.rs +++ b/arrow/src/array/array.rs @@ -54,7 +54,7 @@ pub trait Array: fmt::Debug + Send + Sync + JsonEqual { /// # Ok(()) /// # } /// ``` - fn as_any(&self) -> &Any; + fn as_any(&self) -> &dyn Any; /// Returns a reference to the underlying data of this array. fn data(&self) -> &ArrayData; @@ -224,7 +224,7 @@ pub trait Array: fmt::Debug + Send + Sync + JsonEqual { } /// A reference-counted reference to a generic `Array`. -pub type ArrayRef = Arc; +pub type ArrayRef = Arc; /// Constructs an array using the input `data`. /// Returns a reference-counted `Array` instance. diff --git a/arrow/src/array/array_binary.rs b/arrow/src/array/array_binary.rs index faf9c5cf18fe..6865ffd8b984 100644 --- a/arrow/src/array/array_binary.rs +++ b/arrow/src/array/array_binary.rs @@ -191,7 +191,7 @@ impl fmt::Debug for GenericBinaryArray Array for GenericBinaryArray { - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } @@ -582,7 +582,7 @@ impl fmt::Debug for FixedSizeBinaryArray { } impl Array for FixedSizeBinaryArray { - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } @@ -752,7 +752,7 @@ impl fmt::Debug for DecimalArray { } impl Array for DecimalArray { - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } diff --git a/arrow/src/array/array_boolean.rs b/arrow/src/array/array_boolean.rs index 37080fe5a8c7..40b0f907c2c2 100644 --- a/arrow/src/array/array_boolean.rs +++ b/arrow/src/array/array_boolean.rs @@ -106,7 +106,7 @@ impl BooleanArray { } impl Array for BooleanArray { - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } diff --git a/arrow/src/array/array_dictionary.rs b/arrow/src/array/array_dictionary.rs index 05b1dd333519..cf847ef6fa5e 100644 --- a/arrow/src/array/array_dictionary.rs +++ b/arrow/src/array/array_dictionary.rs @@ -201,7 +201,7 @@ impl<'a, T: ArrowPrimitiveType + ArrowDictionaryKeyType> FromIterator<&'a str> } impl Array for DictionaryArray { - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } diff --git a/arrow/src/array/array_list.rs b/arrow/src/array/array_list.rs index 990ec8aae1c6..24c0e63480b6 100644 --- a/arrow/src/array/array_list.rs +++ b/arrow/src/array/array_list.rs @@ -253,7 +253,7 @@ impl GenericListArray { } impl Array for GenericListArray { - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } @@ -426,7 +426,7 @@ impl From for FixedSizeListArray { } impl Array for FixedSizeListArray { - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } diff --git a/arrow/src/array/array_primitive.rs b/arrow/src/array/array_primitive.rs index fa950a93fa96..e790a6a72e0d 100644 --- a/arrow/src/array/array_primitive.rs +++ b/arrow/src/array/array_primitive.rs @@ -143,7 +143,7 @@ impl PrimitiveArray { } impl Array for PrimitiveArray { - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } diff --git a/arrow/src/array/array_string.rs b/arrow/src/array/array_string.rs index ec703e28f5ac..301e38664b6f 100644 --- a/arrow/src/array/array_string.rs +++ b/arrow/src/array/array_string.rs @@ -281,7 +281,7 @@ impl fmt::Debug for GenericStringArray Array for GenericStringArray { - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } diff --git a/arrow/src/array/array_struct.rs b/arrow/src/array/array_struct.rs index 32c2985e1aa6..9735e17d2a79 100644 --- a/arrow/src/array/array_struct.rs +++ b/arrow/src/array/array_struct.rs @@ -186,7 +186,7 @@ impl TryFrom> for StructArray { } impl Array for StructArray { - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } diff --git a/arrow/src/array/array_union.rs b/arrow/src/array/array_union.rs index e369037244ac..ca15a9086d91 100644 --- a/arrow/src/array/array_union.rs +++ b/arrow/src/array/array_union.rs @@ -268,7 +268,7 @@ impl From for UnionArray { } impl Array for UnionArray { - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } diff --git a/arrow/src/array/builder.rs b/arrow/src/array/builder.rs index 66f2d818f728..f226df465cea 100644 --- a/arrow/src/array/builder.rs +++ b/arrow/src/array/builder.rs @@ -458,17 +458,17 @@ pub trait ArrayBuilder: Any + Send { /// This is most useful when one wants to call non-mutable APIs on a specific builder /// type. In this case, one can first cast this into a `Any`, and then use /// `downcast_ref` to get a reference on the specific builder. - fn as_any(&self) -> &Any; + fn as_any(&self) -> &dyn Any; /// Returns the builder as a mutable `Any` reference. /// /// This is most useful when one wants to call mutable APIs on a specific builder /// type. In this case, one can first cast this into a `Any`, and then use /// `downcast_mut` to get a reference on the specific builder. - fn as_any_mut(&mut self) -> &mut Any; + fn as_any_mut(&mut self) -> &mut dyn Any; /// Returns the boxed builder as a box of `Any`. - fn into_box_any(self: Box) -> Box; + fn into_box_any(self: Box) -> Box; } /// Array builder for fixed-width primitive types @@ -557,17 +557,17 @@ impl BooleanBuilder { impl ArrayBuilder for BooleanBuilder { /// Returns the builder as a non-mutable `Any` reference. - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } /// Returns the builder as a mutable `Any` reference. - fn as_any_mut(&mut self) -> &mut Any { + fn as_any_mut(&mut self) -> &mut dyn Any { self } /// Returns the boxed builder as a box of `Any`. - fn into_box_any(self: Box) -> Box { + fn into_box_any(self: Box) -> Box { self } @@ -598,17 +598,17 @@ pub struct PrimitiveBuilder { impl ArrayBuilder for PrimitiveBuilder { /// Returns the builder as a non-mutable `Any` reference. - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } /// Returns the builder as a mutable `Any` reference. - fn as_any_mut(&mut self) -> &mut Any { + fn as_any_mut(&mut self) -> &mut dyn Any { self } /// Returns the boxed builder as a box of `Any`. - fn into_box_any(self: Box) -> Box { + fn into_box_any(self: Box) -> Box { self } @@ -793,17 +793,17 @@ where T: 'static, { /// Returns the builder as a non-mutable `Any` reference. - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } /// Returns the builder as a mutable `Any` reference. - fn as_any_mut(&mut self) -> &mut Any { + fn as_any_mut(&mut self) -> &mut dyn Any { self } /// Returns the boxed builder as a box of `Any`. - fn into_box_any(self: Box) -> Box { + fn into_box_any(self: Box) -> Box { self } @@ -921,17 +921,17 @@ where T: 'static, { /// Returns the builder as a non-mutable `Any` reference. - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } /// Returns the builder as a mutable `Any` reference. - fn as_any_mut(&mut self) -> &mut Any { + fn as_any_mut(&mut self) -> &mut dyn Any { self } /// Returns the boxed builder as a box of `Any`. - fn into_box_any(self: Box) -> Box { + fn into_box_any(self: Box) -> Box { self } @@ -1044,17 +1044,17 @@ impl ArrayBuilder for GenericBinaryBuilder { /// Returns the builder as a non-mutable `Any` reference. - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } /// Returns the builder as a mutable `Any` reference. - fn as_any_mut(&mut self) -> &mut Any { + fn as_any_mut(&mut self) -> &mut dyn Any { self } /// Returns the boxed builder as a box of `Any`. - fn into_box_any(self: Box) -> Box { + fn into_box_any(self: Box) -> Box { self } @@ -1078,17 +1078,17 @@ impl ArrayBuilder for GenericStringBuilder { /// Returns the builder as a non-mutable `Any` reference. - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } /// Returns the builder as a mutable `Any` reference. - fn as_any_mut(&mut self) -> &mut Any { + fn as_any_mut(&mut self) -> &mut dyn Any { self } /// Returns the boxed builder as a box of `Any`. - fn into_box_any(self: Box) -> Box { + fn into_box_any(self: Box) -> Box { self } @@ -1111,17 +1111,17 @@ impl ArrayBuilder impl ArrayBuilder for FixedSizeBinaryBuilder { /// Returns the builder as a non-mutable `Any` reference. - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } /// Returns the builder as a mutable `Any` reference. - fn as_any_mut(&mut self) -> &mut Any { + fn as_any_mut(&mut self) -> &mut dyn Any { self } /// Returns the boxed builder as a box of `Any`. - fn into_box_any(self: Box) -> Box { + fn into_box_any(self: Box) -> Box { self } @@ -1143,17 +1143,17 @@ impl ArrayBuilder for FixedSizeBinaryBuilder { impl ArrayBuilder for DecimalBuilder { /// Returns the builder as a non-mutable `Any` reference. - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } /// Returns the builder as a mutable `Any` reference. - fn as_any_mut(&mut self) -> &mut Any { + fn as_any_mut(&mut self) -> &mut dyn Any { self } /// Returns the boxed builder as a box of `Any`. - fn into_box_any(self: Box) -> Box { + fn into_box_any(self: Box) -> Box { self } @@ -1381,7 +1381,7 @@ impl DecimalBuilder { /// properly called to maintain the consistency of the data structure. pub struct StructBuilder { fields: Vec, - field_builders: Vec>, + field_builders: Vec>, bitmap_builder: BooleanBufferBuilder, len: usize, } @@ -1421,7 +1421,7 @@ impl ArrayBuilder for StructBuilder { /// This is most useful when one wants to call non-mutable APIs on a specific builder /// type. In this case, one can first cast this into a `Any`, and then use /// `downcast_ref` to get a reference on the specific builder. - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } @@ -1430,12 +1430,12 @@ impl ArrayBuilder for StructBuilder { /// This is most useful when one wants to call mutable APIs on a specific builder /// type. In this case, one can first cast this into a `Any`, and then use /// `downcast_mut` to get a reference on the specific builder. - fn as_any_mut(&mut self) -> &mut Any { + fn as_any_mut(&mut self) -> &mut dyn Any { self } /// Returns the boxed builder as a box of `Any`. - fn into_box_any(self: Box) -> Box { + fn into_box_any(self: Box) -> Box { self } } @@ -1443,7 +1443,7 @@ impl ArrayBuilder for StructBuilder { /// Returns a builder with capacity `capacity` that corresponds to the datatype `DataType` /// This function is useful to construct arrays from an arbitrary vectors with known/expected /// schema. -pub fn make_builder(datatype: &DataType, capacity: usize) -> Box { +pub fn make_builder(datatype: &DataType, capacity: usize) -> Box { match datatype { DataType::Null => unimplemented!(), DataType::Boolean => Box::new(BooleanBuilder::new(capacity)), @@ -1517,7 +1517,7 @@ pub fn make_builder(datatype: &DataType, capacity: usize) -> Box { } impl StructBuilder { - pub fn new(fields: Vec, field_builders: Vec>) -> Self { + pub fn new(fields: Vec, field_builders: Vec>) -> Self { Self { fields, field_builders, @@ -1893,17 +1893,17 @@ where V: ArrowPrimitiveType, { /// Returns the builder as an non-mutable `Any` reference. - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } /// Returns the builder as an mutable `Any` reference. - fn as_any_mut(&mut self) -> &mut Any { + fn as_any_mut(&mut self) -> &mut dyn Any { self } /// Returns the boxed builder as a box of `Any`. - fn into_box_any(self: Box) -> Box { + fn into_box_any(self: Box) -> Box { self } @@ -2083,17 +2083,17 @@ where K: ArrowDictionaryKeyType, { /// Returns the builder as an non-mutable `Any` reference. - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } /// Returns the builder as an mutable `Any` reference. - fn as_any_mut(&mut self) -> &mut Any { + fn as_any_mut(&mut self) -> &mut dyn Any { self } /// Returns the boxed builder as a box of `Any`. - fn into_box_any(self: Box) -> Box { + fn into_box_any(self: Box) -> Box { self } diff --git a/arrow/src/array/null.rs b/arrow/src/array/null.rs index 6728a407fde0..521d472f6df5 100644 --- a/arrow/src/array/null.rs +++ b/arrow/src/array/null.rs @@ -58,7 +58,7 @@ impl NullArray { } impl Array for NullArray { - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { self } diff --git a/arrow/src/array/ord.rs b/arrow/src/array/ord.rs index 7fb4668d962b..323a882ecff6 100644 --- a/arrow/src/array/ord.rs +++ b/arrow/src/array/ord.rs @@ -39,7 +39,10 @@ fn cmp_nans_last(a: &T, b: &T) -> Ordering { } } -fn compare_primitives(left: &Array, right: &Array) -> DynComparator +fn compare_primitives( + left: &dyn Array, + right: &dyn Array, +) -> DynComparator where T::Native: Ord, { @@ -48,14 +51,17 @@ where Box::new(move |i, j| left.value(i).cmp(&right.value(j))) } -fn compare_boolean(left: &Array, right: &Array) -> DynComparator { +fn compare_boolean(left: &dyn Array, right: &dyn Array) -> DynComparator { let left: BooleanArray = BooleanArray::from(left.data().clone()); let right: BooleanArray = BooleanArray::from(right.data().clone()); Box::new(move |i, j| left.value(i).cmp(&right.value(j))) } -fn compare_float(left: &Array, right: &Array) -> DynComparator +fn compare_float( + left: &dyn Array, + right: &dyn Array, +) -> DynComparator where T::Native: Float, { @@ -64,7 +70,7 @@ where Box::new(move |i, j| cmp_nans_last(&left.value(i), &right.value(j))) } -fn compare_string(left: &Array, right: &Array) -> DynComparator +fn compare_string(left: &dyn Array, right: &dyn Array) -> DynComparator where T: StringOffsetSizeTrait, { @@ -74,7 +80,7 @@ where Box::new(move |i, j| left.value(i).cmp(&right.value(j))) } -fn compare_dict_string(left: &Array, right: &Array) -> DynComparator +fn compare_dict_string(left: &dyn Array, right: &dyn Array) -> DynComparator where T: ArrowDictionaryKeyType, { @@ -115,7 +121,7 @@ where /// ``` // This is a factory of comparisons. // The lifetime 'a enforces that we cannot use the closure beyond any of the array's lifetime. -pub fn build_compare(left: &Array, right: &Array) -> Result { +pub fn build_compare(left: &dyn Array, right: &dyn Array) -> Result { use DataType::*; use IntervalUnit::*; use TimeUnit::*; diff --git a/arrow/src/array/transform/mod.rs b/arrow/src/array/transform/mod.rs index 0194b9387c47..69092c1af55d 100644 --- a/arrow/src/array/transform/mod.rs +++ b/arrow/src/array/transform/mod.rs @@ -38,12 +38,12 @@ mod structure; mod utils; mod variable_size; -type ExtendNullBits<'a> = Box; +type ExtendNullBits<'a> = Box; // function that extends `[start..start+len]` to the mutable array. -// this is dynamic because different data_types influence how buffers and childs are extended. -type Extend<'a> = Box; +// this is dynamic because different data_types influence how buffers and children are extended. +type Extend<'a> = Box; -type ExtendNulls = Box ()>; +type ExtendNulls = Box; /// A mutable [ArrayData] that knows how to freeze itself into an [ArrayData]. /// This is just a data container. diff --git a/arrow/src/compute/kernels/boolean.rs b/arrow/src/compute/kernels/boolean.rs index c9c0bc3545f6..bab5f0fbdd48 100644 --- a/arrow/src/compute/kernels/boolean.rs +++ b/arrow/src/compute/kernels/boolean.rs @@ -407,7 +407,7 @@ pub fn not(left: &BooleanArray) -> Result { /// # Ok(()) /// # } /// ``` -pub fn is_null(input: &Array) -> Result { +pub fn is_null(input: &dyn Array) -> Result { let len = input.len(); let output = match input.data_ref().null_buffer() { @@ -439,7 +439,7 @@ pub fn is_null(input: &Array) -> Result { /// # Ok(()) /// # } /// ``` -pub fn is_not_null(input: &Array) -> Result { +pub fn is_not_null(input: &dyn Array) -> Result { let len = input.len(); let output = match input.data_ref().null_buffer() { diff --git a/arrow/src/compute/kernels/concat.rs b/arrow/src/compute/kernels/concat.rs index 5526432f8d8a..303c919e0c31 100644 --- a/arrow/src/compute/kernels/concat.rs +++ b/arrow/src/compute/kernels/concat.rs @@ -52,7 +52,7 @@ fn compute_str_values_length( } /// Concatenate multiple [Array] of the same type into a single [ArrayRef]. -pub fn concat(arrays: &[&Array]) -> Result { +pub fn concat(arrays: &[&dyn Array]) -> Result { if arrays.is_empty() { return Err(ArrowError::ComputeError( "concat requires input of at least one array".to_string(), diff --git a/arrow/src/compute/kernels/filter.rs b/arrow/src/compute/kernels/filter.rs index 65d016d1e688..4a5cce77101a 100644 --- a/arrow/src/compute/kernels/filter.rs +++ b/arrow/src/compute/kernels/filter.rs @@ -25,7 +25,7 @@ use crate::{array::*, util::bit_chunk_iterator::BitChunkIterator}; use std::iter::Enumerate; /// Function that can filter arbitrary arrays -pub type Filter<'a> = Box ArrayData + 'a>; +pub type Filter<'a> = Box ArrayData + 'a>; /// Internal state of [SlicesIterator] #[derive(Debug, PartialEq)] @@ -245,7 +245,7 @@ pub fn prep_null_mask_filter(filter: &BooleanArray) -> BooleanArray { /// # Ok(()) /// # } /// ``` -pub fn filter(array: &Array, predicate: &BooleanArray) -> Result { +pub fn filter(array: &dyn Array, predicate: &BooleanArray) -> Result { if predicate.null_count() > 0 { // this greatly simplifies subsequent filtering code // now we only have a boolean mask to deal with diff --git a/arrow/src/compute/kernels/length.rs b/arrow/src/compute/kernels/length.rs index 1f9b6e5f3229..ad2bc1692a8e 100644 --- a/arrow/src/compute/kernels/length.rs +++ b/arrow/src/compute/kernels/length.rs @@ -101,7 +101,7 @@ where /// * this only accepts StringArray/Utf8 and LargeString/LargeUtf8 /// * length of null is null. /// * length is in number of bytes -pub fn length(array: &Array) -> Result { +pub fn length(array: &dyn Array) -> Result { match array.data_type() { DataType::Utf8 => Ok(octet_length::(array)), DataType::LargeUtf8 => Ok(octet_length::(array)), @@ -117,7 +117,7 @@ pub fn length(array: &Array) -> Result { /// * this only accepts StringArray/Utf8 and LargeString/LargeUtf8 /// * bit_length of null is null. /// * bit_length is in number of bits -pub fn bit_length(array: &Array) -> Result { +pub fn bit_length(array: &dyn Array) -> Result { match array.data_type() { DataType::Utf8 => Ok(bit_length_impl::(array)), DataType::LargeUtf8 => Ok(bit_length_impl::(array)), diff --git a/arrow/src/compute/kernels/sort.rs b/arrow/src/compute/kernels/sort.rs index c1add677fd63..008661ec0104 100644 --- a/arrow/src/compute/kernels/sort.rs +++ b/arrow/src/compute/kernels/sort.rs @@ -765,7 +765,7 @@ where } /// Compare two `Array`s based on the ordering defined in [ord](crate::array::ord). -fn cmp_array(a: &Array, b: &Array) -> Ordering { +fn cmp_array(a: &dyn Array, b: &dyn Array) -> Ordering { let cmp_op = build_compare(a, b).unwrap(); let length = a.len().max(b.len()); diff --git a/arrow/src/compute/kernels/substring.rs b/arrow/src/compute/kernels/substring.rs index d9956b896876..d4ea6616c648 100644 --- a/arrow/src/compute/kernels/substring.rs +++ b/arrow/src/compute/kernels/substring.rs @@ -92,7 +92,11 @@ fn generic_substring( /// Returns an ArrayRef with a substring starting from `start` and with optional length `length` of each of the elements in `array`. /// `start` can be negative, in which case the start counts from the end of the string. /// this function errors when the passed array is not a \[Large\]String array. -pub fn substring(array: &Array, start: i64, length: &Option) -> Result { +pub fn substring( + array: &dyn Array, + start: i64, + length: &Option, +) -> Result { match array.data_type() { DataType::LargeUtf8 => generic_substring( array diff --git a/arrow/src/compute/kernels/take.rs b/arrow/src/compute/kernels/take.rs index f36e29e8c5f7..f04208a689e6 100644 --- a/arrow/src/compute/kernels/take.rs +++ b/arrow/src/compute/kernels/take.rs @@ -77,7 +77,7 @@ macro_rules! downcast_dict_take { /// # } /// ``` pub fn take( - values: &Array, + values: &dyn Array, indices: &PrimitiveArray, options: Option, ) -> Result @@ -89,7 +89,7 @@ where } fn take_impl( - values: &Array, + values: &dyn Array, indices: &PrimitiveArray, options: Option, ) -> Result diff --git a/arrow/src/compute/kernels/window.rs b/arrow/src/compute/kernels/window.rs index a537cbc76e47..b354b4aa3bd8 100644 --- a/arrow/src/compute/kernels/window.rs +++ b/arrow/src/compute/kernels/window.rs @@ -56,7 +56,7 @@ use num::{abs, clamp}; /// let expected: Int32Array = vec![None, None, None].into(); /// assert_eq!(res.as_ref(), &expected); /// ``` -pub fn shift(array: &Array, offset: i64) -> Result { +pub fn shift(array: &dyn Array, offset: i64) -> Result { let value_len = array.len() as i64; if offset == 0 { Ok(make_array(array.data_ref().clone())) diff --git a/arrow/src/record_batch.rs b/arrow/src/record_batch.rs index ebd012a4a1c7..bb4b301c1f5a 100644 --- a/arrow/src/record_batch.rs +++ b/arrow/src/record_batch.rs @@ -40,7 +40,7 @@ use crate::error::{ArrowError, Result}; #[derive(Clone, Debug)] pub struct RecordBatch { schema: SchemaRef, - columns: Vec>, + columns: Vec>, } impl RecordBatch {