mod array;
mod dyn_;
mod operations;
mod validity;
mod visitor;
use std::fmt::Debug;
use std::ops::Deref;
pub use array::*;
pub use dyn_::*;
pub use operations::*;
pub use validity::*;
pub use visitor::*;
use vortex_dtype::DType;
use vortex_error::VortexResult;
use vortex_session::VortexSession;
use crate::Array;
use crate::ArrayRef;
use crate::IntoArray;
use crate::buffer::BufferHandle;
use crate::builders::ArrayBuilder;
use crate::executor::ExecutionCtx;
use crate::serde::ArrayChildren;
pub trait VTable: 'static + Sized + Send + Sync + Debug {
type Array: 'static + Send + Sync + Clone + Debug + Deref<Target = dyn Array> + IntoArray;
type Metadata: Debug;
type ArrayVTable: BaseArrayVTable<Self>;
type OperationsVTable: OperationsVTable<Self>;
type ValidityVTable: ValidityVTable<Self>;
type VisitorVTable: VisitorVTable<Self>;
fn id(array: &Self::Array) -> ArrayId;
fn metadata(array: &Self::Array) -> VortexResult<Self::Metadata>;
fn serialize(metadata: Self::Metadata) -> VortexResult<Option<Vec<u8>>>;
fn deserialize(
bytes: &[u8],
_dtype: &DType,
_len: usize,
_buffers: &[BufferHandle],
_session: &VortexSession,
) -> VortexResult<Self::Metadata>;
fn append_to_builder(
array: &Self::Array,
builder: &mut dyn ArrayBuilder,
ctx: &mut ExecutionCtx,
) -> VortexResult<()> {
let array = Self::execute(array, ctx)?;
builder.extend_from_array(array.as_ref());
Ok(())
}
fn build(
dtype: &DType,
len: usize,
metadata: &Self::Metadata,
buffers: &[BufferHandle],
children: &dyn ArrayChildren,
) -> VortexResult<Self::Array>;
fn with_children(array: &mut Self::Array, children: Vec<ArrayRef>) -> VortexResult<()>;
fn execute(array: &Self::Array, ctx: &mut ExecutionCtx) -> VortexResult<ArrayRef>;
fn execute_parent(
array: &Self::Array,
parent: &ArrayRef,
child_idx: usize,
ctx: &mut ExecutionCtx,
) -> VortexResult<Option<ArrayRef>> {
_ = (array, parent, child_idx, ctx);
Ok(None)
}
fn reduce(array: &Self::Array) -> VortexResult<Option<ArrayRef>> {
_ = array;
Ok(None)
}
fn reduce_parent(
array: &Self::Array,
parent: &ArrayRef,
child_idx: usize,
) -> VortexResult<Option<ArrayRef>> {
_ = (array, parent, child_idx);
Ok(None)
}
}
pub struct NotSupported;
#[macro_export]
macro_rules! vtable {
($V:ident) => {
$crate::aliases::paste::paste! {
impl AsRef<dyn $crate::Array> for [<$V Array>] {
fn as_ref(&self) -> &dyn $crate::Array {
unsafe { &*(self as *const [<$V Array>] as *const $crate::ArrayAdapter<[<$V VTable>]>) }
}
}
impl std::ops::Deref for [<$V Array>] {
type Target = dyn $crate::Array;
fn deref(&self) -> &Self::Target {
unsafe { &*(self as *const [<$V Array>] as *const $crate::ArrayAdapter<[<$V VTable>]>) }
}
}
impl $crate::IntoArray for [<$V Array>] {
fn into_array(self) -> $crate::ArrayRef {
std::sync::Arc::new(unsafe { std::mem::transmute::<[<$V Array>], $crate::ArrayAdapter::<[<$V VTable>]>>(self) })
}
}
impl From<[<$V Array>]> for $crate::ArrayRef {
fn from(value: [<$V Array>]) -> $crate::ArrayRef {
use $crate::IntoArray;
value.into_array()
}
}
}
};
}