You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2025/01/15 12:48:36 UTC
[PR] Add example reading data from an `mmap`ed IPC file [arrow-rs]
alamb opened a new pull request, #6986:
URL: https://github.com/apache/arrow-rs/pull/6986
Draft as this example currently errors
# Which issue does this PR close?
- Closes https://github.com/apache/arrow-rs/issues/6709
# Rationale for this change
Reading arrow IPC files without copying is a key format feature, but it is hard to understand how to make this happen today
# What changes are included in this PR?
1. Add an example of how to use
# Are there any user-facing changes?
Example
Potential follow ons (TODO):
1. Create a `Buffer::from_owner` as suggested by @tustvold in https://github.com/apache/arrow-rs/issues/6709#issuecomment-2591285989
2. Maybe add `IPCBufferDecoder` or something similar into the actual crate API
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add example reading data from an `mmap`ed IPC file [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #6986:
URL: https://github.com/apache/arrow-rs/pull/6986#discussion_r1916662236
##########
arrow/examples/zero_copy_ipc.rs:
##########
@@ -0,0 +1,157 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Example of reading arrow IPC files and streams using "zero copy" API
+//!
+//! Zero copy in this case means the Arrow arrays refer directly to a user
+//! provided buffer or memory region.
+
+use arrow::array::{record_batch, RecordBatch};
+use arrow::error::Result;
+use arrow_buffer::Buffer;
+use arrow_cast::pretty::pretty_format_batches;
+use arrow_ipc::convert::fb_to_schema;
+use arrow_ipc::reader::{read_footer_length, FileDecoder};
+use arrow_ipc::writer::FileWriter;
+use arrow_ipc::{root_as_footer, Block};
+use std::path::PathBuf;
+use std::sync::Arc;
+
+/// This example shows how to read data from an Arrow IPC file without copying
Review Comment:
I re-read the code in `StreamDecoder` again and I am pretty sure it will also be zero copy array creation if fed via `StreamDecoder::decode` -- https://github.com/apache/arrow-rs/blob/fc6936aff50b0b1c8bea984bba2d57dac68a98b3/arrow-ipc/src/reader/stream.rs#L131
Perhaps I can extend this example to show that as well 🤔
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add example reading data from an `mmap`ed IPC file [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #6986:
URL: https://github.com/apache/arrow-rs/pull/6986#discussion_r1916615396
##########
arrow/Cargo.toml:
##########
@@ -87,6 +87,9 @@ criterion = { version = "0.5", default-features = false }
half = { version = "2.1", default-features = false }
rand = { version = "0.8", default-features = false, features = ["std", "std_rng"] }
serde = { version = "1.0", default-features = false, features = ["derive"] }
+# used in examples
+memmap2 = "0.9.3"
+bytes = "1.9"
Review Comment:
we could avoid this `bytes` dependency if we added `Buffer::from_owned`
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add example reading data from an `mmap`ed IPC file [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #6986:
URL: https://github.com/apache/arrow-rs/pull/6986#issuecomment-2604451829
Thank you for the review @tustvold
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add example reading data from an `mmap`ed IPC file [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #6986:
URL: https://github.com/apache/arrow-rs/pull/6986
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org