Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IPC] Expose schema on StreamDecoder #6420

Open
wjones127 opened this issue Sep 18, 2024 · 0 comments
Open

[IPC] Expose schema on StreamDecoder #6420

wjones127 opened this issue Sep 18, 2024 · 0 comments
Assignees
Labels
arrow Changes to the arrow crate enhancement Any new improvement worthy of a entry in the changelog

Comments

@wjones127
Copy link
Member

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

There is a nice example in the StreamDecoder::decode docs from reading from a stream:

fn print_stream<I>(src: impl Iterator<Item = Buffer>) -> Result<(), ArrowError> {
   let mut decoder = StreamDecoder::new();
   for mut x in src {
       while !x.is_empty() {
           if let Some(x) = decoder.decode(&mut x)? {
               println!("{x:?}");
           }
       }
   }
   decoder.finish().unwrap();
   Ok(())
}

https://docs.rs/arrow-ipc/latest/arrow_ipc/reader/struct.StreamDecoder.html#method.decode

However, it doesn't show how to get the schema. This would be useful if someone wanted to construct a RecordBatchReader or SendableRecordBatchStream from a stream of Bytes / Buffer. And it would be particularly helpful in cases where there were zero batches but we still wanted to get the schema.

Describe the solution you'd like

Minimally, it would be nice to do this:

impl StreamDecoder {
    /// Return the schema, if decoded yet. Returns `None` if the schema message
    /// has yet to be decoded.
    fn schema(&self) -> Option<SchemaRef> { ... }
}

But it might also be nice to parallel the decode method:

impl StreamDecoder {
    /// Return the schema, if decoded yet. Returns `None` if the schema message
    /// has yet to be decoded.
    fn decode_schema(&mut self, buffer: &mut Buffer) -> Option<SchemaRef> { ... }
}

Describe alternatives you've considered

I asked in Slack if there were other straight forward ways, but didn't see anything easy from the suggestions. https://the-asf.slack.com/archives/C01QUFS30TD/p1726636373388569

Additional context

@wjones127 wjones127 added arrow Changes to the arrow crate enhancement Any new improvement worthy of a entry in the changelog labels Sep 18, 2024
@wjones127 wjones127 self-assigned this Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate enhancement Any new improvement worthy of a entry in the changelog
Projects
None yet
Development

No branches or pull requests

1 participant