From 3f87e76d0462621993095760e537dcf21999c348 Mon Sep 17 00:00:00 2001 From: Yuan Zhou Date: Sat, 21 Aug 2021 12:28:23 +0800 Subject: [PATCH] Add examples for reading delta table with Rust API. (#400) * Add examples for reading delta table with Rust API. --- Cargo.lock | 49 +++++++++++++++++++++++++++++++ rust/README.md | 10 +++++++ rust/examples/read_delta_table.rs | 10 +++++++ 3 files changed, 69 insertions(+) create mode 100644 rust/examples/read_delta_table.rs diff --git a/Cargo.lock b/Cargo.lock index f9ea21ce0f..ecb8447a75 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -531,6 +531,7 @@ version = "0.4.1" dependencies = [ "anyhow", "arrow", + "async-stream", "async-trait", "azure_core", "azure_storage", @@ -560,6 +561,8 @@ dependencies = [ "serde", "serde_json", "serial_test", + "tame-gcs", + "tame-oauth", "tempdir", "thiserror", "tokio", @@ -2642,6 +2645,42 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "tame-gcs" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d20ec2d6525a66afebdff9e1d8ef143c9deae9a3b040c61d3cfa9ae6fda80060" +dependencies = [ + "base64 0.13.0", + "bytes", + "chrono", + "http", + "percent-encoding", + "serde", + "serde_json", + "serde_urlencoded 0.7.0", + "thiserror", + "url", +] + +[[package]] +name = "tame-oauth" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9435c9348e480fad0f2215d5602e2dfad03df8a6398c4e7ceaeaa42758f26a8a" +dependencies = [ + "base64 0.13.0", + "chrono", + "http", + "lock_api", + "parking_lot", + "ring", + "serde", + "serde_json", + "twox-hash", + "url", +] + [[package]] name = "tempdir" version = "0.3.7" @@ -2951,6 +2990,16 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" +[[package]] +name = "twox-hash" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f559b464de2e2bdabcac6a210d12e9b5a5973c251e102c44c585c71d51bd78e" +dependencies = [ + "cfg-if", + "static_assertions", +] + [[package]] name = "typenum" version = "1.13.0" diff --git a/rust/README.md b/rust/README.md index e100445bc2..c2c1603d21 100644 --- a/rust/README.md +++ b/rust/README.md @@ -33,6 +33,16 @@ DeltaTable(./tests/data/delta-0.2.0) files count: 3 ``` +### Examples + +The examples folder shows how to use Rust API to manipulate Delta tables. + +Examples can be run using the `cargo run --example` command. For example: + +```bash +cargo run --example read_delta_table +``` + Optional cargo package features ----------------------- diff --git a/rust/examples/read_delta_table.rs b/rust/examples/read_delta_table.rs new file mode 100644 index 0000000000..5934b1f16f --- /dev/null +++ b/rust/examples/read_delta_table.rs @@ -0,0 +1,10 @@ +extern crate anyhow; +extern crate deltalake; + +#[tokio::main(flavor = "current_thread")] +async fn main() -> anyhow::Result<()> { + let table_path = "./tests/data/delta-0.8.0"; + let table = deltalake::open_table(table_path).await?; + println!("{}", table); + Ok(()) +}