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