pub fn make_union_array(
union_fields: UnionFields,
children: Vec<ArrayRef>,
) -> ArrowResult<ArrayRef>Examples found in repository?
examples/message_impl.rs (lines 41-48)
38 fn try_into_arrow(self) -> ArrowResult<ArrayRef> {
39 let union_fields = get_union_fields::<Self>()?;
40
41 make_union_array(
42 union_fields,
43 vec![
44 self.name.try_into_arrow()?,
45 self.width.try_into_arrow()?,
46 self.height.try_into_arrow()?,
47 ],
48 )
49 }
50}
51
52impl TryFrom<ArrayData> for Metadata {
53 type Error = ArrowError;
54
55 fn try_from(data: ArrayData) -> ArrowResult<Self> {
56 Metadata::try_from_arrow(data)
57 }
58}
59
60impl TryFrom<Metadata> for ArrayData {
61 type Error = ArrowError;
62
63 fn try_from(metadata: Metadata) -> ArrowResult<Self> {
64 metadata.try_into_arrow().map(|array| array.into_data())
65 }
66}
67
68#[derive(Debug)]
69struct Image {
70 data: UInt8Array,
71 metadata: Option<Metadata>,
72}
73
74impl ArrowMessage for Image {
75 fn field(name: impl Into<String>) -> Field {
76 make_union_fields(
77 name,
78 vec![
79 UInt8Array::field("data"),
80 Option::<Metadata>::field("metadata"),
81 ],
82 )
83 }
84
85 fn try_from_arrow(data: ArrayData) -> ArrowResult<Self>
86 where
87 Self: Sized,
88 {
89 let (map, children) = unpack_union(data);
90
91 Ok(Image {
92 data: extract_union_data("data", &map, &children)?,
93 metadata: extract_union_data("metadata", &map, &children)?,
94 })
95 }
96
97 fn try_into_arrow(self) -> ArrowResult<ArrayRef> {
98 let union_fields = get_union_fields::<Self>()?;
99
100 make_union_array(
101 union_fields,
102 vec![self.data.try_into_arrow()?, self.metadata.try_into_arrow()?],
103 )
104 }More examples
examples/message_enum_impl.rs (lines 107-115)
104 fn try_into_arrow(self) -> ArrowResult<ArrayRef> {
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) -> ArrowResult<Self> {
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) -> ArrowResult<Self> {
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: ArrayData) -> ArrowResult<Self>
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) -> ArrowResult<ArrayRef> {
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 }