Skip to main content

ExtVTable

Trait ExtVTable 

Source
pub trait ExtVTable:
    Sized
    + 'static
    + Send
    + Sync
    + Clone
    + Debug
    + Eq
    + Hash {
    type Metadata: 'static + Send + Sync + Clone + Debug + Display + Eq + Hash;
    type NativeValue<'a>: Display;

    // Required methods
    fn id(&self) -> Id;
    fn serialize_metadata(
        &self,
        metadata: &Self::Metadata,
    ) -> Result<Vec<u8>, VortexError>;
    fn deserialize_metadata(
        &self,
        metadata: &[u8],
    ) -> Result<Self::Metadata, VortexError>;
    fn validate_dtype(ext_dtype: &ExtDType<Self>) -> Result<(), VortexError>;
    fn unpack_native<'a>(
        ext_dtype: &'a ExtDType<Self>,
        storage_value: &'a ScalarValue,
    ) -> Result<Self::NativeValue<'a>, VortexError>;

    // Provided methods
    fn can_coerce_from(ext_dtype: &ExtDType<Self>, other: &DType) -> bool { ... }
    fn can_coerce_to(ext_dtype: &ExtDType<Self>, other: &DType) -> bool { ... }
    fn least_supertype(
        ext_dtype: &ExtDType<Self>,
        other: &DType,
    ) -> Option<DType> { ... }
    fn validate_scalar_value(
        ext_dtype: &ExtDType<Self>,
        storage_value: &ScalarValue,
    ) -> Result<(), VortexError> { ... }
}
Expand description

The public API for defining new extension types.

This is the non-object-safe trait that plugin authors implement to define a new extension type. It specifies the type’s identity, metadata, serialization, and validation.

Required Associated Types§

Source

type Metadata: 'static + Send + Sync + Clone + Debug + Display + Eq + Hash

Associated type containing the deserialized metadata for this extension type.

Source

type NativeValue<'a>: Display

A native Rust value that represents a scalar of the extension type.

The value only represents non-null values. We denote nullable values as Option<Value>.

Required Methods§

Source

fn id(&self) -> Id

Returns the ID for this extension type.

Source

fn serialize_metadata( &self, metadata: &Self::Metadata, ) -> Result<Vec<u8>, VortexError>

Serialize the metadata into a byte vector.

Source

fn deserialize_metadata( &self, metadata: &[u8], ) -> Result<Self::Metadata, VortexError>

Deserialize the metadata from a byte slice.

Source

fn validate_dtype(ext_dtype: &ExtDType<Self>) -> Result<(), VortexError>

Validate that the given storage type is compatible with this extension type.

Source

fn unpack_native<'a>( ext_dtype: &'a ExtDType<Self>, storage_value: &'a ScalarValue, ) -> Result<Self::NativeValue<'a>, VortexError>

Validate and unpack a native value from the storage ScalarValue.

Note that ExtVTable::validate_dtype() is always called first to validate the storage crate::dtype::DType, and the Scalar implementation will verify that the storage value is compatible with the storage dtype on construction.

§Errors

Returns an error if the storage ScalarValue is not compatible with the extension type.

Provided Methods§

Source

fn can_coerce_from(ext_dtype: &ExtDType<Self>, other: &DType) -> bool

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. We have both so that either side of the coercion can provide the logic.

Source

fn can_coerce_to(ext_dtype: &ExtDType<Self>, other: &DType) -> bool

Can this type be implicitly widened into other?

Implementors only need to override one of can_coerce_from or can_coerce_to. We have both so that either side of the coercion can provide the logic.

Source

fn least_supertype(ext_dtype: &ExtDType<Self>, other: &DType) -> Option<DType>

Given two types in a Uniform context, what is their least supertype?

Return None if no supertype exists.

Source

fn validate_scalar_value( ext_dtype: &ExtDType<Self>, storage_value: &ScalarValue, ) -> Result<(), VortexError>

Validate the given storage value is compatible with the extension type.

By default, this calls unpack_native() and discards the result.

§Errors

Returns an error if the storage ScalarValue is not compatible with the extension type.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl ExtVTable for FixedShapeTensor

Source§

impl ExtVTable for Vector

Implementors§