From ceb6b7355e818eeddc3758ead27b242fcfb4628f Mon Sep 17 00:00:00 2001 From: Raphael Taylor-Davies Date: Mon, 18 Jul 2022 08:33:54 -0400 Subject: [PATCH] Return reference from UnionArray::child (#2035) --- arrow/src/array/array_union.rs | 4 ++-- arrow/src/ipc/writer.rs | 2 +- arrow/src/util/display.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arrow/src/array/array_union.rs b/arrow/src/array/array_union.rs index 639b82ae980..af2b29f882c 100644 --- a/arrow/src/array/array_union.rs +++ b/arrow/src/array/array_union.rs @@ -231,10 +231,10 @@ impl UnionArray { /// /// Panics if the `type_id` provided is less than zero or greater than the number of types /// in the `Union`. - pub fn child(&self, type_id: i8) -> ArrayRef { + pub fn child(&self, type_id: i8) -> &ArrayRef { assert!(0 <= type_id); assert!((type_id as usize) < self.boxed_fields.len()); - self.boxed_fields[type_id as usize].clone() + &self.boxed_fields[type_id as usize] } /// Returns the `type_id` for the array slot at `index`. diff --git a/arrow/src/ipc/writer.rs b/arrow/src/ipc/writer.rs index 3847661db5e..279edd57221 100644 --- a/arrow/src/ipc/writer.rs +++ b/arrow/src/ipc/writer.rs @@ -226,7 +226,7 @@ impl IpcDataGenerator { } DataType::Union(fields, _, _) => { let union = as_union_array(column); - for (field, ref column) in fields + for (field, column) in fields .iter() .enumerate() .map(|(n, f)| (f, union.child(n as i8))) diff --git a/arrow/src/util/display.rs b/arrow/src/util/display.rs index 7a7da8ccb0f..65590504267 100644 --- a/arrow/src/util/display.rs +++ b/arrow/src/util/display.rs @@ -434,7 +434,7 @@ fn union_to_string( let name = fields.get(field_idx).unwrap().name(); let value = array_value_to_string( - &list.child(type_id), + list.child(type_id), match mode { UnionMode::Dense => list.value_offset(row) as usize, UnionMode::Sparse => row,