Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion vortex-array/src/arrays/chunked/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl Array<Chunked> {

/// Constructs a new `ChunkedArray`.
pub fn try_new(chunks: impl IntoIterator<Item = ArrayRef>, dtype: DType) -> VortexResult<Self> {
Array::try_from_parts(Self::parts_from_chunks::<true>(chunks, dtype)?)
Self::try_from_chunked_parts(Self::parts_from_chunks::<true>(chunks, dtype)?)
}

pub fn rechunk(
Expand Down Expand Up @@ -278,6 +278,26 @@ impl Array<Chunked> {
pub unsafe fn new_unchecked(chunks: impl IntoIterator<Item = ArrayRef>, dtype: DType) -> Self {
let parts = Self::parts_from_chunks::<false>(chunks, dtype)
.vortex_expect("unchecked chunked construction cannot fail");
unsafe { Self::from_chunked_parts_unchecked(parts) }
}

/// Creates the array from parts after validation.
///
/// The generic constructors call this function. It is not generic, so crates that call those
/// constructors do not each compile the `Chunked` array vtable.
fn try_from_chunked_parts(parts: ArrayParts<Chunked>) -> VortexResult<Self> {
Array::try_from_parts(parts)
}

/// Creates the array from parts without validation.
///
/// The generic constructors call this function. It is not generic, so crates that call those
/// constructors do not each compile the `Chunked` array vtable.
///
/// # Safety
///
/// The parts must be logically consistent.
unsafe fn from_chunked_parts_unchecked(parts: ArrayParts<Chunked>) -> Self {
unsafe { Array::from_parts_unchecked(parts) }
}
}
Expand Down
9 changes: 8 additions & 1 deletion vortex-array/src/arrays/constant/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ impl Array<Constant> {
where
S: Into<Scalar>,
{
let scalar = scalar.into();
Self::from_scalar(scalar.into(), len)
}

/// Creates the array from a [`Scalar`].
///
/// The generic constructors call this function. It is not generic, so crates that call those
/// constructors do not each compile the `Constant` array vtable.
fn from_scalar(scalar: Scalar, len: usize) -> Self {
let dtype = scalar.dtype().clone();
let data = ConstantData::new(scalar);
unsafe {
Expand Down
26 changes: 24 additions & 2 deletions vortex-array/src/arrays/decimal/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ impl Array<Decimal> {
let len = buffer.len();
let slots = DecimalData::make_slots(&validity, len);
let data = unsafe { DecimalData::new_unchecked(buffer, decimal_dtype) };
unsafe { Array::from_parts_unchecked(ArrayParts::new(Decimal, dtype, len, data, slots)) }
unsafe {
Self::from_decimal_parts_unchecked(ArrayParts::new(Decimal, dtype, len, data, slots))
}
}

/// Creates a new [`DecimalArray`] from a host-native buffer with validation.
Expand All @@ -439,7 +441,27 @@ impl Array<Decimal> {
let len = buffer.len();
let slots = DecimalData::make_slots(&validity, len);
let data = DecimalData::try_new(buffer, decimal_dtype)?;
Array::try_from_parts(ArrayParts::new(Decimal, dtype, len, data, slots))
Self::try_from_decimal_parts(ArrayParts::new(Decimal, dtype, len, data, slots))
}

/// Creates the array from parts without validation.
///
/// The generic constructors call this function. It is not generic, so crates that call those
/// constructors do not each compile the `Decimal` array vtable.
///
/// # Safety
///
/// The parts must be logically consistent.
unsafe fn from_decimal_parts_unchecked(parts: ArrayParts<Decimal>) -> Self {
unsafe { Array::from_parts_unchecked(parts) }
}

/// Creates the array from parts after validation.
///
/// The generic constructors call this function. It is not generic, so crates that call those
/// constructors do not each compile the `Decimal` array vtable.
fn try_from_decimal_parts(parts: ArrayParts<Decimal>) -> VortexResult<Self> {
Array::try_from_parts(parts)
}

/// Creates a new [`DecimalArray`] from an iterator of values.
Expand Down
34 changes: 30 additions & 4 deletions vortex-array/src/arrays/primitive/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,11 @@ impl Array<Primitive> {
let len = 0;
let data = PrimitiveData::empty::<T>(nullability);
let slots = PrimitiveData::make_slots(&Validity::from(nullability), len);
unsafe { Array::from_parts_unchecked(ArrayParts::new(Primitive, dtype, len, data, slots)) }
unsafe {
Self::from_primitive_parts_unchecked(ArrayParts::new(
Primitive, dtype, len, data, slots,
))
}
}

/// Creates a new `PrimitiveArray`.
Expand All @@ -361,7 +365,11 @@ impl Array<Primitive> {
let len = buffer.len();
let slots = PrimitiveData::make_slots(&validity, len);
let data = PrimitiveData::new(buffer, validity);
unsafe { Array::from_parts_unchecked(ArrayParts::new(Primitive, dtype, len, data, slots)) }
unsafe {
Self::from_primitive_parts_unchecked(ArrayParts::new(
Primitive, dtype, len, data, slots,
))
}
}

/// Constructs a new `PrimitiveArray`.
Expand All @@ -371,7 +379,9 @@ impl Array<Primitive> {
let slots = PrimitiveData::make_slots(&validity, len);
let data = PrimitiveData::try_new(buffer, validity)?;
Ok(unsafe {
Array::from_parts_unchecked(ArrayParts::new(Primitive, dtype, len, data, slots))
Self::from_primitive_parts_unchecked(ArrayParts::new(
Primitive, dtype, len, data, slots,
))
})
}

Expand All @@ -385,7 +395,23 @@ impl Array<Primitive> {
let len = buffer.len();
let slots = PrimitiveData::make_slots(&validity, len);
let data = unsafe { PrimitiveData::new_unchecked(buffer, validity) };
unsafe { Array::from_parts_unchecked(ArrayParts::new(Primitive, dtype, len, data, slots)) }
unsafe {
Self::from_primitive_parts_unchecked(ArrayParts::new(
Primitive, dtype, len, data, slots,
))
}
}

/// Creates the array from parts without validation.
///
/// The generic constructors call this function. It is not generic, so crates that call those
/// constructors do not each compile the `Primitive` array vtable.
///
/// # Safety
///
/// The parts must be logically consistent.
unsafe fn from_primitive_parts_unchecked(parts: ArrayParts<Primitive>) -> Self {
unsafe { Array::from_parts_unchecked(parts) }
}

/// Create a new array from a buffer handle.
Expand Down
4 changes: 3 additions & 1 deletion vortex-array/src/arrays/scalar_fn/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ impl Array<ScalarFn> {
/// # Safety
/// The caller must ensure arity and child lengths were validated and
/// "dtype" is scalar function's return dtype.
#[inline]
///
/// This function is not inlined, so crates that construct scalar function arrays do not each
/// compile the `ScalarFn` array vtable.
unsafe fn new_from_validated_slots(
scalar_fn: ScalarFnRef,
dtype: DType,
Expand Down
28 changes: 24 additions & 4 deletions vortex-array/src/arrays/struct_/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl Array<Struct> {
slots.push(Some(field));
}
let dtype = StructFields::new(names, field_dtypes);
Array::try_from_parts(ArrayParts::new(
Self::try_from_struct_parts(ArrayParts::new(
Struct,
DType::Struct(dtype, validity.nullability()),
length,
Expand All @@ -317,7 +317,7 @@ impl Array<Struct> {
let outer_dtype = DType::Struct(dtype, validity.nullability());
let slots = make_struct_slots(fields, &validity, length);
unsafe {
Array::from_parts_unchecked(ArrayParts::new(
Self::from_struct_parts_unchecked(ArrayParts::new(
Struct,
outer_dtype,
length,
Expand All @@ -336,7 +336,7 @@ impl Array<Struct> {
) -> VortexResult<Self> {
let outer_dtype = DType::Struct(dtype, validity.nullability());
let slots = make_struct_slots(fields, &validity, length);
Array::try_from_parts(ArrayParts::new(
Self::try_from_struct_parts(ArrayParts::new(
Struct,
outer_dtype,
length,
Expand All @@ -345,6 +345,26 @@ impl Array<Struct> {
))
}

/// Creates the array from parts after validation.
///
/// The generic constructors call this function. It is not generic, so crates that call those
/// constructors do not each compile the `Struct` array vtable.
fn try_from_struct_parts(parts: ArrayParts<Struct>) -> VortexResult<Self> {
Array::try_from_parts(parts)
}

/// Creates the array from parts without validation.
///
/// The generic constructors call this function. It is not generic, so crates that call those
/// constructors do not each compile the `Struct` array vtable.
///
/// # Safety
///
/// The parts must be logically consistent.
unsafe fn from_struct_parts_unchecked(parts: ArrayParts<Struct>) -> Self {
unsafe { Array::from_parts_unchecked(parts) }
}

/// Construct a `StructArray` from named fields.
pub fn from_fields<N: AsRef<str>>(items: &[(N, ArrayRef)]) -> VortexResult<Self> {
Self::try_from_iter(items.iter().map(|(a, b)| (a, b.clone())))
Expand Down Expand Up @@ -462,7 +482,7 @@ impl Array<Struct> {

let new_dtype = struct_dtype.without_field(position).ok()?;
let new_array = unsafe {
Array::from_parts_unchecked(ArrayParts::new(
Self::from_struct_parts_unchecked(ArrayParts::new(
Struct,
DType::Struct(new_dtype, self.dtype().nullability()),
len,
Expand Down
Loading