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
use super::Scalar;
use crate::datatypes::ArrowDataType;

/// A single entry of a [`crate::array::UnionArray`].
#[derive(Debug, Clone, PartialEq)]
pub struct UnionScalar {
    value: Box<dyn Scalar>,
    type_: i8,
    data_type: ArrowDataType,
}

impl UnionScalar {
    /// Returns a new [`UnionScalar`]
    #[inline]
    pub fn new(data_type: ArrowDataType, type_: i8, value: Box<dyn Scalar>) -> Self {
        Self {
            value,
            type_,
            data_type,
        }
    }

    /// Returns the inner value
    #[inline]
    pub fn value(&self) -> &Box<dyn Scalar> {
        &self.value
    }

    /// Returns the type of the union scalar
    #[inline]
    pub fn type_(&self) -> i8 {
        self.type_
    }
}

impl Scalar for UnionScalar {
    #[inline]
    fn as_any(&self) -> &dyn std::any::Any {
        self
    }

    #[inline]
    fn is_valid(&self) -> bool {
        true
    }

    #[inline]
    fn data_type(&self) -> &ArrowDataType {
        &self.data_type
    }
}