diff --git a/vortex-array/src/array/constant/compute/binary_numeric.rs b/vortex-array/src/array/constant/compute/binary_numeric.rs index 10cc6dadf..b7994b216 100644 --- a/vortex-array/src/array/constant/compute/binary_numeric.rs +++ b/vortex-array/src/array/constant/compute/binary_numeric.rs @@ -22,8 +22,7 @@ impl BinaryNumericFn for ConstantEncoding { .scalar() .as_primitive() .checked_numeric_operator(rhs.as_primitive(), op)? - .ok_or_else(|| vortex_err!("numeric overflow"))? - .to_scalar(), + .ok_or_else(|| vortex_err!("numeric overflow"))?, array.len(), ) .into_array(), diff --git a/vortex-array/src/array/sparse/compute/binary_numeric.rs b/vortex-array/src/array/sparse/compute/binary_numeric.rs index b58225728..5795406df 100644 --- a/vortex-array/src/array/sparse/compute/binary_numeric.rs +++ b/vortex-array/src/array/sparse/compute/binary_numeric.rs @@ -24,7 +24,7 @@ impl BinaryNumericFn for SparseEncoding { .as_primitive() .checked_numeric_operator(rhs_scalar.as_primitive(), op)? .ok_or_else(|| vortex_err!("numeric overflow"))? - .to_scalar(); + .into(); SparseArray::try_new_from_patches( new_patches, array.len(), diff --git a/vortex-scalar/src/lib.rs b/vortex-scalar/src/lib.rs index 7514d8375..16d71970a 100644 --- a/vortex-scalar/src/lib.rs +++ b/vortex-scalar/src/lib.rs @@ -241,6 +241,17 @@ where } } +impl From> for Scalar { + fn from(pscalar: PrimitiveScalar) -> Self { + let dtype = pscalar.dtype().clone(); + let value = pscalar + .pvalue() + .map(|pvalue| ScalarValue(InnerScalarValue::Primitive(pvalue))) + .unwrap_or_else(|| ScalarValue(InnerScalarValue::Null)); + Self::new(dtype, value) + } +} + macro_rules! from_vec_for_scalar { ($T:ty) => { impl From> for Scalar { diff --git a/vortex-scalar/src/primitive.rs b/vortex-scalar/src/primitive.rs index f14fc8e94..6b9760152 100644 --- a/vortex-scalar/src/primitive.rs +++ b/vortex-scalar/src/primitive.rs @@ -49,6 +49,11 @@ impl<'a> PrimitiveScalar<'a> { self.ptype } + #[inline] + pub fn pvalue(&self) -> Option { + self.pvalue + } + pub fn typed_value>(&self) -> Option { assert_eq!( self.ptype, @@ -109,15 +114,6 @@ impl<'a> PrimitiveScalar<'a> { pub fn checked_sub(self, other: PrimitiveScalar<'a>) -> VortexResult> { self.checked_numeric_operator(other, BinaryNumericOperator::Sub) } - - pub fn to_scalar(self) -> Scalar { - Scalar::new( - self.dtype().clone(), - self.pvalue - .map(|pvalue| ScalarValue(InnerScalarValue::Primitive(pvalue))) - .unwrap_or_else(|| ScalarValue(InnerScalarValue::Null)), - ) - } } pub trait FromPrimitiveOrF16: FromPrimitive {