diff --git a/vortex-alp/src/serde.rs b/vortex-alp/src/serde.rs index 58ef3e090e..732f6bbd6b 100644 --- a/vortex-alp/src/serde.rs +++ b/vortex-alp/src/serde.rs @@ -72,7 +72,7 @@ mod test { #[test] fn roundtrip() { - let arr = alp_encode(&PrimitiveArray::from_vec(vec![ + let arr = alp_encode(&PrimitiveArray::from(vec![ 0.00001f64, 0.0004f64, 1000000.0f64, diff --git a/vortex-array/src/array/bool/mod.rs b/vortex-array/src/array/bool/mod.rs index 8ab1fc171b..65cd19be96 100644 --- a/vortex-array/src/array/bool/mod.rs +++ b/vortex-array/src/array/bool/mod.rs @@ -189,6 +189,12 @@ impl From> for BoolArray { } } +impl From> for ArrayRef { + fn from(values: Vec) -> Self { + BoolArray::from(values).boxed() + } +} + impl FromIterator> for BoolArray { fn from_iter>>(iter: I) -> Self { let iter = iter.into_iter(); diff --git a/vortex-array/src/array/primitive/compute/cast.rs b/vortex-array/src/array/primitive/compute/cast.rs index 397f009421..2e5eb32947 100644 --- a/vortex-array/src/array/primitive/compute/cast.rs +++ b/vortex-array/src/array/primitive/compute/cast.rs @@ -44,26 +44,26 @@ mod test { #[test] fn cast_u32_u8() { - let arr = PrimitiveArray::from_vec(vec![0u32, 10, 200]); + let arr = PrimitiveArray::from(vec![0u32, 10, 200]); let u8arr = compute::cast::cast_primitive(&arr, &PType::U8).unwrap(); assert_eq!(u8arr.typed_data::(), vec![0u8, 10, 200]); } #[test] fn cast_u32_f32() { - let arr = PrimitiveArray::from_vec(vec![0u32, 10, 200]); + let arr = PrimitiveArray::from(vec![0u32, 10, 200]); let u8arr = compute::cast::cast_primitive(&arr, &PType::F32).unwrap(); assert_eq!(u8arr.typed_data::(), vec![0.0f32, 10., 200.]); } #[test] fn cast_i32_u32() { - let arr = PrimitiveArray::from_vec(vec![-1i32]); + let arr = PrimitiveArray::from(vec![-1i32]); assert_eq!( compute::cast::cast_primitive(&arr, &PType::U32) .err() .unwrap(), - VortexError::ComputeError("Failed to cast -1 to U32".into(),) + VortexError::ComputeError("Failed to cast -1 to U32".into()) ) } } diff --git a/vortex-array/src/array/primitive/mod.rs b/vortex-array/src/array/primitive/mod.rs index 9716fc5fa3..ee2ae84606 100644 --- a/vortex-array/src/array/primitive/mod.rs +++ b/vortex-array/src/array/primitive/mod.rs @@ -13,7 +13,6 @@ use arrow::buffer::{Buffer, NullBuffer, ScalarBuffer}; use linkme::distributed_slice; use log::debug; -use crate::array::bool::BoolArray; use crate::array::{ check_slice_bounds, check_validity_buffer, Array, ArrayRef, ArrowIterator, Encoding, EncodingId, EncodingRef, ENCODINGS, @@ -70,11 +69,6 @@ impl PrimitiveArray { }) } - #[inline] - pub fn from_vec(values: Vec) -> Self { - Self::from_nullable(values, None) - } - /// Allocate buffer from allocator-api2 vector. This would be easier when arrow gets https://github.com/apache/arrow-rs/issues/3960 #[inline] pub fn from_vec_in( @@ -256,18 +250,15 @@ impl Encoding for PrimitiveEncoding { } } -/// Wrapper struct to create primitive array from Vec>, this would conflict with Vec -pub struct NullableVec(Vec>); - -impl From> for ArrayRef { - fn from(value: NullableVec) -> Self { - PrimitiveArray::from_iter(value.0).boxed() +impl From> for ArrayRef { + fn from(values: Vec) -> Self { + PrimitiveArray::from(values).boxed() } } -impl From> for ArrayRef { +impl From> for PrimitiveArray { fn from(values: Vec) -> Self { - PrimitiveArray::from_vec(values).boxed() + Self::from_nullable(values, None) } } @@ -289,11 +280,14 @@ impl FromIterator> for PrimitiveArray { }) .collect::>(); - if validity.is_empty() { - PrimitiveArray::from_vec(values) - } else { - PrimitiveArray::from_nullable(values, Some(BoolArray::from(validity).boxed())) - } + PrimitiveArray::from_nullable( + values, + if !validity.is_empty() { + Some(validity.into()) + } else { + None + }, + ) } } @@ -315,7 +309,7 @@ mod test { #[test] fn from_arrow() { - let arr = PrimitiveArray::from_vec::(vec![1, 2, 3]); + let arr = PrimitiveArray::from(vec![1, 2, 3]); assert_eq!(arr.len(), 3); assert_eq!(arr.ptype, PType::I32); assert_eq!( @@ -331,7 +325,7 @@ mod test { #[test] fn slice() { - let arr = PrimitiveArray::from_vec(vec![1, 2, 3, 4, 5]) + let arr = PrimitiveArray::from(vec![1, 2, 3, 4, 5]) .slice(1, 4) .unwrap(); assert_eq!(arr.len(), 3); diff --git a/vortex-array/src/array/primitive/stats.rs b/vortex-array/src/array/primitive/stats.rs index 20fc036f22..80ee311f83 100644 --- a/vortex-array/src/array/primitive/stats.rs +++ b/vortex-array/src/array/primitive/stats.rs @@ -185,7 +185,7 @@ mod test { #[test] fn stats() { - let arr = PrimitiveArray::from_vec(vec![1, 2, 3, 4, 5]); + let arr = PrimitiveArray::from(vec![1, 2, 3, 4, 5]); let min: i32 = arr.stats().get_or_compute_as(&Stat::Min).unwrap(); let max: i32 = arr.stats().get_or_compute_as(&Stat::Max).unwrap(); let is_sorted: bool = arr.stats().get_or_compute_as(&Stat::IsSorted).unwrap(); @@ -217,7 +217,7 @@ mod test { #[test] fn stats_u8() { - let arr = PrimitiveArray::from_vec(vec![1u8, 2, 3, 4, 5]); + let arr = PrimitiveArray::from(vec![1u8, 2, 3, 4, 5]); let min: u8 = arr.stats().get_or_compute_as(&Stat::Min).unwrap(); let max: u8 = arr.stats().get_or_compute_as(&Stat::Max).unwrap(); assert_eq!(min, 1); diff --git a/vortex-array/src/array/sparse/serde.rs b/vortex-array/src/array/sparse/serde.rs index 17270c37e8..85fe6f715b 100644 --- a/vortex-array/src/array/sparse/serde.rs +++ b/vortex-array/src/array/sparse/serde.rs @@ -39,7 +39,7 @@ mod test { #[test] fn roundtrip() { let arr = SparseArray::new( - PrimitiveArray::from_vec(vec![7u64, 37, 71, 97]).boxed(), + vec![7u64, 37, 71, 97].into(), PrimitiveArray::from_iter(vec![Some(0), None, Some(2), Some(42)]).boxed(), 100, ); diff --git a/vortex-array/src/array/struct_/serde.rs b/vortex-array/src/array/struct_/serde.rs index ddcbbd50c6..17e0307ad3 100644 --- a/vortex-array/src/array/struct_/serde.rs +++ b/vortex-array/src/array/struct_/serde.rs @@ -52,7 +52,7 @@ mod test { Arc::new("nullable".to_string()), ], vec![ - PrimitiveArray::from_vec(vec![7u8, 37, 71, 97]).boxed(), + vec![7u8, 37, 71, 97].into(), PrimitiveArray::from_iter(vec![Some(0), None, Some(2), Some(42)]).boxed(), ], ); diff --git a/vortex-array/src/array/typed/serde.rs b/vortex-array/src/array/typed/serde.rs index 60db7c33e7..6643925961 100644 --- a/vortex-array/src/array/typed/serde.rs +++ b/vortex-array/src/array/typed/serde.rs @@ -21,7 +21,6 @@ impl EncodingSerde for TypedEncoding { #[cfg(test)] mod test { use crate::array::downcast::DowncastArrayBuiltin; - use crate::array::primitive::PrimitiveArray; use crate::array::typed::TypedArray; use crate::array::Array; use crate::dtype::{DType, IntWidth, Nullability, Signedness}; @@ -30,7 +29,7 @@ mod test { #[test] fn roundtrip() { let arr = TypedArray::new( - PrimitiveArray::from_vec(vec![7u8, 37, 71, 97]).boxed(), + vec![7u8, 37, 71, 97].into(), DType::Int(IntWidth::_64, Signedness::Signed, Nullability::NonNullable), ); diff --git a/vortex-array/src/array/varbin/mod.rs b/vortex-array/src/array/varbin/mod.rs index c6dd68100f..e2e60c29d4 100644 --- a/vortex-array/src/array/varbin/mod.rs +++ b/vortex-array/src/array/varbin/mod.rs @@ -136,8 +136,8 @@ impl VarBinArray { } VarBinArray::new( - PrimitiveArray::from_vec(offsets).boxed(), - PrimitiveArray::from_vec(values).boxed(), + PrimitiveArray::from(offsets).boxed(), + PrimitiveArray::from(values).boxed(), dtype, None, ) @@ -165,8 +165,8 @@ impl VarBinArray { } } - let offsets_ref = PrimitiveArray::from_vec(offsets).boxed(); - let bytes_ref = PrimitiveArray::from_vec(bytes).boxed(); + let offsets_ref = PrimitiveArray::from(offsets).boxed(); + let bytes_ref = PrimitiveArray::from(bytes).boxed(); if validity.is_empty() { VarBinArray::new(offsets_ref, bytes_ref, dtype, None) } else { @@ -387,12 +387,12 @@ mod test { use crate::dtype::{DType, Nullability}; fn binary_array() -> VarBinArray { - let values = PrimitiveArray::from_vec( + let values = PrimitiveArray::from( "hello worldhello world this is a long string" .as_bytes() .to_vec(), ); - let offsets = PrimitiveArray::from_vec(vec![0, 11, 44]); + let offsets = PrimitiveArray::from(vec![0, 11, 44]); VarBinArray::new( offsets.boxed(), diff --git a/vortex-array/src/array/varbin/stats.rs b/vortex-array/src/array/varbin/stats.rs index 3cc9c70baf..f4cecd03a2 100644 --- a/vortex-array/src/array/varbin/stats.rs +++ b/vortex-array/src/array/varbin/stats.rs @@ -86,12 +86,12 @@ mod test { use crate::stats::Stat; fn array(dtype: DType) -> VarBinArray { - let values = PrimitiveArray::from_vec( + let values = PrimitiveArray::from( "hello worldhello world this is a long string" .as_bytes() .to_vec(), ); - let offsets = PrimitiveArray::from_vec(vec![0, 11, 44]); + let offsets = PrimitiveArray::from(vec![0, 11, 44]); VarBinArray::new(offsets.boxed(), values.boxed(), dtype, None) } diff --git a/vortex-array/src/array/varbinview/mod.rs b/vortex-array/src/array/varbinview/mod.rs index fc90e88825..fd5ad7a6c5 100644 --- a/vortex-array/src/array/varbinview/mod.rs +++ b/vortex-array/src/array/varbinview/mod.rs @@ -360,8 +360,7 @@ mod test { use super::*; fn binary_array() -> VarBinViewArray { - let values = - PrimitiveArray::from_vec("hello world this is a long string".as_bytes().to_vec()); + let values = PrimitiveArray::from("hello world this is a long string".as_bytes().to_vec()); let view1 = BinaryView { inlined: Inlined::new("hello world"), }; @@ -373,7 +372,7 @@ mod test { offset: 0, }, }; - let view_arr = PrimitiveArray::from_vec( + let view_arr = PrimitiveArray::from( vec![view1.to_le_bytes(), view2.to_le_bytes()] .into_iter() .flatten() diff --git a/vortex-array/src/array/varbinview/serde.rs b/vortex-array/src/array/varbinview/serde.rs index 3fb5910f7a..6950787de8 100644 --- a/vortex-array/src/array/varbinview/serde.rs +++ b/vortex-array/src/array/varbinview/serde.rs @@ -45,8 +45,7 @@ mod test { use crate::serde::test::roundtrip_array; fn binary_array() -> VarBinViewArray { - let values = - PrimitiveArray::from_vec("hello world this is a long string".as_bytes().to_vec()); + let values = PrimitiveArray::from("hello world this is a long string".as_bytes().to_vec()); let view1 = BinaryView { inlined: Inlined::new("hello world"), }; @@ -58,7 +57,7 @@ mod test { offset: 0, }, }; - let view_arr = PrimitiveArray::from_vec( + let view_arr = PrimitiveArray::from( vec![view1.to_le_bytes(), view2.to_le_bytes()] .into_iter() .flatten() diff --git a/vortex-array/src/compute/as_contiguous.rs b/vortex-array/src/compute/as_contiguous.rs index 37903e7594..88a9f68b8c 100644 --- a/vortex-array/src/compute/as_contiguous.rs +++ b/vortex-array/src/compute/as_contiguous.rs @@ -43,7 +43,7 @@ fn bool_as_contiguous(arrays: Vec<&BoolArray>) -> VortexResult { .map(|a| { a.validity() .clone_optional() - .unwrap_or_else(|| BoolArray::from(vec![true; a.len()]).boxed()) + .unwrap_or_else(|| vec![true; a.len()].into()) }) .collect(), )?) @@ -77,7 +77,7 @@ fn primitive_as_contiguous(arrays: Vec<&PrimitiveArray>) -> VortexResult ArrayFormatter<'a, 'b> { #[cfg(test)] mod test { - use crate::array::primitive::PrimitiveArray; - use crate::array::Array; + use crate::array::ArrayRef; #[test] fn primitive_array() { - let arr = PrimitiveArray::from_vec((0..100).collect()).boxed(); + let arr: ArrayRef = (0..100).collect::>().into(); assert_eq!(format!("{}", arr), "vortex.primitive(signed_int(32)), len=100, nbytes=400 B (100.00%)\n[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]...\n") } } diff --git a/vortex-dict/src/compress.rs b/vortex-dict/src/compress.rs index 5b040228c1..ce6ef03372 100644 --- a/vortex-dict/src/compress.rs +++ b/vortex-dict/src/compress.rs @@ -131,7 +131,7 @@ fn dict_encode_typed_primitive< ( PrimitiveArray::from_nullable(codes, array.validity().clone_optional()), - PrimitiveArray::from_vec(values), + PrimitiveArray::from(values), ) } @@ -262,8 +262,8 @@ where ( PrimitiveArray::from_nullable(codes, validity.clone_optional()), VarBinArray::new( - PrimitiveArray::from_vec(offsets).boxed(), - PrimitiveArray::from_vec(bytes).boxed(), + PrimitiveArray::from(offsets).boxed(), + PrimitiveArray::from(bytes).boxed(), dtype, None, ), @@ -280,7 +280,7 @@ mod test { #[test] fn encode_primitive() { - let arr = PrimitiveArray::from_vec(vec![1, 1, 3, 3, 3]); + let arr = PrimitiveArray::from(vec![1, 1, 3, 3, 3]); let (codes, values) = dict_encode_typed_primitive::(&arr); assert_eq!(codes.buffer().typed_data::(), &[0, 0, 1, 1, 1]); assert_eq!(values.buffer().typed_data::(), &[1, 3]); diff --git a/vortex-dict/src/serde.rs b/vortex-dict/src/serde.rs index 59ff2aec3d..9c09cd5e03 100644 --- a/vortex-dict/src/serde.rs +++ b/vortex-dict/src/serde.rs @@ -28,7 +28,6 @@ mod test { use std::io; use vortex::array::downcast::DowncastArrayBuiltin; - use vortex::array::primitive::PrimitiveArray; use vortex::array::{Array, ArrayRef}; use vortex::serde::{ReadCtx, WriteCtx}; @@ -47,8 +46,8 @@ mod test { #[test] fn roundtrip() { let arr = DictArray::new( - PrimitiveArray::from_vec(vec![0u8, 0, 1, 2, 3]).boxed(), - PrimitiveArray::from_vec(vec![-7i64, -13, 17, 23]).boxed(), + vec![0u8, 0, 1, 2, 3].into(), + vec![-7i64, -13, 17, 23].into(), ); let read_arr = roundtrip_array(arr.as_ref()).unwrap(); diff --git a/vortex-fastlanes/src/bitpacking/compress.rs b/vortex-fastlanes/src/bitpacking/compress.rs index d287bb3849..b3e75ddd76 100644 --- a/vortex-fastlanes/src/bitpacking/compress.rs +++ b/vortex-fastlanes/src/bitpacking/compress.rs @@ -77,7 +77,7 @@ fn bitpacked_compressor( // If we pack into zero bits, then we have an empty byte array. let packed = if bit_width == 0 { - PrimitiveArray::from_vec(Vec::::new()).boxed() + PrimitiveArray::from(Vec::::new()).boxed() } else { bitpack(parray, bit_width) }; @@ -118,7 +118,7 @@ fn bitpack(parray: &PrimitiveArray, bit_width: usize) -> ArrayRef { I64 | U64 => bitpack_primitive(parray.buffer().typed_data::(), bit_width), _ => panic!("Unsupported ptype {:?}", parray.ptype()), }; - PrimitiveArray::from_vec(bytes).boxed() + PrimitiveArray::from(bytes).boxed() } fn bitpack_primitive(array: &[T], bit_width: usize) -> Vec { @@ -160,8 +160,8 @@ fn bitpack_patches( } let len = indices.len(); SparseArray::new( - PrimitiveArray::from_vec(indices).boxed(), - PrimitiveArray::from_vec(values).boxed(), + PrimitiveArray::from(indices).boxed(), + PrimitiveArray::from(values).boxed(), len, ).boxed() }) @@ -224,12 +224,10 @@ mod test { ); let ctx = CompressCtx::new(&cfg); - let compressed = ctx - .compress( - &PrimitiveArray::from_vec(Vec::from_iter((0..10_000).map(|i| (i % 63) as u8))), - None, - ) - .unwrap(); + let compressed = ctx.compress( + &PrimitiveArray::from(Vec::from_iter((0..10_000).map(|i| (i % 63) as u8))), + None, + )?; assert_eq!(compressed.encoding().id(), BitPackedEncoding.id()); let bp = compressed .as_any() diff --git a/vortex-fastlanes/src/for/compress.rs b/vortex-fastlanes/src/for/compress.rs index 0ba25c3ea7..397f464d39 100644 --- a/vortex-fastlanes/src/for/compress.rs +++ b/vortex-fastlanes/src/for/compress.rs @@ -54,7 +54,7 @@ fn for_compressor( // TODO(ngates): cast to unsigned // .map(|v| v as parray.ptype().to_unsigned()::T) .collect_vec(); - PrimitiveArray::from_vec(values) + PrimitiveArray::from(values) }); // TODO(ngates): remove FoR as a potential encoding from the ctx @@ -91,7 +91,7 @@ mod test { let ctx = CompressCtx::new(&cfg); // Create a range offset by a million - let array = PrimitiveArray::from_vec((0u32..10_000).map(|v| v + 1_000_000).collect_vec()); + let array = PrimitiveArray::from((0u32..10_000).map(|v| v + 1_000_000).collect_vec()); let compressed = ctx.compress(&array, None).unwrap(); assert_eq!(compressed.encoding().id(), FoREncoding.id()); diff --git a/vortex-fastlanes/src/for/serde.rs b/vortex-fastlanes/src/for/serde.rs index d91565230b..7a03b425c5 100644 --- a/vortex-fastlanes/src/for/serde.rs +++ b/vortex-fastlanes/src/for/serde.rs @@ -24,7 +24,6 @@ impl EncodingSerde for FoREncoding { mod test { use crate::FoRArray; use std::io; - use vortex::array::primitive::PrimitiveArray; use vortex::array::{Array, ArrayRef}; use vortex::scalar::ScalarRef; use vortex::serde::{ReadCtx, WriteCtx}; @@ -41,7 +40,7 @@ mod test { #[test] fn roundtrip() { let arr = FoRArray::try_new( - PrimitiveArray::from_vec(vec![-7i64, -13, 17, 23]).boxed(), + vec![-7i64, -13, 17, 23].into(), >::into(-7i64), ) .unwrap(); diff --git a/vortex-ffor/src/serde.rs b/vortex-ffor/src/serde.rs index cc55dc5889..eeebbca2e4 100644 --- a/vortex-ffor/src/serde.rs +++ b/vortex-ffor/src/serde.rs @@ -71,7 +71,7 @@ mod test { #[test] fn roundtrip() { - let arr = ffor_encode(&PrimitiveArray::from_vec(vec![-7i64, -13, 17, 23])); + let arr = ffor_encode(&PrimitiveArray::from(vec![-7i64, -13, 17, 23])); let read_arr = roundtrip_array(arr.as_ref()).unwrap(); assert_eq!( diff --git a/vortex-ree/src/serde.rs b/vortex-ree/src/serde.rs index 9134ee9060..822e549072 100644 --- a/vortex-ree/src/serde.rs +++ b/vortex-ree/src/serde.rs @@ -38,7 +38,6 @@ mod test { use std::io; use vortex::array::downcast::DowncastArrayBuiltin; - use vortex::array::primitive::PrimitiveArray; use vortex::array::{Array, ArrayRef}; use vortex::serde::{ReadCtx, WriteCtx}; @@ -57,8 +56,8 @@ mod test { #[test] fn roundtrip() { let arr = REEArray::new( - PrimitiveArray::from_vec(vec![0u8, 9, 20, 32, 49]).boxed(), - PrimitiveArray::from_vec(vec![-7i64, -13, 17, 23]).boxed(), + vec![0u8, 9, 20, 32, 49].into(), + vec![-7i64, -13, 17, 23].into(), None, 49, ); diff --git a/vortex-roaring/src/integer/mod.rs b/vortex-roaring/src/integer/mod.rs index a2efcc4d27..eab6dfdb08 100644 --- a/vortex-roaring/src/integer/mod.rs +++ b/vortex-roaring/src/integer/mod.rs @@ -156,7 +156,6 @@ impl Encoding for RoaringIntEncoding { #[cfg(test)] mod test { use vortex::array::primitive::PrimitiveArray; - use vortex::array::Array; use vortex::compute::scalar_at::scalar_at; use vortex::error::VortexResult; @@ -164,8 +163,8 @@ mod test { #[test] pub fn test_scalar_at() -> VortexResult<()> { - let ints: &dyn Array = &PrimitiveArray::from_vec::(vec![2, 12, 22, 32]); - let array = RoaringIntArray::encode(ints)?; + let ints = PrimitiveArray::from(vec![2u32, 12, 22, 32]); + let array = RoaringIntArray::encode(ints.as_ref())?; assert_eq!(scalar_at(array.as_ref(), 0), Ok(2u32.into())); assert_eq!(scalar_at(array.as_ref(), 1), Ok(12u32.into())); diff --git a/vortex-zigzag/src/serde.rs b/vortex-zigzag/src/serde.rs index 2af02e2f49..f86352889e 100644 --- a/vortex-zigzag/src/serde.rs +++ b/vortex-zigzag/src/serde.rs @@ -52,7 +52,7 @@ mod test { #[test] fn roundtrip() { - let arr = zigzag_encode(&PrimitiveArray::from_vec(vec![-7i64, -13, 17, 23])).unwrap(); + let arr = zigzag_encode(&PrimitiveArray::from(vec![-7i64, -13, 17, 23])).unwrap(); let read_arr = roundtrip_array(arr.as_ref()).unwrap(); let read_zigzag = read_arr.as_zigzag();