scovich opened a new pull request, #12455: URL: https://github.com/apache/arrow-rs/pull/12455
# Which issue does this PR close? - Closes #8794 # Rationale for this change It's not unusual for an array operation to start with an `ArrayRef` and cast it to a concrete array type. But `Array::as_any` returns `&dyn Any`, which is impossible to turn back into an `Arc` even tho we know it came from an Arc. It's relatively cheap, but certainly not free, to convert e.g. `&StructArray` into an `Arc<StructArray>` by cloning its buffers and allocating a new Arc. # What changes are included in this PR? Define a new `Array::into_any_arc` method that returns `Arc<dyn Any + Send + Sync>`. If the underlying concrete array was already an `Arc`, just bump the refcount as if by `Arc::clone`. Otherwise, shallow clone it and allocate a new `Arc` as if by `Array::to_arc`. While we're at it, define a new blanket `impl<T: Array> Array for Arc<T>`. Historically, somebody who wanted to pass e.g. `Arc<StructArray>` to a method that expects `&dyn Array` had two options: 1. Pass `array.as_ref()`. This strips away the Arc and makes both `to_arc` and `into_any_arc` more expensive 2. Coerce it to `ArrayRef` first, e.g. `let array: ArrayRef = array`. (or `array.clone()`, if caller only has a reference) With the new blanket impl, the caller simply passes `&array`. # Are these changes tested? New unit+doc tests cover the new capabilities. # Are there any significant user-facing changes? Yes: 1. `Array::into_any_arc` has no safe default implementation (similar to `Array::as_any`), so it must be a required method. Concrete array types simply return `self` while wrapper types should forward to their inner. 2. The new blanket impl means `Array` methods can shadow same-named inherent methods on `T`. For example, two call sites had to change `array.slice(...)` to `array.as_ref().slice(...)` because `BooleanArray::slice` returns `BooleanArray` and is newly shadowed by `Array::slice` that returns `ArrayRef`. # AI usage disclosure Worked with an AI agent to explore several approaches before settling on this one. Vibe coded the first draft. Reviewed and cleaned up before pushing the PR. The PR description is all mine. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
