plewis110 opened a new issue, #5593:
URL: https://github.com/apache/arrow-rs/issues/5593

   **Is your feature request related to a problem or challenge? Please describe 
what you are trying to do.**
   <!--
   A clear and concise description of what the problem is. Ex. I'm always 
frustrated when [...] 
   (This section helps Arrow developers understand the context and *why* for 
this feature, in addition to  the *what*)
   -->
   
   Hi, I've been having trouble integrating with the 
[`arrow_ipc`](https://docs.rs/arrow-ipc/51.0.0/arrow_ipc/) crate due to the 
requirement that a 
[`RecordBatch`](https://docs.rs/arrow-array/51.0.0/arrow_array/struct.RecordBatch.html)
 object can only be constructed from a stream of data via the 
[`Read`](https://doc.rust-lang.org/nightly/std/io/trait.Read.html) trait. This 
is problematic when I have an already existing buffer of data in-memory which 
is expected to represent an entire and valid 
[`RecordBatch`](https://docs.rs/arrow-array/51.0.0/arrow_array/struct.RecordBatch.html)
 already.
   
   For example, I have a 
[`bytes::Bytes`](https://docs.rs/bytes/latest/bytes/struct.Bytes.html) instance 
which has been provided from another library. `bytes::Bytes` implements `Read` 
trait but I would like to avoid the copy which is forced when an object which 
implements the `Read` trait is passed to 
[`arrow_ipc::reader::StreamReader::try_new_unbuffered(...)`](https://docs.rs/arrow-ipc/51.0.0/arrow_ipc/reader/struct.StreamReader.html#method.try_new_unbuffered).
   
   Because Arrow prides itself on being a "zero-copy" format, I expected an 
interface which did not force a copy to be provided.
   
   **Describe the solution you'd like**
   <!--
   A clear and concise description of what you want to happen.
   -->
   
   For both the [`FileReader`]() and the [`StreamReader`]() instances, the 
following methods would be helpful:
   
   ```rust
   pub fn try_new_from_bytes(
       buffer: bytes::Bytes,
       projection: Option<Vec<usize>>,
   ) -> Result<Self, ArrowError>;
   ```
   
   **Describe alternatives you've considered**
   <!--
   A clear and concise description of any alternative solutions or features 
you've considered.
   -->
   
   The [`Read`](https://doc.rust-lang.org/nightly/std/io/trait.Read.html) trait 
is not acceptable for any zero-copy use case due to its trait methods passing 
around byte-slices which provide no means of lifetime extension and by 
extension, no way to avoid a copy of the data:
   
   ```rust
   pub trait Read {
       // Required method
       fn read(&mut self, buf: &mut [u8]) -> Result<usize>;
       
       // Provided methods
       ...
   }
   ```
   
   **Additional context**
   <!--
   Add any other context or screenshots about the feature request here.
   -->
   
   It appears that under the hood the underlying array type also uses 
`bytes::Bytes`, so this probably wouldn't be too difficult of a change.


-- 
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]

Reply via email to