vortex_compute/cast/
null.rs1use vortex_dtype::DType;
5use vortex_error::VortexResult;
6use vortex_error::vortex_bail;
7use vortex_vector::Scalar;
8use vortex_vector::Vector;
9use vortex_vector::VectorMut;
10use vortex_vector::VectorMutOps;
11use vortex_vector::VectorOps;
12use vortex_vector::null::NullScalar;
13use vortex_vector::null::NullVector;
14
15use crate::cast::Cast;
16
17impl Cast for NullVector {
18 type Output = Vector;
19
20 fn cast(&self, target_dtype: &DType) -> VortexResult<Vector> {
22 if target_dtype.is_nullable() {
23 let mut vec = VectorMut::with_capacity(target_dtype, self.len());
25 vec.append_nulls(self.len());
26 Ok(vec.freeze())
27 } else {
28 vortex_bail!(
29 "Cannot cast NullVector to non-nullable type {}",
30 target_dtype
31 );
32 }
33 }
34}
35
36impl Cast for NullScalar {
37 type Output = Scalar;
38
39 fn cast(&self, target_dtype: &DType) -> VortexResult<Scalar> {
41 if target_dtype.is_nullable() {
42 Ok(Scalar::null(target_dtype))
43 } else {
44 vortex_bail!(
45 "Cannot cast NullScalar to non-nullable type {}",
46 target_dtype
47 );
48 }
49 }
50}