Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-arrow/src/scalar/union.rs
6939 views
1
use super::Scalar;
2
use crate::datatypes::ArrowDataType;
3
4
/// A single entry of a [`crate::array::UnionArray`].
5
#[derive(Debug, Clone, PartialEq)]
6
pub struct UnionScalar {
7
value: Box<dyn Scalar>,
8
type_: i8,
9
dtype: ArrowDataType,
10
}
11
12
impl UnionScalar {
13
/// Returns a new [`UnionScalar`]
14
#[inline]
15
pub fn new(dtype: ArrowDataType, type_: i8, value: Box<dyn Scalar>) -> Self {
16
Self {
17
value,
18
type_,
19
dtype,
20
}
21
}
22
23
/// Returns the inner value
24
#[inline]
25
pub fn value(&self) -> &Box<dyn Scalar> {
26
&self.value
27
}
28
29
/// Returns the type of the union scalar
30
#[inline]
31
pub fn type_(&self) -> i8 {
32
self.type_
33
}
34
}
35
36
impl Scalar for UnionScalar {
37
#[inline]
38
fn as_any(&self) -> &dyn std::any::Any {
39
self
40
}
41
42
#[inline]
43
fn is_valid(&self) -> bool {
44
true
45
}
46
47
#[inline]
48
fn dtype(&self) -> &ArrowDataType {
49
&self.dtype
50
}
51
}
52
53