use std::any::Any;
use std::fmt::{Debug, Display, Formatter};
use std::sync::Arc;
use arrow_array::ArrayRef;
use vortex_error::{vortex_bail, vortex_panic, VortexResult};
use crate::compute::ComputeVTable;
use crate::encoding::{EncodingId, EncodingVTable};
use crate::stats::StatisticsVTable;
use crate::validity::{LogicalValidity, ValidityVTable};
use crate::variants::VariantsVTable;
use crate::visitor::{ArrayVisitor, VisitorVTable};
use crate::{
ArrayData, ArrayMetadata, Canonical, IntoCanonicalVTable, MetadataVTable,
TrySerializeArrayMetadata,
};
#[derive(Debug, Clone, Copy)]
pub struct OpaqueEncoding(pub u16);
impl VariantsVTable<ArrayData> for OpaqueEncoding {}
impl EncodingVTable for OpaqueEncoding {
fn id(&self) -> EncodingId {
EncodingId::new("vortex.opaque", self.0)
}
fn as_any(&self) -> &dyn Any {
self
}
}
impl IntoCanonicalVTable for OpaqueEncoding {
fn into_canonical(&self, _array: ArrayData) -> VortexResult<Canonical> {
vortex_bail!(
"OpaqueEncoding: into_canonical cannot be called for opaque array ({})",
self.0
)
}
fn into_arrow(&self, _array: ArrayData) -> VortexResult<ArrayRef> {
vortex_bail!(
"OpaqueEncoding: into_arrow cannot be called for opaque array ({})",
self.0
)
}
}
impl ComputeVTable for OpaqueEncoding {}
impl MetadataVTable for OpaqueEncoding {
fn load_metadata(&self, _metadata: Option<&[u8]>) -> VortexResult<Arc<dyn ArrayMetadata>> {
Ok(Arc::new(OpaqueMetadata))
}
}
impl StatisticsVTable<ArrayData> for OpaqueEncoding {}
impl ValidityVTable<ArrayData> for OpaqueEncoding {
fn is_valid(&self, _array: &ArrayData, _index: usize) -> bool {
vortex_panic!(
"OpaqueEncoding: is_valid cannot be called for opaque array ({})",
self.0
)
}
fn logical_validity(&self, _array: &ArrayData) -> LogicalValidity {
vortex_panic!(
"OpaqueEncoding: logical_validity cannot be called for opaque array ({})",
self.0
)
}
}
impl VisitorVTable<ArrayData> for OpaqueEncoding {
fn accept(&self, _array: &ArrayData, _visitor: &mut dyn ArrayVisitor) -> VortexResult<()> {
vortex_bail!(
"OpaqueEncoding: into_canonical cannot be called for opaque array ({})",
self.0
)
}
}
#[derive(Debug)]
pub struct OpaqueMetadata;
impl TrySerializeArrayMetadata for OpaqueMetadata {
fn try_serialize_metadata(&self) -> VortexResult<Arc<[u8]>> {
vortex_bail!("OpaqueMetadata cannot be serialized")
}
}
impl Display for OpaqueMetadata {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "OpaqueMetadata")
}
}
impl ArrayMetadata for OpaqueMetadata {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_arc(self: Arc<Self>) -> Arc<dyn Any + Send + Sync> {
self
}
}