vortex_array/arrays/null/
mod.rs1use vortex_buffer::ByteBuffer;
2use vortex_dtype::DType;
3use vortex_error::VortexResult;
4use vortex_mask::Mask;
5use vortex_scalar::Scalar;
6
7use crate::serde::ArrayChildren;
8use crate::stats::{ArrayStats, StatsSetRef};
9use crate::vtable::{
10 ArrayVTable, CanonicalVTable, NotSupported, OperationsVTable, SerdeVTable, VTable,
11 ValidityVTable, VisitorVTable,
12};
13use crate::{
14 ArrayBufferVisitor, ArrayChildVisitor, ArrayRef, Canonical, EmptyMetadata, EncodingId,
15 EncodingRef, IntoArray, vtable,
16};
17
18mod compute;
19
20vtable!(Null);
21
22impl VTable for NullVTable {
23 type Array = NullArray;
24 type Encoding = NullEncoding;
25
26 type ArrayVTable = Self;
27 type CanonicalVTable = Self;
28 type OperationsVTable = Self;
29 type ValidityVTable = Self;
30 type VisitorVTable = Self;
31 type ComputeVTable = NotSupported;
32 type EncodeVTable = NotSupported;
33 type SerdeVTable = Self;
34
35 fn id(_encoding: &Self::Encoding) -> EncodingId {
36 EncodingId::new_ref("vortex.null")
37 }
38
39 fn encoding(_array: &Self::Array) -> EncodingRef {
40 EncodingRef::new_ref(NullEncoding.as_ref())
41 }
42}
43
44#[derive(Clone, Debug)]
45pub struct NullArray {
46 len: usize,
47 stats_set: ArrayStats,
48}
49
50#[derive(Clone, Debug)]
51pub struct NullEncoding;
52
53impl NullArray {
54 pub fn new(len: usize) -> Self {
55 Self {
56 len,
57 stats_set: Default::default(),
58 }
59 }
60}
61
62impl ArrayVTable<NullVTable> for NullVTable {
63 fn len(array: &NullArray) -> usize {
64 array.len
65 }
66
67 fn dtype(_array: &NullArray) -> &DType {
68 &DType::Null
69 }
70
71 fn stats(array: &NullArray) -> StatsSetRef<'_> {
72 array.stats_set.to_ref(array.as_ref())
73 }
74}
75
76impl SerdeVTable<NullVTable> for NullVTable {
77 type Metadata = EmptyMetadata;
78
79 fn metadata(_array: &NullArray) -> VortexResult<Option<Self::Metadata>> {
80 Ok(Some(EmptyMetadata))
81 }
82
83 fn build(
84 _encoding: &NullEncoding,
85 _dtype: &DType,
86 len: usize,
87 _metadata: &Self::Metadata,
88 _buffers: &[ByteBuffer],
89 _children: &dyn ArrayChildren,
90 ) -> VortexResult<NullArray> {
91 Ok(NullArray::new(len))
92 }
93}
94
95impl VisitorVTable<NullVTable> for NullVTable {
96 fn visit_buffers(_array: &NullArray, _visitor: &mut dyn ArrayBufferVisitor) {}
97
98 fn visit_children(_array: &NullArray, _visitor: &mut dyn ArrayChildVisitor) {}
99}
100
101impl CanonicalVTable<NullVTable> for NullVTable {
102 fn canonicalize(array: &NullArray) -> VortexResult<Canonical> {
103 Ok(Canonical::Null(array.clone()))
104 }
105}
106
107impl OperationsVTable<NullVTable> for NullVTable {
108 fn slice(_array: &NullArray, start: usize, stop: usize) -> VortexResult<ArrayRef> {
109 Ok(NullArray::new(stop - start).into_array())
110 }
111
112 fn scalar_at(_array: &NullArray, _index: usize) -> VortexResult<Scalar> {
113 Ok(Scalar::null(DType::Null))
114 }
115}
116
117impl ValidityVTable<NullVTable> for NullVTable {
118 fn is_valid(_array: &NullArray, _index: usize) -> VortexResult<bool> {
119 Ok(false)
120 }
121
122 fn all_valid(array: &NullArray) -> VortexResult<bool> {
123 Ok(array.is_empty())
124 }
125
126 fn all_invalid(array: &NullArray) -> VortexResult<bool> {
127 Ok(!array.is_empty())
128 }
129
130 fn validity_mask(array: &NullArray) -> VortexResult<Mask> {
131 Ok(Mask::AllFalse(array.len))
132 }
133}