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