-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Is your feature request related to a problem or challenge? Please describe what you are trying to do.
arrow-rs makes heavy use of ArrayRef (= Arc<dyn Array>), and it's impossible to impl Array for !Any types because Array::as_any is a required method. But for some reason we have Array: Send + Sync instead of Array: Any + Send + Sync, so there's no way to Arc::downcast an ArrayRef to e.g. Arc<StructArray>.
Describe the solution you'd like
trait Array: std::any::Any + ... { ... }Which allows
let array: ArrayRef = ...;
let struct_array: Arc<StructArray> = Arc::downcast(array).map_err(...)?;One big problem tho -- the blanket impl<T: Array> Array for &T means Array cannot require Any (because Any: 'static). I'm not sure how to work around that.
Describe alternatives you've considered
As far as I can tell, with today's code you have to downcast to &StructArray, clone it, and allocate a new Arc:
let array: ArrayRef = ...;
let struct_array = array.as_struct_opt().ok_or_else(...)?;
let struct_array = Arc::new(struct_array.clone());Sure, cloning an array is probably fairly inexpensive, but there's no way it's as cheap as an arc clone.