This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed error in reading a non-finished IPC stream. (#302)
- Loading branch information
1 parent
824ad7e
commit 4bbfb25
Showing
16 changed files
with
136 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
data.arrows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "ipc_stream" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
[dependencies] | ||
arrow2 = { path = "../../", default-features = false, features = ["io_ipc"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import pyarrow as pa | ||
from time import sleep | ||
import socket | ||
|
||
# Set up the data exchange socket | ||
sk = socket.socket() | ||
sk.bind(("127.0.0.1", 12989)) | ||
sk.listen() | ||
|
||
data = [ | ||
pa.array([1, 2, 3, 4]), | ||
pa.array(["foo", "bar", "baz", None]), | ||
pa.array([True, None, False, True]), | ||
] | ||
|
||
batch = pa.record_batch(data, names=["f0", "f1", "f2"]) | ||
|
||
# Accept incoming connection and stream the data away | ||
connection, address = sk.accept() | ||
dummy_socket_file = connection.makefile("wb") | ||
with pa.RecordBatchStreamWriter(dummy_socket_file, batch.schema) as writer: | ||
for i in range(50): | ||
writer.write_batch(batch) | ||
sleep(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
python main.py & | ||
PRODUCER_PID=$! | ||
|
||
sleep 1 # wait for metadata to be available. | ||
cargo run | ||
|
||
kill $PRODUCER_PID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::net::TcpStream; | ||
use std::thread; | ||
use std::time::Duration; | ||
|
||
use arrow2::array::{Array, Int64Array}; | ||
use arrow2::datatypes::DataType; | ||
use arrow2::error::Result; | ||
use arrow2::io::ipc::read; | ||
|
||
fn main() -> Result<()> { | ||
const ADDRESS: &str = "127.0.0.1:12989"; | ||
|
||
let mut reader = TcpStream::connect(ADDRESS)?; | ||
let metadata = read::read_stream_metadata(&mut reader)?; | ||
let mut stream = read::StreamReader::new(&mut reader, metadata); | ||
|
||
let mut idx = 0; | ||
loop { | ||
match stream.next() { | ||
Some(x) => match x { | ||
Ok(read::StreamState::Some(b)) => { | ||
idx += 1; | ||
println!("batch: {:?}", idx) | ||
} | ||
Ok(read::StreamState::Waiting) => thread::sleep(Duration::from_millis(2000)), | ||
Err(l) => println!("{:?} ({})", l, idx), | ||
}, | ||
None => break, | ||
}; | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Read Arrow streams | ||
|
||
When compiled with feature `io_ipc`, this crate can be used to read Arrow streams. | ||
|
||
The example below shows how to read from a stream: | ||
|
||
```rust | ||
{{#include ../../../examples/ipc_pyarrow/src/main.rs}} | ||
``` | ||
|
||
e.g. written by pyarrow: | ||
|
||
```python,ignore | ||
{{#include ../../../examples/ipc_pyarrow/main.py}} | ||
``` | ||
|
||
via | ||
|
||
```bash,ignore | ||
{{#include ../../../examples/ipc_pyarrow/run.sh}} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters