Skip to content
Merged
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
12 changes: 8 additions & 4 deletions vortex-array/src/arrays/extension/vtable/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ mod tests {
use crate::expr::Operator;
use crate::optimizer::ArrayOptimizer;

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
struct TestExt;
impl ExtDTypeVTable for TestExt {
type Metadata = EmptyMetadata;
Expand All @@ -82,7 +82,11 @@ mod tests {
ExtID::new_ref("test_ext")
}

fn validate(&self, _options: &Self::Metadata, _storage_dtype: &DType) -> VortexResult<()> {
fn validate_dtype(
&self,
_options: &Self::Metadata,
_storage_dtype: &DType,
) -> VortexResult<()> {
Ok(())
}
}
Expand Down Expand Up @@ -153,7 +157,7 @@ mod tests {

#[test]
fn test_scalar_fn_no_pushdown_different_ext_types() {
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
struct TestExt2;
impl ExtDTypeVTable for TestExt2 {
type Metadata = EmptyMetadata;
Expand All @@ -162,7 +166,7 @@ mod tests {
ExtID::new_ref("test_ext_2")
}

fn validate(
fn validate_dtype(
&self,
_options: &Self::Metadata,
_storage_dtype: &DType,
Expand Down
4 changes: 2 additions & 2 deletions vortex-dtype/src/datetime/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::extension::ExtDTypeVTable;
use crate::extension::ExtID;

/// Date DType.
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct Date;

impl Date {
Expand Down Expand Up @@ -54,7 +54,7 @@ impl ExtDTypeVTable for Date {
TimeUnit::try_from(tag)
}

fn validate(&self, metadata: &Self::Metadata, storage_dtype: &DType) -> VortexResult<()> {
fn validate_dtype(&self, metadata: &Self::Metadata, storage_dtype: &DType) -> VortexResult<()> {
let ptype = date_ptype(metadata)
.ok_or_else(|| vortex_err!("Date type does not support time unit {}", metadata))?;

Expand Down
4 changes: 2 additions & 2 deletions vortex-dtype/src/datetime/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::extension::ExtDTypeVTable;
use crate::extension::ExtID;

/// Time DType.
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct Time;

impl Time {
Expand Down Expand Up @@ -50,7 +50,7 @@ impl ExtDTypeVTable for Time {
TimeUnit::try_from(tag)
}

fn validate(&self, metadata: &Self::Metadata, storage_dtype: &DType) -> VortexResult<()> {
fn validate_dtype(&self, metadata: &Self::Metadata, storage_dtype: &DType) -> VortexResult<()> {
let ptype = time_ptype(metadata)
.ok_or_else(|| vortex_err!("Time type does not support time unit {}", metadata))?;

Expand Down
10 changes: 7 additions & 3 deletions vortex-dtype/src/datetime/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ use crate::extension::ExtDTypeVTable;
use crate::extension::ExtID;

/// Timestamp DType.
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct Timestamp;

impl Timestamp {
/// Creates a new Timestamp extension dtype with the given time unit and nullability.
/// Creates a new Timestamp extension =dtype with the given time unit and nullability.
pub fn new(time_unit: TimeUnit, nullability: Nullability) -> ExtDType<Self> {
Self::new_with_tz(time_unit, None, nullability)
}
Expand Down Expand Up @@ -120,7 +120,11 @@ impl ExtDTypeVTable for Timestamp {
})
}

fn validate(&self, _metadata: &Self::Metadata, storage_dtype: &DType) -> VortexResult<()> {
fn validate_dtype(
&self,
_metadata: &Self::Metadata,
storage_dtype: &DType,
) -> VortexResult<()> {
vortex_ensure!(
matches!(storage_dtype, DType::Primitive(PType::I64, _)),
"Timestamp storage dtype must be i64"
Expand Down
2 changes: 1 addition & 1 deletion vortex-dtype/src/extension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<V: ExtDTypeVTable> ExtDType<V> {
metadata: V::Metadata,
storage_dtype: DType,
) -> VortexResult<Self> {
vtable.validate(&metadata, &storage_dtype)?;
vtable.validate_dtype(&metadata, &storage_dtype)?;
Ok(Self(Arc::new(ExtDTypeAdapter::<V> {
vtable,
metadata,
Expand Down
15 changes: 4 additions & 11 deletions vortex-dtype/src/extension/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::ExtID;
use crate::extension::ExtDTypeRef;

/// The public API for defining new extension DTypes.
pub trait ExtDTypeVTable: 'static + Sized + Send + Sync + Clone + Debug {
pub trait ExtDTypeVTable: 'static + Sized + Send + Sync + Clone + Debug + Eq + Hash {
/// Associated type containing the deserialized metadata for this extension type
type Metadata: 'static + Send + Sync + Clone + Debug + Display + Eq + Hash;

Expand All @@ -40,23 +40,20 @@ pub trait ExtDTypeVTable: 'static + Sized + Send + Sync + Clone + Debug {
}

/// Validate that the given storage type is compatible with this extension type.
fn validate(&self, metadata: &Self::Metadata, storage_dtype: &DType) -> VortexResult<()>;
fn validate_dtype(&self, metadata: &Self::Metadata, storage_dtype: &DType) -> VortexResult<()>;
}

/// A dynamic vtable for extension types, used for type-erased deserialization.
// TODO(ngates): consider renaming this to ExtDTypePlugin or similar?
pub trait DynVTable: 'static + Send + Sync + Debug {
pub trait DynExtDTypeVTable: 'static + Send + Sync + Debug {
/// Returns the ID for this extension type.
fn id(&self) -> ExtID;

/// Deserialize an extension type from serialized metadata.
fn deserialize(&self, data: &[u8], storage_dtype: DType) -> VortexResult<ExtDTypeRef>;

/// Clones this vtable into a boxed trait object.
fn clone_box(&self) -> Box<dyn DynVTable>;
}

impl<V: ExtDTypeVTable> DynVTable for V {
impl<V: ExtDTypeVTable> DynExtDTypeVTable for V {
fn id(&self) -> ExtID {
ExtDTypeVTable::id(self)
}
Expand All @@ -65,10 +62,6 @@ impl<V: ExtDTypeVTable> DynVTable for V {
let metadata = ExtDTypeVTable::deserialize(self, data)?;
Ok(ExtDType::try_with_vtable(self.clone(), metadata, storage_dtype)?.erased())
}

fn clone_box(&self) -> Box<dyn DynVTable> {
Box::new(self.clone())
}
}

/// An empty metadata struct for extension dtypes that do not require any metadata.
Expand Down
6 changes: 3 additions & 3 deletions vortex-dtype/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use vortex_session::registry::Registry;
use crate::datetime::Date;
use crate::datetime::Time;
use crate::datetime::Timestamp;
use crate::extension::DynVTable;
use crate::extension::DynExtDTypeVTable;
use crate::extension::ExtDTypeVTable;

/// Registry for extension dtypes.
pub type ExtDTypeRegistry = Registry<Arc<dyn DynVTable>>;
pub type ExtDTypeRegistry = Registry<Arc<dyn DynExtDTypeVTable>>;

/// Session for managing extension dtypes.
#[derive(Debug)]
Expand All @@ -43,7 +43,7 @@ impl DTypeSession {
/// Register an extension DType with the Vortex session.
pub fn register<V: ExtDTypeVTable>(&self, vtable: V) {
self.registry
.register(vtable.id(), Arc::new(vtable) as Arc<dyn DynVTable>);
.register(vtable.id(), Arc::new(vtable) as Arc<dyn DynExtDTypeVTable>);
}

/// Return the registry of extension dtypes.
Expand Down
4 changes: 2 additions & 2 deletions vortex-duckdb/src/convert/dtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ mod tests {
use vortex::dtype::ExtID;
use vortex::dtype::PType;

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
struct TestExt;
impl ExtDTypeVTable for TestExt {
type Metadata = EmptyMetadata;
Expand All @@ -576,7 +576,7 @@ mod tests {
ExtID::new_ref("unknown.extension")
}

fn validate(
fn validate_dtype(
&self,
_options: &Self::Metadata,
_storage_dtype: &DType,
Expand Down
8 changes: 6 additions & 2 deletions vortex-scalar/src/arrow/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ fn test_list_scalar_to_arrow_todo() {
fn test_non_temporal_extension_to_arrow_todo() {
use vortex_dtype::ExtID;

#[derive(Debug, Clone, Default)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
struct SomeExt;
impl ExtDTypeVTable for SomeExt {
type Metadata = String;
Expand All @@ -279,7 +279,11 @@ fn test_non_temporal_extension_to_arrow_todo() {
vortex_bail!("not implemented")
}

fn validate(&self, _options: &Self::Metadata, _storage_dtype: &DType) -> VortexResult<()> {
fn validate_dtype(
&self,
_options: &Self::Metadata,
_storage_dtype: &DType,
) -> VortexResult<()> {
Ok(())
}
}
Expand Down
16 changes: 10 additions & 6 deletions vortex-scalar/src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ mod tests {
use crate::Scalar;
use crate::ScalarValue;

#[derive(Debug, Clone, Default)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
struct TestExt;
impl ExtDTypeVTable for TestExt {
type Metadata = EmptyMetadata;
Expand All @@ -176,7 +176,11 @@ mod tests {
ExtID::new_ref("test_ext")
}

fn validate(&self, _options: &Self::Metadata, _storage_dtype: &DType) -> VortexResult<()> {
fn validate_dtype(
&self,
_options: &Self::Metadata,
_storage_dtype: &DType,
) -> VortexResult<()> {
Ok(())
}
}
Expand Down Expand Up @@ -234,7 +238,7 @@ mod tests {

#[test]
fn test_ext_scalar_partial_ord_different_types() {
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
struct TestExt2;
impl ExtDTypeVTable for TestExt2 {
type Metadata = EmptyMetadata;
Expand All @@ -243,7 +247,7 @@ mod tests {
ExtID::new_ref("test_ext_2")
}

fn validate(
fn validate_dtype(
&self,
_options: &Self::Metadata,
_storage_dtype: &DType,
Expand Down Expand Up @@ -413,7 +417,7 @@ mod tests {

#[test]
fn test_ext_scalar_with_metadata() {
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
struct TestExtMetadata;
impl ExtDTypeVTable for TestExtMetadata {
type Metadata = usize;
Expand All @@ -422,7 +426,7 @@ mod tests {
ExtID::new_ref("test_ext_metadata")
}

fn validate(
fn validate_dtype(
&self,
_options: &Self::Metadata,
_storage_dtype: &DType,
Expand Down
16 changes: 10 additions & 6 deletions vortex-scalar/src/tests/casting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod tests {
use crate::Scalar;
use crate::ScalarValue;

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
struct Apples;
impl ExtDTypeVTable for Apples {
type Metadata = usize;
Expand All @@ -33,7 +33,11 @@ mod tests {
ExtID::new_ref("apples")
}

fn validate(&self, _options: &Self::Metadata, _storage_dtype: &DType) -> VortexResult<()> {
fn validate_dtype(
&self,
_options: &Self::Metadata,
_storage_dtype: &DType,
) -> VortexResult<()> {
Ok(())
}
}
Expand Down Expand Up @@ -311,7 +315,7 @@ mod tests {
#[test]
fn test_extension_dtype_coercion() {
// Create an extension type with f16 storage
#[derive(Debug, Clone, Default)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
struct F16Ext;
impl ExtDTypeVTable for F16Ext {
type Metadata = usize;
Expand All @@ -320,7 +324,7 @@ mod tests {
ExtID::new_ref("f16_ext")
}

fn validate(
fn validate_dtype(
&self,
_options: &Self::Metadata,
_storage_dtype: &DType,
Expand Down Expand Up @@ -356,7 +360,7 @@ mod tests {
#[test]
fn test_extension_dtype_nested_struct_coercion() {
// Create an extension type with struct storage that contains f16 field
#[derive(Debug, Clone, Default)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
struct StructExt;
impl ExtDTypeVTable for StructExt {
type Metadata = usize;
Expand All @@ -365,7 +369,7 @@ mod tests {
ExtID::new_ref("struct_ext")
}

fn validate(
fn validate_dtype(
&self,
_options: &Self::Metadata,
_storage_dtype: &DType,
Expand Down
Loading