diff --git a/vortex-array/src/scalar/primitive.rs b/vortex-array/src/scalar/primitive.rs index 31c026fdc4..73eda83c4f 100644 --- a/vortex-array/src/scalar/primitive.rs +++ b/vortex-array/src/scalar/primitive.rs @@ -13,6 +13,7 @@ use crate::scalar::Scalar; #[derive(Debug, Clone, PartialEq, PartialOrd)] pub struct PrimitiveScalar { ptype: PType, + dtype: DType, nullability: Nullability, value: Option, } @@ -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::::into(v)), }) @@ -34,19 +36,11 @@ impl PrimitiveScalar { } pub fn some(value: T) -> Self { - Self { - ptype: T::PTYPE, - nullability: Nullability::default(), - value: Some(Into::::into(value)), - } + Self::new::(Some(value), Nullability::default()).unwrap() } pub fn none() -> Self { - Self { - ptype: T::PTYPE, - nullability: Nullability::Nullable, - value: None, - } + Self::new::(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 { diff --git a/vortex-array/src/scalar/value.rs b/vortex-array/src/scalar/value.rs index 1b938f9165..6a014b57f5 100644 --- a/vortex-array/src/scalar/value.rs +++ b/vortex-array/src/scalar/value.rs @@ -16,31 +16,19 @@ impl ScalarValue { } 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> {