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
108 changes: 54 additions & 54 deletions vortex-array/public-api.lock

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions vortex-array/src/arrays/extension/compute/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,11 @@ mod tests {
Ok(EmptyMetadata)
}

fn validate_dtype(&self, _extension_dtype: &ExtDType<Self>) -> VortexResult<()> {
fn validate_dtype(_extension_dtype: &ExtDType<Self>) -> VortexResult<()> {
Ok(())
}

fn unpack_native<'a>(
&self,
_extension_dtype: &'a ExtDType<Self>,
_storage_value: &'a ScalarValue,
) -> VortexResult<Self::NativeValue<'a>> {
Expand Down Expand Up @@ -192,12 +191,11 @@ mod tests {
Ok(EmptyMetadata)
}

fn validate_dtype(&self, _extension_dtype: &ExtDType<Self>) -> VortexResult<()> {
fn validate_dtype(_extension_dtype: &ExtDType<Self>) -> VortexResult<()> {
Ok(())
}

fn unpack_native<'a>(
&self,
_extension_dtype: &'a ExtDType<Self>,
_storage_value: &'a ScalarValue,
) -> VortexResult<Self::NativeValue<'a>> {
Expand Down
12 changes: 6 additions & 6 deletions vortex-array/src/dtype/extension/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<V: ExtVTable> ExtDType<V> {
storage_dtype,
};

this.vtable.validate_dtype(&this)?;
V::validate_dtype(&this)?;

Ok(this)
}
Expand Down Expand Up @@ -182,15 +182,15 @@ impl<V: ExtVTable> DynExtDType for ExtDType<V> {
}

fn value_validate(&self, storage_value: &ScalarValue) -> VortexResult<()> {
self.vtable.validate_scalar_value(self, storage_value)
V::validate_scalar_value(self, storage_value)
}

fn value_display(
&self,
f: &mut fmt::Formatter<'_>,
storage_value: &ScalarValue,
) -> fmt::Result {
match self.vtable.unpack_native(self, storage_value) {
match V::unpack_native(self, storage_value) {
Ok(native) => fmt::Display::fmt(&native, f),
Err(_) => write!(
f,
Expand All @@ -202,14 +202,14 @@ impl<V: ExtVTable> DynExtDType for ExtDType<V> {
}

fn coercion_can_coerce_from(&self, other: &DType) -> bool {
self.vtable.can_coerce_from(self, other)
V::can_coerce_from(self, other)
}

fn coercion_can_coerce_to(&self, other: &DType) -> bool {
self.vtable.can_coerce_to(self, other)
V::can_coerce_to(self, other)
}

fn coercion_least_supertype(&self, other: &DType) -> Option<DType> {
self.vtable.least_supertype(self, other)
V::least_supertype(self, other)
}
}
12 changes: 5 additions & 7 deletions vortex-array/src/dtype/extension/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ pub trait ExtVTable: 'static + Sized + Send + Sync + Clone + Debug + Eq + Hash {
fn deserialize_metadata(&self, metadata: &[u8]) -> VortexResult<Self::Metadata>;

/// Validate that the given storage type is compatible with this extension type.
fn validate_dtype(&self, ext_dtype: &ExtDType<Self>) -> VortexResult<()>;
fn validate_dtype(ext_dtype: &ExtDType<Self>) -> VortexResult<()>;

/// Can a value of `other` be implicitly widened into this type?
/// e.g. GeographyType might accept Point, LineString, etc.
///
/// Implementors only need to override one of `can_coerce_from` or `can_coerce_to` — both
/// exist so that either side of the coercion can provide the logic.
fn can_coerce_from(&self, ext_dtype: &ExtDType<Self>, other: &DType) -> bool {
fn can_coerce_from(ext_dtype: &ExtDType<Self>, other: &DType) -> bool {
let _ = (ext_dtype, other);
false
}
Expand All @@ -53,14 +53,14 @@ pub trait ExtVTable: 'static + Sized + Send + Sync + Clone + Debug + Eq + Hash {
///
/// Implementors only need to override one of `can_coerce_from` or `can_coerce_to` — both
/// exist so that either side of the coercion can provide the logic.
fn can_coerce_to(&self, ext_dtype: &ExtDType<Self>, other: &DType) -> bool {
fn can_coerce_to(ext_dtype: &ExtDType<Self>, other: &DType) -> bool {
let _ = (ext_dtype, other);
false
}

/// Given two types in a Uniform context, what is their least supertype?
/// Return None if no supertype exists.
fn least_supertype(&self, ext_dtype: &ExtDType<Self>, other: &DType) -> Option<DType> {
fn least_supertype(ext_dtype: &ExtDType<Self>, other: &DType) -> Option<DType> {
let _ = (ext_dtype, other);
None
}
Expand All @@ -75,11 +75,10 @@ pub trait ExtVTable: 'static + Sized + Send + Sync + Clone + Debug + Eq + Hash {
///
/// Returns an error if the storage [`ScalarValue`] is not compatible with the extension type.
fn validate_scalar_value(
&self,
ext_dtype: &ExtDType<Self>,
storage_value: &ScalarValue,
) -> VortexResult<()> {
self.unpack_native(ext_dtype, storage_value).map(|_| ())
Self::unpack_native(ext_dtype, storage_value).map(|_| ())
}

/// Validate and unpack a native value from the storage [`ScalarValue`].
Expand All @@ -92,7 +91,6 @@ pub trait ExtVTable: 'static + Sized + Send + Sync + Clone + Debug + Eq + Hash {
///
/// Returns an error if the storage [`ScalarValue`] is not compatible with the extension type.
fn unpack_native<'a>(
&self,
ext_dtype: &'a ExtDType<Self>,
storage_value: &'a ScalarValue,
) -> VortexResult<Self::NativeValue<'a>>;
Expand Down
15 changes: 7 additions & 8 deletions vortex-array/src/extension/datetime/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl ExtVTable for Date {
TimeUnit::try_from(tag)
}

fn validate_dtype(&self, ext_dtype: &ExtDType<Self>) -> VortexResult<()> {
fn validate_dtype(ext_dtype: &ExtDType<Self>) -> VortexResult<()> {
let metadata = ext_dtype.metadata();
let ptype = date_ptype(metadata)
.ok_or_else(|| vortex_err!("Date type does not support time unit {}", metadata))?;
Expand All @@ -106,7 +106,7 @@ impl ExtVTable for Date {
Ok(())
}

fn can_coerce_from(&self, ext_dtype: &ExtDType<Self>, other: &DType) -> bool {
fn can_coerce_from(ext_dtype: &ExtDType<Self>, other: &DType) -> bool {
let DType::Extension(other_ext) = other else {
return false;
};
Expand All @@ -118,7 +118,7 @@ impl ExtVTable for Date {
our_unit <= other_unit && (ext_dtype.storage_dtype().is_nullable() || !other.is_nullable())
}

fn least_supertype(&self, ext_dtype: &ExtDType<Self>, other: &DType) -> Option<DType> {
fn least_supertype(ext_dtype: &ExtDType<Self>, other: &DType) -> Option<DType> {
let DType::Extension(other_ext) = other else {
return None;
};
Expand All @@ -129,11 +129,10 @@ impl ExtVTable for Date {
Some(DType::Extension(Date::new(finest, union_null).erased()))
}

fn unpack_native(
&self,
ext_dtype: &ExtDType<Self>,
storage_value: &ScalarValue,
) -> VortexResult<Self::NativeValue<'_>> {
fn unpack_native<'a>(
ext_dtype: &'a ExtDType<Self>,
storage_value: &'a ScalarValue,
) -> VortexResult<Self::NativeValue<'a>> {
let metadata = ext_dtype.metadata();
match metadata {
TimeUnit::Milliseconds => Ok(DateValue::Milliseconds(
Expand Down
15 changes: 7 additions & 8 deletions vortex-array/src/extension/datetime/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl ExtVTable for Time {
TimeUnit::try_from(tag)
}

fn validate_dtype(&self, ext_dtype: &ExtDType<Self>) -> VortexResult<()> {
fn validate_dtype(ext_dtype: &ExtDType<Self>) -> VortexResult<()> {
let metadata = ext_dtype.metadata();
let ptype = time_ptype(metadata)
.ok_or_else(|| vortex_err!("Time type does not support time unit {}", metadata))?;
Expand All @@ -107,7 +107,7 @@ impl ExtVTable for Time {
Ok(())
}

fn can_coerce_from(&self, ext_dtype: &ExtDType<Self>, other: &DType) -> bool {
fn can_coerce_from(ext_dtype: &ExtDType<Self>, other: &DType) -> bool {
let DType::Extension(other_ext) = other else {
return false;
};
Expand All @@ -118,7 +118,7 @@ impl ExtVTable for Time {
our_unit <= other_unit && (ext_dtype.storage_dtype().is_nullable() || !other.is_nullable())
}

fn least_supertype(&self, ext_dtype: &ExtDType<Self>, other: &DType) -> Option<DType> {
fn least_supertype(ext_dtype: &ExtDType<Self>, other: &DType) -> Option<DType> {
let DType::Extension(other_ext) = other else {
return None;
};
Expand All @@ -129,11 +129,10 @@ impl ExtVTable for Time {
Some(DType::Extension(Time::new(finest, union_null).erased()))
}

fn unpack_native(
&self,
ext_dtype: &ExtDType<Self>,
storage_value: &ScalarValue,
) -> VortexResult<Self::NativeValue<'_>> {
fn unpack_native<'a>(
ext_dtype: &'a ExtDType<Self>,
storage_value: &'a ScalarValue,
) -> VortexResult<Self::NativeValue<'a>> {
let length_of_time = storage_value.as_primitive().cast::<i64>()?;

let (span, value) = match *ext_dtype.metadata() {
Expand Down
7 changes: 3 additions & 4 deletions vortex-array/src/extension/datetime/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl ExtVTable for Timestamp {
})
}

fn can_coerce_from(&self, ext_dtype: &ExtDType<Self>, other: &DType) -> bool {
fn can_coerce_from(ext_dtype: &ExtDType<Self>, other: &DType) -> bool {
let DType::Extension(other_ext) = other else {
return false;
};
Expand All @@ -182,7 +182,7 @@ impl ExtVTable for Timestamp {
&& (ext_dtype.storage_dtype().is_nullable() || !other.is_nullable())
}

fn least_supertype(&self, ext_dtype: &ExtDType<Self>, other: &DType) -> Option<DType> {
fn least_supertype(ext_dtype: &ExtDType<Self>, other: &DType) -> Option<DType> {
let DType::Extension(other_ext) = other else {
return None;
};
Expand All @@ -198,7 +198,7 @@ impl ExtVTable for Timestamp {
))
}

fn validate_dtype(&self, ext_dtype: &ExtDType<Self>) -> VortexResult<()> {
fn validate_dtype(ext_dtype: &ExtDType<Self>) -> VortexResult<()> {
vortex_ensure!(
matches!(ext_dtype.storage_dtype(), DType::Primitive(PType::I64, _)),
"Timestamp storage dtype must be i64"
Expand All @@ -207,7 +207,6 @@ impl ExtVTable for Timestamp {
}

fn unpack_native<'a>(
&self,
ext_dtype: &'a ExtDType<Self>,
storage_value: &'a ScalarValue,
) -> VortexResult<Self::NativeValue<'a>> {
Expand Down
9 changes: 3 additions & 6 deletions vortex-array/src/extension/tests/divisible_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use vortex_error::vortex_ensure;

use crate::dtype::DType;
use crate::dtype::PType;
use crate::dtype::extension::ExtDType;
use crate::dtype::extension::ExtId;
use crate::dtype::extension::ExtVTable;
use crate::scalar::ScalarValue;
Expand Down Expand Up @@ -51,10 +52,7 @@ impl ExtVTable for DivisibleInt {
Ok(Divisor(n))
}

fn validate_dtype(
&self,
ext_dtype: &crate::dtype::extension::ExtDType<Self>,
) -> VortexResult<()> {
fn validate_dtype(ext_dtype: &ExtDType<Self>) -> VortexResult<()> {
vortex_ensure!(
matches!(ext_dtype.storage_dtype(), DType::Primitive(PType::U64, _)),
"divisible int storage dtype must be u64"
Expand All @@ -63,8 +61,7 @@ impl ExtVTable for DivisibleInt {
}

fn unpack_native<'a>(
&self,
ext_dtype: &'a crate::dtype::extension::ExtDType<Self>,
ext_dtype: &'a ExtDType<Self>,
storage_value: &'a ScalarValue,
) -> VortexResult<Self::NativeValue<'a>> {
let value = storage_value.as_primitive().cast::<u64>()?;
Expand Down
11 changes: 5 additions & 6 deletions vortex-array/src/extension/uuid/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl ExtVTable for Uuid {
Ok(UuidMetadata { version })
}

fn validate_dtype(&self, ext_dtype: &ExtDType<Self>) -> VortexResult<()> {
fn validate_dtype(ext_dtype: &ExtDType<Self>) -> VortexResult<()> {
let storage_dtype = ext_dtype.storage_dtype();
let DType::FixedSizeList(element_dtype, list_size, _nullability) = storage_dtype else {
vortex_bail!("UUID storage dtype must be a FixedSizeList, got {storage_dtype}");
Expand Down Expand Up @@ -77,7 +77,6 @@ impl ExtVTable for Uuid {
}

fn unpack_native<'a>(
&self,
ext_dtype: &ExtDType<Self>,
storage_value: &'a ScalarValue,
) -> VortexResult<Self::NativeValue<'a>> {
Expand Down Expand Up @@ -248,7 +247,7 @@ mod tests {
let storage_value = storage_scalar
.value()
.ok_or_else(|| vortex_error::vortex_err!("expected non-null scalar"))?;
let result = Uuid.unpack_native(&ext_dtype, storage_value)?;
let result = Uuid::unpack_native(&ext_dtype, storage_value)?;
assert_eq!(result, expected);
assert_eq!(result.to_string(), "550e8400-e29b-41d4-a716-446655440000");
Ok(())
Expand Down Expand Up @@ -283,7 +282,7 @@ mod tests {
let storage_value = storage_scalar
.value()
.ok_or_else(|| vortex_error::vortex_err!("expected non-null scalar"))?;
assert!(Uuid.unpack_native(&ext_dtype, storage_value).is_err());
assert!(Uuid::unpack_native(&ext_dtype, storage_value).is_err());
Ok(())
}

Expand Down Expand Up @@ -317,7 +316,7 @@ mod tests {
.unwrap();
let storage_value = uuid_storage_scalar(&v4_uuid);

let result = Uuid.unpack_native(&ext_dtype, &storage_value)?;
let result = Uuid::unpack_native(&ext_dtype, &storage_value)?;
assert_eq!(result, v4_uuid);
Ok(())
}
Expand All @@ -335,7 +334,7 @@ mod tests {
.unwrap();
let storage_value = uuid_storage_scalar(&v4_uuid);

let result = Uuid.unpack_native(&ext_dtype, &storage_value)?;
let result = Uuid::unpack_native(&ext_dtype, &storage_value)?;
assert_eq!(result, v4_uuid);
Ok(())
}
Expand Down
9 changes: 3 additions & 6 deletions vortex-array/src/scalar/arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ mod tests {
use crate::dtype::Nullability;
use crate::dtype::PType;
use crate::dtype::StructFields;
use crate::dtype::extension::ExtDType;
use crate::dtype::extension::ExtId;
use crate::dtype::extension::ExtVTable;
use crate::dtype::i256;
Expand Down Expand Up @@ -465,16 +466,12 @@ mod tests {
vortex_bail!("not implemented")
}

fn validate_dtype(
&self,
_ext_dtype: &crate::dtype::extension::ExtDType<Self>,
) -> VortexResult<()> {
fn validate_dtype(_ext_dtype: &ExtDType<Self>) -> VortexResult<()> {
Ok(())
}

fn unpack_native<'a>(
&self,
_ext_dtype: &'a crate::dtype::extension::ExtDType<Self>,
_ext_dtype: &'a ExtDType<Self>,
_storage_value: &'a ScalarValue,
) -> VortexResult<Self::NativeValue<'a>> {
Ok("")
Expand Down
Loading
Loading