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

   **Is your feature request related to a problem or challenge? Please describe 
what you are trying to do.**
   
   I'm trying to use 
[`RecordBatchWriter`](https://docs.rs/arrow/52.2.0/arrow/array/trait.RecordBatchWriter.html)
 trait to introduce dynamism in the type of output - e.g. depending on the 
command line options, I'd like to write parquet, csv, json or ipc. I know that 
corresponding writers all implement this trait, thanks to #4206 and #4228 by 
@alexandreyc.
   
   Specifically, I was planning to use `Box<dyn RecordBatchWriter>` and pass it 
to the writing code, something like this:
   ```rust
   let writer: Box<dyn RecordBatchWriter> = match args.format {
       "parquet" => Box::new(parquet::arrow::ArrowWriter::try_new(file, schema, 
None)),
       "csv" => Box::new(arrow::csv::Writer::new(file)),
       ...
   }
   
   writer.write(my_batch);
   writer.close();  // this is required to write the formats correctly
   ```
   
   Unfortunately, due to `close` method in that trait consuming `self`, we 
can't really use this approach, as now close() needs to know the exact type of 
the writer. Calling close() on the trait object gives compilation error "the 
size of `dyn RecordBatchWriter` cannot be statically determined". See [example 
in Rust 
playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=2f5a6a45fb2c4321dbb4806009bafaa3).
 
   
   **Describe the solution you'd like**
   
   Ideally, switch to `close(&mut self)`. This is not backwards-compatible. On 
the other hand, I don't see how this trait can reasonably be used in client 
code in the current state, so maybe it's worth it? Let me know if I'm missing 
anything.
   
   **Describe alternatives you've considered**
   
   Manually downcasting to specific types and then calling close() on them, but 
that doesn't seem to work, as RecordBatchWriter needs to explicitly have 
`as_any` method or similar.


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