1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use std::any::Any;

use crate::array::{Array, MutableArray, NullArray};
use crate::bitmap::MutableBitmap;
use crate::datatypes::ArrowDataType;

#[derive(Debug, Default, Clone)]
pub struct MutableNullArray {
    len: usize,
}

impl MutableArray for MutableNullArray {
    fn data_type(&self) -> &ArrowDataType {
        &ArrowDataType::Null
    }

    fn len(&self) -> usize {
        self.len
    }

    fn validity(&self) -> Option<&MutableBitmap> {
        None
    }

    fn as_box(&mut self) -> Box<dyn Array> {
        Box::new(NullArray::new_null(ArrowDataType::Null, self.len))
    }

    fn as_any(&self) -> &dyn Any {
        self
    }

    fn as_mut_any(&mut self) -> &mut dyn Any {
        self
    }

    fn push_null(&mut self) {
        self.len += 1;
    }

    fn reserve(&mut self, _additional: usize) {
        // no-op
    }

    fn shrink_to_fit(&mut self) {
        // no-op
    }
}

impl MutableNullArray {
    pub fn new(len: usize) -> Self {
        MutableNullArray { len }
    }

    pub fn extend_nulls(&mut self, null_count: usize) {
        self.len += null_count;
    }
}