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