vortex_array/arrays/null/
plugin.rs1use vortex_error::VortexResult;
7use vortex_error::vortex_ensure;
8use vortex_error::vortex_ensure_eq;
9use vortex_session::VortexSession;
10
11use crate::Array;
12use crate::ArrayDeserialization;
13use crate::ArrayId;
14use crate::ArrayParts;
15use crate::ArrayPlugin;
16use crate::ArrayRef;
17use crate::ArraySerialization;
18use crate::ArraySlots;
19use crate::IntoArray;
20use crate::VTable;
21use crate::array::EmptyArrayData;
22use crate::arrays::Null;
23
24impl ArrayPlugin for Null {
25 fn id(&self) -> ArrayId {
26 VTable::id(self)
27 }
28
29 fn serialize(
30 &self,
31 array: &ArrayRef,
32 _session: &VortexSession,
33 ) -> VortexResult<Option<ArraySerialization>> {
34 vortex_ensure_eq!(
35 array.encoding_id(),
36 ArrayPlugin::id(self),
37 "Null plugin cannot serialize an array of another encoding",
38 );
39 Ok(Some(ArraySerialization::from_array(
40 ArrayPlugin::id(self),
41 array,
42 vec![],
43 )))
44 }
45
46 fn deserialize(
47 &self,
48 parts: ArrayDeserialization<'_>,
49 _session: &VortexSession,
50 ) -> VortexResult<ArrayRef> {
51 vortex_ensure_eq!(
52 parts.serialized_id,
53 ArrayPlugin::id(self),
54 "Null plugin does not recognize the serialized ID",
55 );
56 let ArrayDeserialization {
57 dtype,
58 len,
59 metadata,
60 ..
61 } = parts;
62 vortex_ensure!(
63 metadata.is_empty(),
64 "NullArray expects empty metadata, got {} bytes",
65 metadata.len()
66 );
67 Ok(Array::try_from_parts(ArrayParts::new(
68 self.clone(),
69 dtype.clone(),
70 len,
71 EmptyArrayData,
72 ArraySlots::new(),
73 ))?
74 .into_array())
75 }
76}