vortex_array/builders/
null.rs

1use std::any::Any;
2
3use vortex_dtype::DType;
4use vortex_error::VortexResult;
5
6use crate::arrays::NullArray;
7use crate::builders::ArrayBuilder;
8use crate::{Array, ArrayRef};
9
10pub struct NullBuilder {
11    length: usize,
12}
13
14impl Default for NullBuilder {
15    fn default() -> Self {
16        Self::new()
17    }
18}
19
20impl NullBuilder {
21    pub fn new() -> Self {
22        Self { length: 0 }
23    }
24}
25
26impl ArrayBuilder for NullBuilder {
27    fn as_any(&self) -> &dyn Any {
28        self
29    }
30
31    fn as_any_mut(&mut self) -> &mut dyn Any {
32        self
33    }
34
35    fn dtype(&self) -> &DType {
36        &DType::Null
37    }
38
39    fn len(&self) -> usize {
40        self.length
41    }
42
43    fn append_zeros(&mut self, n: usize) {
44        self.length += n;
45    }
46
47    fn append_nulls(&mut self, n: usize) {
48        self.length += n;
49    }
50
51    fn extend_from_array(&mut self, array: &dyn Array) -> VortexResult<()> {
52        assert_eq!(array.dtype(), &DType::Null);
53        self.append_nulls(array.len());
54        Ok(())
55    }
56
57    fn finish(&mut self) -> ArrayRef {
58        NullArray::new(self.length).into_array()
59    }
60}