Skip to content

Commit

Permalink
Update version + add example (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncpenke authored Sep 30, 2022
1 parent d4c7a9e commit 6c37e29
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = [
"arrow2_convert",
"arrow2_convert_derive"
"arrow2_convert_derive",
"examples/simple"
]
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ pub struct Foo {
name: String,
}

#[test]
fn test_simple_roundtrip() {
fn main() {
// an item
let original_array = [
Foo { name: "hello".to_string() },
Expand Down
6 changes: 3 additions & 3 deletions arrow2_convert/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "arrow2_convert"
version = "0.3.1"
version = "0.3.2"
authors = [
"Jorge Leitao <[email protected]>",
"Chandra Penke <[email protected]>"
Expand All @@ -13,13 +13,13 @@ description = "Convert between nested rust types and Arrow with arrow2"

[dependencies]
arrow2 = "0.14.1"
arrow2_convert_derive = { version = "0.3.0", path = "../arrow2_convert_derive", optional = true }
arrow2_convert_derive = { version = "0.3.2", path = "../arrow2_convert_derive", optional = true }
chrono = { version = "0.4", default_features = false, features = ["std"] }
err-derive = "0.3"
trybuild = "1.0"

[dev-dependencies]
arrow2_convert_derive = { version = "0.3.1", path = "../arrow2_convert_derive" }
arrow2_convert_derive = { version = "0.3.2", path = "../arrow2_convert_derive" }

[features]
default = [ "derive" ]
Expand Down
2 changes: 1 addition & 1 deletion arrow2_convert_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "arrow2_convert_derive"
version = "0.3.1"
version = "0.3.2"
authors = [
"Jorge Leitao <[email protected]>",
"Chandra Penke <[email protected]>"
Expand Down
10 changes: 10 additions & 0 deletions examples/simple/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "arrow2_convert_example_simple"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
arrow2 = "0.14"
arrow2_convert = { version = "0.3", path = "../../arrow2_convert" }
38 changes: 38 additions & 0 deletions examples/simple/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/// Simple example
use arrow2::array::Array;
use arrow2_convert::{deserialize::TryIntoCollection, serialize::TryIntoArrow, ArrowField};

#[derive(Debug, Clone, PartialEq, Eq, ArrowField)]
pub struct Foo {
name: String,
}

fn main() {
// an item
let original_array = [
Foo {
name: "hello".to_string(),
},
Foo {
name: "one more".to_string(),
},
Foo {
name: "good bye".to_string(),
},
];

// serialize to an arrow array. try_into_arrow() is enabled by the TryIntoArrow trait
let arrow_array: Box<dyn Array> = original_array.try_into_arrow().unwrap();

// which can be cast to an Arrow StructArray and be used for all kinds of IPC, FFI, etc.
// supported by `arrow2`
let struct_array = arrow_array
.as_any()
.downcast_ref::<arrow2::array::StructArray>()
.unwrap();
assert_eq!(struct_array.len(), 3);

// deserialize back to our original vector via TryIntoCollection trait.
let round_trip_array: Vec<Foo> = arrow_array.try_into_collection().unwrap();
assert_eq!(round_trip_array, original_array);
}

0 comments on commit 6c37e29

Please sign in to comment.