Skip to content

Commit 572af94

Browse files
committed
[FIX] make code modular
1 parent 382421e commit 572af94

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

parquet-variant-compute/src/variant_array.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ impl VariantArray {
159159
/// Return a reference to the metadata field of the [`StructArray`]
160160
pub fn metadata_field(&self) -> &ArrayRef {
161161
// spec says fields order is not guaranteed, so we search by name
162-
self.inner.column_by_name("metadata").unwrap()
162+
&self.metadata_ref
163163
}
164164

165165
/// Return a reference to the value field of the `StructArray`
166166
pub fn value_field(&self) -> &ArrayRef {
167167
// spec says fields order is not guaranteed, so we search by name
168-
self.inner.column_by_name("value").unwrap()
168+
&self.value_ref
169169
}
170170

171171
/// Get the metadata bytes for a specific index
@@ -180,23 +180,13 @@ impl VariantArray {
180180

181181
/// Get the field names for an object at the given index
182182
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) {
188184
return vec![];
189185
}
190186

191187
let variant = self.value(index);
192188
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()))
200190
} else {
201191
vec![]
202192
}

0 commit comments

Comments
 (0)