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 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support to write to Arrow Stream
- Loading branch information
1 parent
22f0c3e
commit cf2b10b
Showing
10 changed files
with
199 additions
and
10 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
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
File renamed without changes.
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,2 @@ | ||
mod data; | ||
mod stream; |
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,35 @@ | ||
use std::collections::BTreeMap; | ||
use std::sync::Arc; | ||
|
||
use arrow2::array::*; | ||
use arrow2::bitmap::Bitmap; | ||
use arrow2::datatypes::{DataType, Field, TimeUnit}; | ||
use arrow2::{error::Result, ffi}; | ||
|
||
fn _test_round_trip(arrays: Vec<Arc<dyn Array>>) -> Result<()> { | ||
let field = Field::new("a", arrays[0].data_type().clone(), true); | ||
let iter = Box::new(arrays.clone().into_iter().map(Ok)) as _; | ||
|
||
let mut stream = Box::new(ffi::ArrowArrayStream::empty()); | ||
|
||
unsafe { ffi::export_iterator(iter, field.clone(), &mut *stream) } | ||
|
||
let mut stream = unsafe { ffi::ArrowArrayStreamReader::try_new(stream)? }; | ||
|
||
let mut produced_arrays: Vec<Arc<dyn Array>> = vec![]; | ||
while let Some(array) = unsafe { stream.next() } { | ||
produced_arrays.push(array?.into()); | ||
} | ||
|
||
assert_eq!(produced_arrays, arrays); | ||
assert_eq!(stream.field(), &field); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn round_trip() -> Result<()> { | ||
let array = Int32Array::from(&[Some(2), None, Some(1), None]); | ||
let array: Arc<dyn Array> = Arc::new(array.clone()); | ||
|
||
_test_round_trip(vec![array.clone(), array.clone(), array]) | ||
} |