This is an automated email from the ASF dual-hosted git repository.

liurenjie1024 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-rust.git


The following commit(s) were added to refs/heads/main by this push:
     new a3f9aec  docs: Add an example to scan an iceberg table (#545)
a3f9aec is described below

commit a3f9aecb80e582dfafb450f41e4f760176c6c36c
Author: Xuanwo <[email protected]>
AuthorDate: Wed Aug 14 20:57:32 2024 +0800

    docs: Add an example to scan an iceberg table (#545)
    
    * docs: Add an example to scan an iceberg table
    
    Signed-off-by: Xuanwo <[email protected]>
    
    * Format toml
    
    Signed-off-by: Xuanwo <[email protected]>
    
    ---------
    
    Signed-off-by: Xuanwo <[email protected]>
---
 Cargo.toml                    | 15 +++++++--------
 crates/catalog/sql/Cargo.toml |  8 +++++++-
 crates/iceberg/Cargo.toml     |  1 +
 crates/iceberg/README.md      | 32 ++++++++++++++++++++++++++++++++
 crates/iceberg/src/lib.rs     | 36 +++++++++++++++++++++++++++++++++++-
 5 files changed, 82 insertions(+), 10 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 04966d2..d7d52f2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,15 +18,13 @@
 [workspace]
 resolver = "2"
 members = [
-    "crates/catalog/*",
-    "crates/examples",
-    "crates/iceberg",
-    "crates/integrations/*",
-    "crates/test_utils",
-]
-exclude = [
-    "bindings/python"
+  "crates/catalog/*",
+  "crates/examples",
+  "crates/iceberg",
+  "crates/integrations/*",
+  "crates/test_utils",
 ]
+exclude = ["bindings/python"]
 
 [workspace.package]
 version = "0.2.0"
@@ -65,6 +63,7 @@ futures = "0.3"
 iceberg = { version = "0.2.0", path = "./crates/iceberg" }
 iceberg-catalog-rest = { version = "0.2.0", path = "./crates/catalog/rest" }
 iceberg-catalog-hms = { version = "0.2.0", path = "./crates/catalog/hms" }
+iceberg-catalog-memory = { version = "0.2.0", path = "./crates/catalog/memory" 
}
 itertools = "0.13"
 log = "^0.4"
 mockito = "^1"
diff --git a/crates/catalog/sql/Cargo.toml b/crates/catalog/sql/Cargo.toml
index b90423f..03a3f2f 100644
--- a/crates/catalog/sql/Cargo.toml
+++ b/crates/catalog/sql/Cargo.toml
@@ -38,6 +38,12 @@ typed-builder = { workspace = true }
 iceberg_test_utils = { path = "../../test_utils", features = ["tests"] }
 itertools = { workspace = true }
 regex = "1.10.5"
-sqlx = { version = "0.8.0", features = ["tls-rustls", "runtime-tokio", "any", 
"sqlite", "migrate"], default-features = false }
+sqlx = { version = "0.8.0", features = [
+  "tls-rustls",
+  "runtime-tokio",
+  "any",
+  "sqlite",
+  "migrate",
+], default-features = false }
 tempfile = { workspace = true }
 tokio = { workspace = true }
diff --git a/crates/iceberg/Cargo.toml b/crates/iceberg/Cargo.toml
index 84e29df..fd523e4 100644
--- a/crates/iceberg/Cargo.toml
+++ b/crates/iceberg/Cargo.toml
@@ -81,6 +81,7 @@ uuid = { workspace = true }
 
 [dev-dependencies]
 ctor = { workspace = true }
+iceberg-catalog-memory = { workspace = true }
 iceberg_test_utils = { path = "../test_utils", features = ["tests"] }
 pretty_assertions = { workspace = true }
 tempfile = { workspace = true }
diff --git a/crates/iceberg/README.md b/crates/iceberg/README.md
index 513fa8a..4533e42 100644
--- a/crates/iceberg/README.md
+++ b/crates/iceberg/README.md
@@ -25,3 +25,35 @@
 This crate contains the official Native Rust implementation of [Apache 
Iceberg](https://rust.iceberg.apache.org/).
 
 See the [API documentation](https://docs.rs/iceberg/latest) for examples and 
the full API.
+
+## Usage
+
+```rust
+use futures::TryStreamExt;
+use iceberg::io::{FileIO, FileIOBuilder};
+use iceberg::{Catalog, Result, TableIdent};
+use iceberg_catalog_memory::MemoryCatalog;
+
+#[tokio::main]
+async fn main() -> Result<()> {
+    // Build your file IO.
+    let file_io = FileIOBuilder::new("memory").build()?;
+    // Connect to a catalog.
+    let catalog = MemoryCatalog::new(file_io, None);
+    // Load table from catalog.
+    let table = catalog
+        .load_table(&TableIdent::from_strs(["hello", "world"])?)
+        .await?;
+    // Build table scan.
+    let stream = table
+        .scan()
+        .select(["name", "id"])
+        .build()?
+        .to_arrow()
+        .await?;
+
+    // Consume this stream like arrow record batch stream.
+    let _data: Vec<_> = stream. try_collect().await?;
+    Ok(())
+}
+```
\ No newline at end of file
diff --git a/crates/iceberg/src/lib.rs b/crates/iceberg/src/lib.rs
index 9682fa1..3af03f5 100644
--- a/crates/iceberg/src/lib.rs
+++ b/crates/iceberg/src/lib.rs
@@ -15,7 +15,41 @@
 // specific language governing permissions and limitations
 // under the License.
 
-//! Native Rust implementation of Apache Iceberg
+//! Apache Iceberg Official Native Rust Implementation
+//!
+//! # Examples
+//!
+//! ## Scan A Table
+//!
+//! ```rust, no_run
+//! use futures::TryStreamExt;
+//! use iceberg::io::{FileIO, FileIOBuilder};
+//! use iceberg::{Catalog, Result, TableIdent};
+//! use iceberg_catalog_memory::MemoryCatalog;
+//!
+//! #[tokio::main]
+//! async fn main() -> Result<()> {
+//!     // Build your file IO.
+//!     let file_io = FileIOBuilder::new("memory").build()?;
+//!     // Connect to a catalog.
+//!     let catalog = MemoryCatalog::new(file_io, None);
+//!     // Load table from catalog.
+//!     let table = catalog
+//!         .load_table(&TableIdent::from_strs(["hello", "world"])?)
+//!         .await?;
+//!     // Build table scan.
+//!     let stream = table
+//!         .scan()
+//!         .select(["name", "id"])
+//!         .build()?
+//!         .to_arrow()
+//!         .await?;
+//!
+//!     // Consume this stream like arrow record batch stream.
+//!     let _data: Vec<_> = stream.try_collect().await?;
+//!     Ok(())
+//! }
+//! ```
 
 #![deny(missing_docs)]
 

Reply via email to