Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
viirya committed Nov 15, 2022
1 parent a3ad2c5 commit 7e25463
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
9 changes: 6 additions & 3 deletions arrow-array/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ impl<'a, T: Array> Array for &'a T {
}
}

/*
/// A kind of `Array` which can be downcasted by `downcast_array`.
pub(crate) trait SizedArray: AsDynAny + Array {}
Expand All @@ -393,6 +394,7 @@ pub(crate) fn downcast_array<T: Send + Sync + 'static>(
) -> Option<Arc<T>> {
AsDynAny::as_dyn_any(array).downcast().ok()
}
*/

/// A generic trait for accessing the values of an [`Array`]
///
Expand Down Expand Up @@ -884,6 +886,7 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::cast::downcast_array;
use arrow_schema::Field;

#[test]
Expand Down Expand Up @@ -1140,10 +1143,10 @@ mod tests {
fn test_downcast_array() {
let array: Int32Array = vec![1, 2, 3].into_iter().map(Some).collect();

let boxed: Arc<dyn SizedArray> = Arc::new(array);
let array: Arc<Int32Array> = downcast_array(boxed).unwrap();
let boxed: ArrayRef = Arc::new(array);
let array: Int32Array = downcast_array(&boxed);

let expected: Int32Array = vec![1, 2, 3].into_iter().map(Some).collect();
assert_eq!(&array, &Arc::new(expected));
assert_eq!(array, expected);
}
}
15 changes: 6 additions & 9 deletions arrow-array/src/array/primitive_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// specific language governing permissions and limitations
// under the License.

use crate::array::SizedArray;
use crate::builder::{BooleanBufferBuilder, BufferBuilder, PrimitiveBuilder};
use crate::iterator::PrimitiveIter;
use crate::raw_pointer::RawPtrBox;
Expand Down Expand Up @@ -565,9 +564,6 @@ impl<T: ArrowPrimitiveType> Array for PrimitiveArray<T> {
}
}

/// Makes `PrimitiveArray<T>` can be "downcast_array".
impl<T: ArrowPrimitiveType> SizedArray for PrimitiveArray<T> {}

impl<'a, T: ArrowPrimitiveType> ArrayAccessor for &'a PrimitiveArray<T> {
type Item = T::Native;

Expand Down Expand Up @@ -1075,7 +1071,8 @@ impl<T: DecimalType + ArrowPrimitiveType> PrimitiveArray<T> {
mod tests {
use super::*;
use crate::builder::{Decimal128Builder, Decimal256Builder};
use crate::{downcast_array, BooleanArray};
use crate::cast::downcast_array;
use crate::{ArrayRef, BooleanArray};
use std::sync::Arc;

#[test]
Expand Down Expand Up @@ -1984,10 +1981,10 @@ mod tests {
fn test_into_builder() {
let array: Int32Array = vec![1, 2, 3].into_iter().map(Some).collect();

let boxed: Arc<dyn SizedArray> = Arc::new(array);
let array: Arc<Int32Array> = downcast_array(boxed).unwrap();
let boxed: ArrayRef = Arc::new(array);
let col: Int32Array = downcast_array(&boxed);
drop(boxed);

let col: Int32Array = Arc::try_unwrap(array).unwrap();
let mut builder = col.into_builder().unwrap();

builder.append_value(4);
Expand All @@ -2004,7 +2001,7 @@ mod tests {
fn test_into_builder_cloned_array() {
let array: Int32Array = vec![1, 2, 3].into_iter().map(Some).collect();

let boxed: Arc<dyn SizedArray> = Arc::new(array);
let boxed: ArrayRef = Arc::new(array);

let col: Int32Array = PrimitiveArray::<Int32Type>::from(boxed.data().clone());
let err = col.into_builder();
Expand Down

0 comments on commit 7e25463

Please sign in to comment.