Skip to content

Commit

Permalink
nullable scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
gatesn committed Mar 26, 2024
1 parent a5bc6b4 commit b598666
Showing 2 changed files with 9 additions and 27 deletions.
16 changes: 5 additions & 11 deletions vortex-array/src/scalar/primitive.rs
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ use crate::scalar::Scalar;
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct PrimitiveScalar {
ptype: PType,
dtype: DType,
nullability: Nullability,
value: Option<PScalar>,
}
@@ -24,6 +25,7 @@ impl PrimitiveScalar {
}
Ok(Self {
ptype: T::PTYPE,
dtype: DType::from(T::PTYPE).with_nullability(nullability),
nullability,
value: value.map(|v| Into::<PScalar>::into(v)),
})
@@ -34,19 +36,11 @@ impl PrimitiveScalar {
}

pub fn some<T: NativePType>(value: T) -> Self {
Self {
ptype: T::PTYPE,
nullability: Nullability::default(),
value: Some(Into::<PScalar>::into(value)),
}
Self::new::<T>(Some(value), Nullability::default()).unwrap()
}

pub fn none<T: NativePType>() -> Self {
Self {
ptype: T::PTYPE,
nullability: Nullability::Nullable,
value: None,
}
Self::new::<T>(None, Nullability::Nullable).unwrap()
}

#[inline]
@@ -61,7 +55,7 @@ impl PrimitiveScalar {

#[inline]
pub fn dtype(&self) -> &DType {
self.ptype.into()
&self.dtype
}

pub fn cast(&self, dtype: &DType) -> VortexResult<Scalar> {
20 changes: 4 additions & 16 deletions vortex-array/src/scalar/value.rs
Original file line number Diff line number Diff line change
@@ -16,31 +16,19 @@ impl<T> ScalarValue<T> {
}

pub fn non_nullable(value: T) -> Self {
Self {
value: Some(value),
nullability: Nullability::NonNullable,
}
Self::new(Some(value), Nullability::NonNullable).unwrap()
}

pub fn nullable(value: T) -> Self {
Self {
value: Some(value),
nullability: Nullability::Nullable,
}
Self::new(Some(value), Nullability::Nullable).unwrap()
}

pub fn some(value: T) -> Self {
Self {
value: Some(value),
nullability: Nullability::default(),
}
Self::new(Some(value), Nullability::default()).unwrap()
}

pub fn none() -> Self {
Self {
value: None,
nullability: Nullability::Nullable,
}
Self::new(None, Nullability::Nullable).unwrap()
}

pub fn value(&self) -> Option<&T> {

0 comments on commit b598666

Please sign in to comment.