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