From 98e0f1651449bc10ea5398a5d4cbea3751820c4d Mon Sep 17 00:00:00 2001 From: Raphael Taylor-Davies Date: Thu, 24 Nov 2022 19:45:46 +0000 Subject: [PATCH] StructArray::columns return slice --- arrow-array/src/array/struct_array.rs | 7 ++++--- arrow-cast/src/display.rs | 2 +- arrow-ipc/src/writer.rs | 2 +- parquet/src/arrow/arrow_writer/levels.rs | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/arrow-array/src/array/struct_array.rs b/arrow-array/src/array/struct_array.rs index 841d3235f64..955e0c53032 100644 --- a/arrow-array/src/array/struct_array.rs +++ b/arrow-array/src/array/struct_array.rs @@ -67,13 +67,14 @@ impl StructArray { } /// Returns the fields of the struct array - pub fn columns(&self) -> Vec<&ArrayRef> { - self.boxed_fields.iter().collect() + pub fn columns(&self) -> &[ArrayRef] { + &self.boxed_fields } /// Returns child array refs of the struct array + #[deprecated(note = "Use columns().to_vec()")] pub fn columns_ref(&self) -> Vec { - self.boxed_fields.clone() + self.columns().to_vec() } /// Return field names in this struct array diff --git a/arrow-cast/src/display.rs b/arrow-cast/src/display.rs index ae1c799a4ef..434f750afc4 100644 --- a/arrow-cast/src/display.rs +++ b/arrow-cast/src/display.rs @@ -459,7 +459,7 @@ pub fn array_value_to_string( let mut s = String::new(); s.push('{'); - let mut kv_iter = st.columns().into_iter().zip(st.column_names().into_iter()); + let mut kv_iter = st.columns().iter().zip(st.column_names()); if let Some((col, name)) = kv_iter.next() { append_struct_field_string(&mut s, name, col, row)?; } diff --git a/arrow-ipc/src/writer.rs b/arrow-ipc/src/writer.rs index dec44de177f..0497cbe5e47 100644 --- a/arrow-ipc/src/writer.rs +++ b/arrow-ipc/src/writer.rs @@ -177,7 +177,7 @@ impl IpcDataGenerator { match column.data_type() { DataType::Struct(fields) => { let s = as_struct_array(column); - for (field, &column) in fields.iter().zip(s.columns().iter()) { + for (field, column) in fields.iter().zip(s.columns()) { self.encode_dictionaries( field, column, diff --git a/parquet/src/arrow/arrow_writer/levels.rs b/parquet/src/arrow/arrow_writer/levels.rs index e2a8a8c50e9..182f68c498f 100644 --- a/parquet/src/arrow/arrow_writer/levels.rs +++ b/parquet/src/arrow/arrow_writer/levels.rs @@ -324,7 +324,7 @@ impl LevelInfoBuilder { }; let write_non_null = |children: &mut [LevelInfoBuilder], range: Range| { - for (child_array, child) in array.columns().into_iter().zip(children) { + for (child_array, child) in array.columns().iter().zip(children) { child.write(child_array, range.clone()) } };