vortex_array/arrays/null/
mod.rs

1use vortex_dtype::DType;
2use vortex_error::VortexResult;
3use vortex_mask::Mask;
4
5use crate::serde::ArrayParts;
6use crate::stats::{ArrayStats, StatsSetRef};
7use crate::variants::NullArrayTrait;
8use crate::vtable::{EncodingVTable, VTableRef};
9use crate::{
10    Array, ArrayCanonicalImpl, ArrayContext, ArrayImpl, ArrayRef, ArrayStatisticsImpl,
11    ArrayValidityImpl, ArrayVariantsImpl, ArrayVisitorImpl, Canonical, EmptyMetadata, Encoding,
12    EncodingId,
13};
14
15mod compute;
16
17#[derive(Clone, Debug)]
18pub struct NullArray {
19    len: usize,
20    stats_set: ArrayStats,
21}
22
23#[derive(Debug)]
24pub struct NullEncoding;
25impl Encoding for NullEncoding {
26    type Array = NullArray;
27    type Metadata = EmptyMetadata;
28}
29
30impl EncodingVTable for NullEncoding {
31    fn id(&self) -> EncodingId {
32        EncodingId::new_ref("vortex.null")
33    }
34
35    fn decode(
36        &self,
37        _parts: &ArrayParts,
38        _ctx: &ArrayContext,
39        _dtype: DType,
40        len: usize,
41    ) -> VortexResult<ArrayRef> {
42        Ok(NullArray::new(len).into_array())
43    }
44}
45
46impl ArrayVisitorImpl for NullArray {
47    fn _metadata(&self) -> EmptyMetadata {
48        EmptyMetadata
49    }
50}
51
52impl NullArray {
53    pub fn new(len: usize) -> Self {
54        Self {
55            len,
56            stats_set: Default::default(),
57        }
58    }
59}
60
61impl ArrayImpl for NullArray {
62    type Encoding = NullEncoding;
63
64    fn _len(&self) -> usize {
65        self.len
66    }
67
68    fn _dtype(&self) -> &DType {
69        &DType::Null
70    }
71
72    fn _vtable(&self) -> VTableRef {
73        VTableRef::new_ref(&NullEncoding)
74    }
75
76    fn _with_children(&self, _children: &[ArrayRef]) -> VortexResult<Self> {
77        Ok(self.clone())
78    }
79}
80
81impl ArrayStatisticsImpl for NullArray {
82    fn _stats_ref(&self) -> StatsSetRef<'_> {
83        self.stats_set.to_ref(self)
84    }
85}
86
87impl ArrayCanonicalImpl for NullArray {
88    fn _to_canonical(&self) -> VortexResult<Canonical> {
89        Ok(Canonical::Null(self.clone()))
90    }
91}
92
93impl ArrayValidityImpl for NullArray {
94    fn _is_valid(&self, _index: usize) -> VortexResult<bool> {
95        Ok(false)
96    }
97
98    fn _all_valid(&self) -> VortexResult<bool> {
99        Ok(self.is_empty())
100    }
101
102    fn _all_invalid(&self) -> VortexResult<bool> {
103        Ok(!self.is_empty())
104    }
105
106    fn _validity_mask(&self) -> VortexResult<Mask> {
107        Ok(Mask::AllFalse(self.len))
108    }
109}
110
111impl ArrayVariantsImpl for NullArray {
112    fn _as_null_typed(&self) -> Option<&dyn NullArrayTrait> {
113        Some(self)
114    }
115}
116
117impl NullArrayTrait for NullArray {}