diff --git a/vortex-array/public-api.lock b/vortex-array/public-api.lock index ea2e3619b1e..5d03b88a616 100644 --- a/vortex-array/public-api.lock +++ b/vortex-array/public-api.lock @@ -4708,6 +4708,118 @@ pub vortex_array::arrays::varbinview::VarBinViewArrayParts::validity: vortex_arr pub vortex_array::arrays::varbinview::VarBinViewArrayParts::views: vortex_array::buffer::BufferHandle +pub mod vortex_array::arrays::variant + +pub struct vortex_array::arrays::variant::Variant + +impl vortex_array::arrays::Variant + +pub const vortex_array::arrays::Variant::ID: vortex_array::vtable::ArrayId + +impl core::fmt::Debug for vortex_array::arrays::Variant + +pub fn vortex_array::arrays::Variant::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result + +impl vortex_array::vtable::OperationsVTable for vortex_array::arrays::Variant + +pub fn vortex_array::arrays::Variant::scalar_at(array: &::Array, index: usize) -> vortex_error::VortexResult + +impl vortex_array::vtable::VTable for vortex_array::arrays::Variant + +pub type vortex_array::arrays::Variant::Array = vortex_array::arrays::variant::VariantArray + +pub type vortex_array::arrays::Variant::Metadata = vortex_array::EmptyMetadata + +pub type vortex_array::arrays::Variant::OperationsVTable = vortex_array::arrays::Variant + +pub type vortex_array::arrays::Variant::ValidityVTable = vortex_array::arrays::Variant + +pub fn vortex_array::arrays::Variant::append_to_builder(array: &Self::Array, builder: &mut dyn vortex_array::builders::ArrayBuilder, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<()> + +pub fn vortex_array::arrays::Variant::array_eq(array: &Self::Array, other: &Self::Array, precision: vortex_array::Precision) -> bool + +pub fn vortex_array::arrays::Variant::array_hash(array: &Self::Array, state: &mut H, precision: vortex_array::Precision) + +pub fn vortex_array::arrays::Variant::buffer(_array: &Self::Array, idx: usize) -> vortex_array::buffer::BufferHandle + +pub fn vortex_array::arrays::Variant::buffer_name(_array: &Self::Array, _idx: usize) -> core::option::Option + +pub fn vortex_array::arrays::Variant::build(dtype: &vortex_array::dtype::DType, len: usize, _metadata: &Self::Metadata, _buffers: &[vortex_array::buffer::BufferHandle], children: &dyn vortex_array::serde::ArrayChildren) -> vortex_error::VortexResult + +pub fn vortex_array::arrays::Variant::child(array: &Self::Array, idx: usize) -> vortex_array::ArrayRef + +pub fn vortex_array::arrays::Variant::child_name(_array: &Self::Array, idx: usize) -> alloc::string::String + +pub fn vortex_array::arrays::Variant::deserialize(_bytes: &[u8], _dtype: &vortex_array::dtype::DType, _len: usize, _buffers: &[vortex_array::buffer::BufferHandle], _session: &vortex_session::VortexSession) -> vortex_error::VortexResult + +pub fn vortex_array::arrays::Variant::dtype(array: &Self::Array) -> &vortex_array::dtype::DType + +pub fn vortex_array::arrays::Variant::execute(array: &Self::Array, _ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult + +pub fn vortex_array::arrays::Variant::execute_parent(array: &Self::Array, parent: &vortex_array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult> + +pub fn vortex_array::arrays::Variant::id(_array: &Self::Array) -> vortex_array::vtable::ArrayId + +pub fn vortex_array::arrays::Variant::len(array: &Self::Array) -> usize + +pub fn vortex_array::arrays::Variant::metadata(_array: &Self::Array) -> vortex_error::VortexResult + +pub fn vortex_array::arrays::Variant::nbuffers(_array: &Self::Array) -> usize + +pub fn vortex_array::arrays::Variant::nchildren(_array: &Self::Array) -> usize + +pub fn vortex_array::arrays::Variant::reduce(array: &Self::Array) -> vortex_error::VortexResult> + +pub fn vortex_array::arrays::Variant::reduce_parent(array: &Self::Array, parent: &vortex_array::ArrayRef, child_idx: usize) -> vortex_error::VortexResult> + +pub fn vortex_array::arrays::Variant::serialize(_metadata: Self::Metadata) -> vortex_error::VortexResult>> + +pub fn vortex_array::arrays::Variant::stats(array: &Self::Array) -> vortex_array::stats::StatsSetRef<'_> + +pub fn vortex_array::arrays::Variant::with_children(array: &mut Self::Array, children: alloc::vec::Vec) -> vortex_error::VortexResult<()> + +impl vortex_array::vtable::ValidityVTable for vortex_array::arrays::Variant + +pub fn vortex_array::arrays::Variant::validity(array: &::Array) -> vortex_error::VortexResult + +pub struct vortex_array::arrays::variant::VariantArray + +impl vortex_array::arrays::variant::VariantArray + +pub fn vortex_array::arrays::variant::VariantArray::child(&self) -> &vortex_array::ArrayRef + +pub fn vortex_array::arrays::variant::VariantArray::new(child: vortex_array::ArrayRef, nullability: vortex_array::dtype::Nullability) -> Self + +impl vortex_array::arrays::variant::VariantArray + +pub fn vortex_array::arrays::variant::VariantArray::to_array(&self) -> vortex_array::ArrayRef + +impl core::clone::Clone for vortex_array::arrays::variant::VariantArray + +pub fn vortex_array::arrays::variant::VariantArray::clone(&self) -> vortex_array::arrays::variant::VariantArray + +impl core::convert::AsRef for vortex_array::arrays::variant::VariantArray + +pub fn vortex_array::arrays::variant::VariantArray::as_ref(&self) -> &dyn vortex_array::DynArray + +impl core::convert::From for vortex_array::ArrayRef + +pub fn vortex_array::ArrayRef::from(value: vortex_array::arrays::variant::VariantArray) -> vortex_array::ArrayRef + +impl core::fmt::Debug for vortex_array::arrays::variant::VariantArray + +pub fn vortex_array::arrays::variant::VariantArray::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result + +impl core::ops::deref::Deref for vortex_array::arrays::variant::VariantArray + +pub type vortex_array::arrays::variant::VariantArray::Target = dyn vortex_array::DynArray + +pub fn vortex_array::arrays::variant::VariantArray::deref(&self) -> &Self::Target + +impl vortex_array::IntoArray for vortex_array::arrays::variant::VariantArray + +pub fn vortex_array::arrays::variant::VariantArray::into_array(self) -> vortex_array::ArrayRef + pub struct vortex_array::arrays::Bool impl vortex_array::arrays::Bool @@ -7852,6 +7964,116 @@ impl<'a> core::iter::traits::collect::FromIterator pub fn vortex_array::arrays::VarBinViewArray::from_iter>>(iter: T) -> Self +pub struct vortex_array::arrays::Variant + +impl vortex_array::arrays::Variant + +pub const vortex_array::arrays::Variant::ID: vortex_array::vtable::ArrayId + +impl core::fmt::Debug for vortex_array::arrays::Variant + +pub fn vortex_array::arrays::Variant::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result + +impl vortex_array::vtable::OperationsVTable for vortex_array::arrays::Variant + +pub fn vortex_array::arrays::Variant::scalar_at(array: &::Array, index: usize) -> vortex_error::VortexResult + +impl vortex_array::vtable::VTable for vortex_array::arrays::Variant + +pub type vortex_array::arrays::Variant::Array = vortex_array::arrays::variant::VariantArray + +pub type vortex_array::arrays::Variant::Metadata = vortex_array::EmptyMetadata + +pub type vortex_array::arrays::Variant::OperationsVTable = vortex_array::arrays::Variant + +pub type vortex_array::arrays::Variant::ValidityVTable = vortex_array::arrays::Variant + +pub fn vortex_array::arrays::Variant::append_to_builder(array: &Self::Array, builder: &mut dyn vortex_array::builders::ArrayBuilder, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<()> + +pub fn vortex_array::arrays::Variant::array_eq(array: &Self::Array, other: &Self::Array, precision: vortex_array::Precision) -> bool + +pub fn vortex_array::arrays::Variant::array_hash(array: &Self::Array, state: &mut H, precision: vortex_array::Precision) + +pub fn vortex_array::arrays::Variant::buffer(_array: &Self::Array, idx: usize) -> vortex_array::buffer::BufferHandle + +pub fn vortex_array::arrays::Variant::buffer_name(_array: &Self::Array, _idx: usize) -> core::option::Option + +pub fn vortex_array::arrays::Variant::build(dtype: &vortex_array::dtype::DType, len: usize, _metadata: &Self::Metadata, _buffers: &[vortex_array::buffer::BufferHandle], children: &dyn vortex_array::serde::ArrayChildren) -> vortex_error::VortexResult + +pub fn vortex_array::arrays::Variant::child(array: &Self::Array, idx: usize) -> vortex_array::ArrayRef + +pub fn vortex_array::arrays::Variant::child_name(_array: &Self::Array, idx: usize) -> alloc::string::String + +pub fn vortex_array::arrays::Variant::deserialize(_bytes: &[u8], _dtype: &vortex_array::dtype::DType, _len: usize, _buffers: &[vortex_array::buffer::BufferHandle], _session: &vortex_session::VortexSession) -> vortex_error::VortexResult + +pub fn vortex_array::arrays::Variant::dtype(array: &Self::Array) -> &vortex_array::dtype::DType + +pub fn vortex_array::arrays::Variant::execute(array: &Self::Array, _ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult + +pub fn vortex_array::arrays::Variant::execute_parent(array: &Self::Array, parent: &vortex_array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult> + +pub fn vortex_array::arrays::Variant::id(_array: &Self::Array) -> vortex_array::vtable::ArrayId + +pub fn vortex_array::arrays::Variant::len(array: &Self::Array) -> usize + +pub fn vortex_array::arrays::Variant::metadata(_array: &Self::Array) -> vortex_error::VortexResult + +pub fn vortex_array::arrays::Variant::nbuffers(_array: &Self::Array) -> usize + +pub fn vortex_array::arrays::Variant::nchildren(_array: &Self::Array) -> usize + +pub fn vortex_array::arrays::Variant::reduce(array: &Self::Array) -> vortex_error::VortexResult> + +pub fn vortex_array::arrays::Variant::reduce_parent(array: &Self::Array, parent: &vortex_array::ArrayRef, child_idx: usize) -> vortex_error::VortexResult> + +pub fn vortex_array::arrays::Variant::serialize(_metadata: Self::Metadata) -> vortex_error::VortexResult>> + +pub fn vortex_array::arrays::Variant::stats(array: &Self::Array) -> vortex_array::stats::StatsSetRef<'_> + +pub fn vortex_array::arrays::Variant::with_children(array: &mut Self::Array, children: alloc::vec::Vec) -> vortex_error::VortexResult<()> + +impl vortex_array::vtable::ValidityVTable for vortex_array::arrays::Variant + +pub fn vortex_array::arrays::Variant::validity(array: &::Array) -> vortex_error::VortexResult + +pub struct vortex_array::arrays::VariantArray + +impl vortex_array::arrays::variant::VariantArray + +pub fn vortex_array::arrays::variant::VariantArray::child(&self) -> &vortex_array::ArrayRef + +pub fn vortex_array::arrays::variant::VariantArray::new(child: vortex_array::ArrayRef, nullability: vortex_array::dtype::Nullability) -> Self + +impl vortex_array::arrays::variant::VariantArray + +pub fn vortex_array::arrays::variant::VariantArray::to_array(&self) -> vortex_array::ArrayRef + +impl core::clone::Clone for vortex_array::arrays::variant::VariantArray + +pub fn vortex_array::arrays::variant::VariantArray::clone(&self) -> vortex_array::arrays::variant::VariantArray + +impl core::convert::AsRef for vortex_array::arrays::variant::VariantArray + +pub fn vortex_array::arrays::variant::VariantArray::as_ref(&self) -> &dyn vortex_array::DynArray + +impl core::convert::From for vortex_array::ArrayRef + +pub fn vortex_array::ArrayRef::from(value: vortex_array::arrays::variant::VariantArray) -> vortex_array::ArrayRef + +impl core::fmt::Debug for vortex_array::arrays::variant::VariantArray + +pub fn vortex_array::arrays::variant::VariantArray::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result + +impl core::ops::deref::Deref for vortex_array::arrays::variant::VariantArray + +pub type vortex_array::arrays::variant::VariantArray::Target = dyn vortex_array::DynArray + +pub fn vortex_array::arrays::variant::VariantArray::deref(&self) -> &Self::Target + +impl vortex_array::IntoArray for vortex_array::arrays::variant::VariantArray + +pub fn vortex_array::arrays::variant::VariantArray::into_array(self) -> vortex_array::ArrayRef + pub mod vortex_array::arrow pub mod vortex_array::arrow::bool @@ -20420,6 +20642,10 @@ impl vortex_array::vtable::OperationsVTable fo pub fn vortex_array::arrays::VarBinView::scalar_at(array: &vortex_array::arrays::VarBinViewArray, index: usize) -> vortex_error::VortexResult +impl vortex_array::vtable::OperationsVTable for vortex_array::arrays::Variant + +pub fn vortex_array::arrays::Variant::scalar_at(array: &::Array, index: usize) -> vortex_error::VortexResult + impl vortex_array::vtable::OperationsVTable for vortex_array::arrays::dict::Dict pub fn vortex_array::arrays::dict::Dict::scalar_at(array: &vortex_array::arrays::dict::DictArray, index: usize) -> vortex_error::VortexResult @@ -21304,6 +21530,60 @@ pub fn vortex_array::arrays::VarBinView::stats(array: &vortex_array::arrays::Var pub fn vortex_array::arrays::VarBinView::with_children(array: &mut Self::Array, children: alloc::vec::Vec) -> vortex_error::VortexResult<()> +impl vortex_array::vtable::VTable for vortex_array::arrays::Variant + +pub type vortex_array::arrays::Variant::Array = vortex_array::arrays::variant::VariantArray + +pub type vortex_array::arrays::Variant::Metadata = vortex_array::EmptyMetadata + +pub type vortex_array::arrays::Variant::OperationsVTable = vortex_array::arrays::Variant + +pub type vortex_array::arrays::Variant::ValidityVTable = vortex_array::arrays::Variant + +pub fn vortex_array::arrays::Variant::append_to_builder(array: &Self::Array, builder: &mut dyn vortex_array::builders::ArrayBuilder, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<()> + +pub fn vortex_array::arrays::Variant::array_eq(array: &Self::Array, other: &Self::Array, precision: vortex_array::Precision) -> bool + +pub fn vortex_array::arrays::Variant::array_hash(array: &Self::Array, state: &mut H, precision: vortex_array::Precision) + +pub fn vortex_array::arrays::Variant::buffer(_array: &Self::Array, idx: usize) -> vortex_array::buffer::BufferHandle + +pub fn vortex_array::arrays::Variant::buffer_name(_array: &Self::Array, _idx: usize) -> core::option::Option + +pub fn vortex_array::arrays::Variant::build(dtype: &vortex_array::dtype::DType, len: usize, _metadata: &Self::Metadata, _buffers: &[vortex_array::buffer::BufferHandle], children: &dyn vortex_array::serde::ArrayChildren) -> vortex_error::VortexResult + +pub fn vortex_array::arrays::Variant::child(array: &Self::Array, idx: usize) -> vortex_array::ArrayRef + +pub fn vortex_array::arrays::Variant::child_name(_array: &Self::Array, idx: usize) -> alloc::string::String + +pub fn vortex_array::arrays::Variant::deserialize(_bytes: &[u8], _dtype: &vortex_array::dtype::DType, _len: usize, _buffers: &[vortex_array::buffer::BufferHandle], _session: &vortex_session::VortexSession) -> vortex_error::VortexResult + +pub fn vortex_array::arrays::Variant::dtype(array: &Self::Array) -> &vortex_array::dtype::DType + +pub fn vortex_array::arrays::Variant::execute(array: &Self::Array, _ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult + +pub fn vortex_array::arrays::Variant::execute_parent(array: &Self::Array, parent: &vortex_array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult> + +pub fn vortex_array::arrays::Variant::id(_array: &Self::Array) -> vortex_array::vtable::ArrayId + +pub fn vortex_array::arrays::Variant::len(array: &Self::Array) -> usize + +pub fn vortex_array::arrays::Variant::metadata(_array: &Self::Array) -> vortex_error::VortexResult + +pub fn vortex_array::arrays::Variant::nbuffers(_array: &Self::Array) -> usize + +pub fn vortex_array::arrays::Variant::nchildren(_array: &Self::Array) -> usize + +pub fn vortex_array::arrays::Variant::reduce(array: &Self::Array) -> vortex_error::VortexResult> + +pub fn vortex_array::arrays::Variant::reduce_parent(array: &Self::Array, parent: &vortex_array::ArrayRef, child_idx: usize) -> vortex_error::VortexResult> + +pub fn vortex_array::arrays::Variant::serialize(_metadata: Self::Metadata) -> vortex_error::VortexResult>> + +pub fn vortex_array::arrays::Variant::stats(array: &Self::Array) -> vortex_array::stats::StatsSetRef<'_> + +pub fn vortex_array::arrays::Variant::with_children(array: &mut Self::Array, children: alloc::vec::Vec) -> vortex_error::VortexResult<()> + impl vortex_array::vtable::VTable for vortex_array::arrays::dict::Dict pub type vortex_array::arrays::dict::Dict::Array = vortex_array::arrays::dict::DictArray @@ -21604,6 +21884,10 @@ impl vortex_array::vtable::ValidityVTable for vort pub fn vortex_array::arrays::Shared::validity(array: &vortex_array::arrays::SharedArray) -> vortex_error::VortexResult +impl vortex_array::vtable::ValidityVTable for vortex_array::arrays::Variant + +pub fn vortex_array::arrays::Variant::validity(array: &::Array) -> vortex_error::VortexResult + impl vortex_array::vtable::ValidityVTable for vortex_array::arrays::dict::Dict pub fn vortex_array::arrays::dict::Dict::validity(array: &vortex_array::arrays::dict::DictArray) -> vortex_error::VortexResult @@ -22672,6 +22956,10 @@ impl vortex_array::IntoArray for vortex_array::arrays::slice::SliceArray pub fn vortex_array::arrays::slice::SliceArray::into_array(self) -> vortex_array::ArrayRef +impl vortex_array::IntoArray for vortex_array::arrays::variant::VariantArray + +pub fn vortex_array::arrays::variant::VariantArray::into_array(self) -> vortex_array::ArrayRef + impl vortex_array::IntoArray for vortex_buffer::bit::buf::BitBuffer pub fn vortex_buffer::bit::buf::BitBuffer::into_array(self) -> vortex_array::ArrayRef diff --git a/vortex-array/src/arrays/mod.rs b/vortex-array/src/arrays/mod.rs index 62325b69eb5..43f8a84d49e 100644 --- a/vortex-array/src/arrays/mod.rs +++ b/vortex-array/src/arrays/mod.rs @@ -94,5 +94,9 @@ pub mod varbinview; pub use varbinview::VarBinView; pub use varbinview::VarBinViewArray; +pub mod variant; +pub use variant::Variant; +pub use variant::VariantArray; + #[cfg(feature = "arbitrary")] pub mod arbitrary; diff --git a/vortex-array/src/arrays/variant/mod.rs b/vortex-array/src/arrays/variant/mod.rs new file mode 100644 index 00000000000..054cdedb9b8 --- /dev/null +++ b/vortex-array/src/arrays/variant/mod.rs @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Copyright the Vortex contributors + +mod vtable; + +pub use self::vtable::Variant; +use crate::ArrayRef; +use crate::dtype::DType; +use crate::dtype::Nullability; + +/// The canonical in-memory representation of variant (semi-structured) data. +/// +/// Wraps a single child array that contains the actual variant-encoded data +/// (e.g. a `ParquetVariantArray` or any other variant encoding). +#[derive(Clone, Debug)] +pub struct VariantArray { + dtype: DType, + child: ArrayRef, +} + +impl VariantArray { + /// Creates a new VariantArray with the given nullability. + pub fn new(child: ArrayRef, nullability: Nullability) -> Self { + Self { + dtype: DType::Variant(nullability), + child, + } + } + + /// Returns a reference to the underlying child array. + pub fn child(&self) -> &ArrayRef { + &self.child + } +} diff --git a/vortex-array/src/arrays/variant/vtable/mod.rs b/vortex-array/src/arrays/variant/vtable/mod.rs new file mode 100644 index 00000000000..71ae0665212 --- /dev/null +++ b/vortex-array/src/arrays/variant/vtable/mod.rs @@ -0,0 +1,157 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Copyright the Vortex contributors + +mod operations; +mod validity; + +use std::hash::Hasher; + +use vortex_error::VortexExpect; +use vortex_error::VortexResult; +use vortex_error::vortex_ensure; +use vortex_error::vortex_panic; + +use crate::ArrayEq; +use crate::ArrayHash; +use crate::ArrayRef; +use crate::EmptyMetadata; +use crate::ExecutionCtx; +use crate::ExecutionStep; +use crate::IntoArray; +use crate::Precision; +use crate::arrays::VariantArray; +use crate::buffer::BufferHandle; +use crate::dtype::DType; +use crate::serde::ArrayChildren; +use crate::stats::StatsSetRef; +use crate::vtable; +use crate::vtable::ArrayId; +use crate::vtable::VTable; + +vtable!(Variant); + +#[derive(Debug)] +pub struct Variant; + +impl Variant { + pub const ID: ArrayId = ArrayId::new_ref("vortex.variant"); +} + +impl VTable for Variant { + type Array = VariantArray; + + type Metadata = EmptyMetadata; + + type OperationsVTable = Self; + + type ValidityVTable = Self; + + fn id(_array: &Self::Array) -> ArrayId { + Self::ID + } + + fn len(array: &Self::Array) -> usize { + array.child.len() + } + + fn dtype(array: &Self::Array) -> &DType { + &array.dtype + } + + fn stats(array: &Self::Array) -> StatsSetRef<'_> { + array.child.statistics() + } + + fn array_hash(array: &Self::Array, state: &mut H, precision: Precision) { + array.child.array_hash(state, precision); + } + + fn array_eq(array: &Self::Array, other: &Self::Array, precision: Precision) -> bool { + array.child.array_eq(&other.child, precision) + } + + fn nbuffers(_array: &Self::Array) -> usize { + 0 + } + + fn buffer(_array: &Self::Array, idx: usize) -> BufferHandle { + vortex_panic!("VariantArray buffer index {idx} out of bounds") + } + + fn buffer_name(_array: &Self::Array, _idx: usize) -> Option { + None + } + + fn nchildren(_array: &Self::Array) -> usize { + 1 + } + + fn child(array: &Self::Array, idx: usize) -> ArrayRef { + match idx { + 0 => array.child.clone(), + _ => vortex_panic!("VariantArray child index {idx} out of bounds"), + } + } + + fn child_name(_array: &Self::Array, idx: usize) -> String { + match idx { + 0 => "child".to_string(), + _ => vortex_panic!("VariantArray child_name index {idx} out of bounds"), + } + } + + fn metadata(_array: &Self::Array) -> VortexResult { + Ok(EmptyMetadata) + } + + fn serialize(_metadata: Self::Metadata) -> VortexResult>> { + Ok(Some(vec![])) + } + + fn deserialize( + _bytes: &[u8], + _dtype: &DType, + _len: usize, + _buffers: &[BufferHandle], + _session: &vortex_session::VortexSession, + ) -> VortexResult { + Ok(EmptyMetadata) + } + + fn build( + dtype: &DType, + len: usize, + _metadata: &Self::Metadata, + _buffers: &[BufferHandle], + children: &dyn ArrayChildren, + ) -> VortexResult { + vortex_ensure!(matches!(dtype, DType::Variant(_)), "Expected Variant DType"); + vortex_ensure!( + children.len() == 1, + "Expected 1 child, got {}", + children.len() + ); + // The child can be any variant encoding, so we use DType::Variant. + let child = children.get( + 0, + &DType::Variant(crate::dtype::Nullability::NonNullable), + len, + )?; + Ok(VariantArray::new(child, dtype.nullability())) + } + + fn with_children(array: &mut Self::Array, children: Vec) -> VortexResult<()> { + vortex_ensure!( + children.len() == 1, + "VariantArray expects exactly 1 child, got {}", + children.len() + ); + array.child = children.into_iter().next().vortex_expect("must exist"); + Ok(()) + } + + fn execute(array: &Self::Array, _ctx: &mut ExecutionCtx) -> VortexResult { + // VariantArray is the canonical variant representation. + Ok(ExecutionStep::done(array.clone().into_array())) + } +} diff --git a/vortex-array/src/arrays/variant/vtable/operations.rs b/vortex-array/src/arrays/variant/vtable/operations.rs new file mode 100644 index 00000000000..5884b43319d --- /dev/null +++ b/vortex-array/src/arrays/variant/vtable/operations.rs @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Copyright the Vortex contributors + +use vortex_error::VortexResult; + +use crate::arrays::Variant; +use crate::scalar::Scalar; +use crate::vtable::OperationsVTable; + +impl OperationsVTable for Variant { + fn scalar_at( + array: &::Array, + index: usize, + ) -> VortexResult { + array.child().scalar_at(index) + } +} diff --git a/vortex-array/src/arrays/variant/vtable/validity.rs b/vortex-array/src/arrays/variant/vtable/validity.rs new file mode 100644 index 00000000000..8e1b1d804ad --- /dev/null +++ b/vortex-array/src/arrays/variant/vtable/validity.rs @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Copyright the Vortex contributors + +use vortex_error::VortexResult; + +use crate::arrays::Variant; +use crate::validity::Validity; +use crate::vtable::VTable; +use crate::vtable::ValidityVTable; + +impl ValidityVTable for Variant { + fn validity(array: &::Array) -> VortexResult { + array.child().validity() + } +}