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.
- Loading branch information
1 parent
e0a9b5e
commit 25d40f2
Showing
5 changed files
with
60 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use arrow2::array::*; | ||
use arrow2::error::Error; | ||
use arrow2::io::orc::{format, read}; | ||
|
||
fn deserialize_column(path: &str, column_name: &str) -> Result<Box<dyn Array>, Error> { | ||
// open the file | ||
let mut reader = std::fs::File::open(path).unwrap(); | ||
|
||
// read its metadata (IO-bounded) | ||
let metadata = format::read::read_metadata(&mut reader)?; | ||
|
||
// infer its (Arrow) [`Schema`] | ||
let schema = read::infer_schema(&metadata.footer)?; | ||
|
||
// find the position of the column in the schema | ||
let (pos, field) = schema | ||
.fields | ||
.iter() | ||
.enumerate() | ||
.find(|f| f.1.name == column_name) | ||
.unwrap(); | ||
|
||
// pick a stripe (basically a set of rows) | ||
let stripe = 0; | ||
|
||
// read the stripe's footer (IO-bounded) | ||
let footer = format::read::read_stripe_footer(&mut reader, &metadata, stripe, &mut vec![])?; | ||
|
||
// read the column's data from the stripe (IO-bounded) | ||
let data_type = field.data_type.clone(); | ||
let column = format::read::read_stripe_column( | ||
&mut reader, | ||
&metadata, | ||
0, | ||
footer, | ||
// 1 because ORC schemas always start with a struct, which we ignore | ||
1 + pos as u32, | ||
vec![], | ||
)?; | ||
|
||
// finally, deserialize to Arrow (CPU-bounded) | ||
read::deserialize(data_type, &column) | ||
} | ||
|
||
fn main() -> Result<(), Error> { | ||
use std::env; | ||
let args: Vec<String> = env::args().collect(); | ||
|
||
let file_path = &args[1]; | ||
let column = &args[2]; | ||
|
||
let array = deserialize_column(file_path, column)?; | ||
println!("{array:?}"); | ||
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