Function make_union_array

Source
pub fn make_union_array(
    union_fields: UnionFields,
    children: Vec<ArrayRef>,
) -> Result<ArrayRef, ArrowError>
Examples found in repository?
examples/impl.rs (lines 39-46)
36    fn try_into_arrow(self) -> Result<arrow::array::ArrayRef, ArrowError> {
37        let union_fields = get_union_fields::<Self>()?;
38
39        make_union_array(
40            union_fields,
41            vec![
42                self.name.try_into_arrow()?,
43                self.width.try_into_arrow()?,
44                self.height.try_into_arrow()?,
45            ],
46        )
47    }
48}
49
50impl TryFrom<ArrayData> for Metadata {
51    type Error = ArrowError;
52
53    fn try_from(data: ArrayData) -> Result<Self, Self::Error> {
54        Metadata::try_from_arrow(data)
55    }
56}
57
58impl TryFrom<Metadata> for ArrayData {
59    type Error = ArrowError;
60
61    fn try_from(metadata: Metadata) -> Result<Self, Self::Error> {
62        metadata.try_into_arrow().map(|array| array.into_data())
63    }
64}
65
66#[derive(Debug)]
67struct Image {
68    data: UInt8Array,
69    metadata: Option<Metadata>,
70}
71
72impl ArrowMessage for Image {
73    fn field(name: impl Into<String>) -> Field {
74        make_union_fields(
75            name,
76            vec![
77                UInt8Array::field("data"),
78                Option::<Metadata>::field("metadata"),
79            ],
80        )
81    }
82
83    fn try_from_arrow(data: arrow::array::ArrayData) -> Result<Self, ArrowError>
84    where
85        Self: Sized,
86    {
87        let (map, children) = unpack_union(data);
88
89        Ok(Image {
90            data: extract_union_data("data", &map, &children)?,
91            metadata: extract_union_data("metadata", &map, &children)?,
92        })
93    }
94
95    fn try_into_arrow(self) -> Result<arrow::array::ArrayRef, ArrowError> {
96        let union_fields = get_union_fields::<Self>()?;
97
98        make_union_array(
99            union_fields,
100            vec![self.data.try_into_arrow()?, self.metadata.try_into_arrow()?],
101        )
102    }
More examples
Hide additional examples
examples/enum_impl.rs (lines 107-115)
104    fn try_into_arrow(self) -> Result<arrow::array::ArrayRef, ArrowError> {
105        let union_fields = get_union_fields::<Self>()?;
106
107        make_union_array(
108            union_fields,
109            vec![
110                self.name.try_into_arrow()?,
111                self.width.try_into_arrow()?,
112                self.height.try_into_arrow()?,
113                self.encoding.try_into_arrow()?,
114            ],
115        )
116    }
117}
118
119impl TryFrom<ArrayData> for Metadata {
120    type Error = ArrowError;
121
122    fn try_from(data: ArrayData) -> Result<Self, Self::Error> {
123        Metadata::try_from_arrow(data)
124    }
125}
126
127impl TryFrom<Metadata> for ArrayData {
128    type Error = ArrowError;
129
130    fn try_from(metadata: Metadata) -> Result<Self, Self::Error> {
131        metadata.try_into_arrow().map(|array| array.into_data())
132    }
133}
134
135#[derive(Debug)]
136struct Image {
137    data: UInt8Array,
138    metadata: Option<Metadata>,
139}
140
141impl ArrowMessage for Image {
142    fn field(name: impl Into<String>) -> Field {
143        make_union_fields(
144            name,
145            vec![
146                UInt8Array::field("data"),
147                Option::<Metadata>::field("metadata"),
148            ],
149        )
150    }
151
152    fn try_from_arrow(data: arrow::array::ArrayData) -> Result<Self, ArrowError>
153    where
154        Self: Sized,
155    {
156        let (map, children) = unpack_union(data);
157
158        Ok(Image {
159            data: extract_union_data("data", &map, &children)?,
160            metadata: extract_union_data("metadata", &map, &children)?,
161        })
162    }
163
164    fn try_into_arrow(self) -> Result<arrow::array::ArrayRef, ArrowError> {
165        let union_fields = get_union_fields::<Self>()?;
166
167        make_union_array(
168            union_fields,
169            vec![self.data.try_into_arrow()?, self.metadata.try_into_arrow()?],
170        )
171    }