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