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.
- Loading branch information
1 parent
a19765e
commit 1eef2d0
Showing
27 changed files
with
478 additions
and
334 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::io::{Cursor, Seek, Write}; | ||
use std::sync::Arc; | ||
|
||
use arrow2::array::*; | ||
use arrow2::datatypes::*; | ||
use arrow2::error::Result; | ||
use arrow2::io::ipc::read; | ||
use arrow2::io::ipc::write; | ||
use arrow2::record_batch::RecordBatch; | ||
|
||
fn main() -> Result<()> { | ||
// declare an extension. | ||
let extension_type = | ||
DataType::Extension("date16".to_string(), Box::new(DataType::UInt16), None); | ||
|
||
// initialize an array with it. | ||
let array = UInt16Array::from_slice([1, 2]).to(extension_type.clone()); | ||
|
||
// from here on, it works as usual | ||
let mut buffer = Cursor::new(vec![]); | ||
|
||
// write to IPC | ||
write_ipc(&mut buffer, array)?; | ||
|
||
// read it back | ||
let batch = read_ipc(&buffer.into_inner())?; | ||
|
||
// and verify that the datatype is preserved. | ||
let array = &batch.columns()[0]; | ||
assert_eq!(array.data_type(), &extension_type); | ||
|
||
// see https://arrow.apache.org/docs/format/Columnar.html#extension-types | ||
// for consuming by other consumers. | ||
Ok(()) | ||
} | ||
|
||
fn write_ipc<W: Write + Seek>(writer: &mut W, array: impl Array + 'static) -> Result<()> { | ||
let schema = Schema::new(vec![Field::new("a", array.data_type().clone(), false)]); | ||
|
||
let mut writer = write::FileWriter::try_new(writer, &schema)?; | ||
|
||
let batch = RecordBatch::try_new(Arc::new(schema), vec![Arc::new(array)])?; | ||
|
||
writer.write(&batch) | ||
} | ||
|
||
fn read_ipc(reader: &[u8]) -> Result<RecordBatch> { | ||
let mut reader = Cursor::new(reader); | ||
let metadata = read::read_file_metadata(&mut reader)?; | ||
let mut reader = read::FileReader::new(&mut reader, metadata, None); | ||
reader.next().unwrap() | ||
} |
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,8 @@ | ||
# Extension types | ||
|
||
This crate supports Arrows' ["extension type"](https://arrow.apache.org/docs/format/Columnar.html#extension-types), to declare, use, and share custom logical types. | ||
The follow example shows how to declare one: | ||
|
||
```rust | ||
{{#include ../../../examples/extension.rs}} | ||
``` |
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
Oops, something went wrong.