alamb opened a new issue, #5463: URL: https://github.com/apache/arrow-rs/issues/5463
**Is your feature request related to a problem or challenge? Please describe what you are trying to do.** For reasons I am not sure of (likely historical), certain APIs of `Schema`/`RecordBatch` return owned instances of `SchemaRef`. So for example ```rust let schema: SchemaRef = record_batch.schema() ``` There are at least two challenges here: 1. This often requires an extra copy when not needed (though it is an `Arc::clone` which is relatively inexpensive compared to the work done by most Arrow apis) 2. It makes it hard for borrow propagation to work correctly. An example of challenges with borrow propagation is illustrated on https://github.com/apache/arrow-rs/issues/5342, which observes, we can't change `Schema::try_merge` to take (`&Schema`) even when it doesn't actually need owned ownership of the `Schema` without creating a temporary `Vec<SchemaRef>` or something similiar ```diff - pub fn try_merge(schemas: impl IntoIterator<Item = Self>) -> Result<Self, ArrowError> { + pub fn try_merge<'a>( + schemas: impl IntoIterator<Item = &'a Schema>, + ) -> Result<Schema, ArrowError> { ``` **Describe the solution you'd like** I recommend we add *new* functions that return a reference to the `SchemaRef` So new functions like ```rust /// Returns a reference to the [`Schema`] of the record batch. pub fn schema_ref(&self) -> &SchemaRef { &self.schema } ... **Describe alternatives you've considered** One alternative is to change the existing APIs as proposed in https://github.com/apache/arrow-rs/pull/5448 ```rust /// Returns a reference to the [`Schema`] of the record batch. pub fn schema(&self) -> &SchemaRef { &self.schema } ``` However I think this requires a substantial amount of downstream code change (as explained on https://github.com/apache/arrow-rs/pull/5448#pullrequestreview-1913470338) **Additional context** This came up recently on https://github.com/apache/arrow-rs/issues/5342 @tustvold notes we have made similar changes in the past, e.g. https://github.com/apache/arrow-rs/issues/2035 and https://github.com/apache/arrow-rs/issues/313 -- 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]
