@@ -159,13 +159,13 @@ impl VariantArray {
159
159
/// Return a reference to the metadata field of the [`StructArray`]
160
160
pub fn metadata_field ( & self ) -> & ArrayRef {
161
161
// spec says fields order is not guaranteed, so we search by name
162
- self . inner . column_by_name ( "metadata" ) . unwrap ( )
162
+ & self . metadata_ref
163
163
}
164
164
165
165
/// Return a reference to the value field of the `StructArray`
166
166
pub fn value_field ( & self ) -> & ArrayRef {
167
167
// spec says fields order is not guaranteed, so we search by name
168
- self . inner . column_by_name ( "value" ) . unwrap ( )
168
+ & self . value_ref
169
169
}
170
170
171
171
/// Get the metadata bytes for a specific index
@@ -180,23 +180,13 @@ impl VariantArray {
180
180
181
181
/// Get the field names for an object at the given index
182
182
pub fn get_field_names ( & self , index : usize ) -> Vec < String > {
183
- if index >= self . len ( ) {
184
- return vec ! [ ] ;
185
- }
186
-
187
- if self . is_null ( index) {
183
+ if index >= self . len ( ) || self . is_null ( index) {
188
184
return vec ! [ ] ;
189
185
}
190
186
191
187
let variant = self . value ( index) ;
192
188
if let Some ( obj) = variant. as_object ( ) {
193
- let mut field_names = Vec :: new ( ) ;
194
- for i in 0 ..obj. len ( ) {
195
- if let Some ( field_name) = obj. field_name ( i) {
196
- field_names. push ( field_name. to_string ( ) ) ;
197
- }
198
- }
199
- field_names
189
+ Vec :: from_iter ( ( 0 ..obj. len ( ) ) . map ( |i| obj. field_name ( i) . unwrap ( ) . to_string ( ) ) )
200
190
} else {
201
191
vec ! [ ]
202
192
}
0 commit comments