Skip to content

Extension Scalars#6477

Draft
connortsui20 wants to merge 2 commits intodevelopfrom
ct/ext-scalar
Draft

Extension Scalars#6477
connortsui20 wants to merge 2 commits intodevelopfrom
ct/ext-scalar

Conversation

@connortsui20
Copy link
Contributor

@connortsui20 connortsui20 commented Feb 12, 2026

TODO

Right now this doesn't compile because it is blocked on a few other things. The tests in vortex-scalar do pass though (when it does compile), so not everything is terrible

@connortsui20 connortsui20 requested a review from gatesn February 12, 2026 20:55
@connortsui20 connortsui20 added the changelog/break A breaking API change label Feb 12, 2026
Copy link
Contributor

@gatesn gatesn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have a think about how we can attach logic to the ExtDTypeVTable such that we don't need to provide the session if we already have a DType

/// Unlike [`try_downcast`], this borrows rather than consuming `self`.
///
/// [`try_downcast`]: ExtScalarValueRef::try_downcast
pub fn try_get_vtable<V: ExtScalarVTable>(&self) -> Option<&V> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be keen to try and remove functions like this, they're probably superfluous / not called?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case this is now a helper function for the matcher. I'll leave it in for now and we can remove it if it makes more sense

///
/// Note that this is not strictly necessary since [`ExtScalarValueAdapter`] and
/// [`ExtScalarValueAdapterImpl`] are both private to this module, this is just for hygiene.
mod sealed {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You added sealed for scalars, but removed it for dtypes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo we should probably seal the dtype one as well

mod bool;
mod decimal;
mod extension;
mod ext;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the name change? Needless API churn

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not public (everything is re-exported) so there's no change. I wanted to make a distinction between this and the extension module that contains all the vtable logic.

}

#[test]
#[should_panic(expected = "Cannot convert extension scalar")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should still panic shouldn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now just doesn't even compile so unless we want to put it in a doctest (which I think it kind of pointless) we can just delete it.

pub fn extension<V: ExtScalarVTable + Default>(metadata: V::Metadata, value: Scalar) -> Self {
let ext_dtype = ExtDType::<V>::try_new(metadata, value.dtype().clone())
.vortex_expect("Failed to create extension dtype");
let storage_value = value.into_value();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can value.into_parts() to avoid the dtype clone above.
Also rename value -> storage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dtype is the extension dtype, into_parts would give the storage dtype

/// # Errors
///
/// Returns an error if the given [`DType`] and [`ScalarValue`] are incompatible.
pub fn validate(dtype: &DType, value: Option<&ScalarValue>) -> VortexResult<()> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious if this actually needs to be public

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question 🤔

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/break A breaking API change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants