Skip to content

Commit a3f9aec

Browse files
authored
docs: Add an example to scan an iceberg table (#545)
* docs: Add an example to scan an iceberg table Signed-off-by: Xuanwo <github@xuanwo.io> * Format toml Signed-off-by: Xuanwo <github@xuanwo.io> --------- Signed-off-by: Xuanwo <github@xuanwo.io>
1 parent 2137f6b commit a3f9aec

File tree

5 files changed

+82
-10
lines changed

5 files changed

+82
-10
lines changed

Cargo.toml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@
1818
[workspace]
1919
resolver = "2"
2020
members = [
21-
"crates/catalog/*",
22-
"crates/examples",
23-
"crates/iceberg",
24-
"crates/integrations/*",
25-
"crates/test_utils",
26-
]
27-
exclude = [
28-
"bindings/python"
21+
"crates/catalog/*",
22+
"crates/examples",
23+
"crates/iceberg",
24+
"crates/integrations/*",
25+
"crates/test_utils",
2926
]
27+
exclude = ["bindings/python"]
3028

3129
[workspace.package]
3230
version = "0.2.0"
@@ -65,6 +63,7 @@ futures = "0.3"
6563
iceberg = { version = "0.2.0", path = "./crates/iceberg" }
6664
iceberg-catalog-rest = { version = "0.2.0", path = "./crates/catalog/rest" }
6765
iceberg-catalog-hms = { version = "0.2.0", path = "./crates/catalog/hms" }
66+
iceberg-catalog-memory = { version = "0.2.0", path = "./crates/catalog/memory" }
6867
itertools = "0.13"
6968
log = "^0.4"
7069
mockito = "^1"

crates/catalog/sql/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ typed-builder = { workspace = true }
3838
iceberg_test_utils = { path = "../../test_utils", features = ["tests"] }
3939
itertools = { workspace = true }
4040
regex = "1.10.5"
41-
sqlx = { version = "0.8.0", features = ["tls-rustls", "runtime-tokio", "any", "sqlite", "migrate"], default-features = false }
41+
sqlx = { version = "0.8.0", features = [
42+
"tls-rustls",
43+
"runtime-tokio",
44+
"any",
45+
"sqlite",
46+
"migrate",
47+
], default-features = false }
4248
tempfile = { workspace = true }
4349
tokio = { workspace = true }

crates/iceberg/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ uuid = { workspace = true }
8181

8282
[dev-dependencies]
8383
ctor = { workspace = true }
84+
iceberg-catalog-memory = { workspace = true }
8485
iceberg_test_utils = { path = "../test_utils", features = ["tests"] }
8586
pretty_assertions = { workspace = true }
8687
tempfile = { workspace = true }

crates/iceberg/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,35 @@
2525
This crate contains the official Native Rust implementation of [Apache Iceberg](https://rust.iceberg.apache.org/).
2626

2727
See the [API documentation](https://docs.rs/iceberg/latest) for examples and the full API.
28+
29+
## Usage
30+
31+
```rust
32+
use futures::TryStreamExt;
33+
use iceberg::io::{FileIO, FileIOBuilder};
34+
use iceberg::{Catalog, Result, TableIdent};
35+
use iceberg_catalog_memory::MemoryCatalog;
36+
37+
#[tokio::main]
38+
async fn main() -> Result<()> {
39+
// Build your file IO.
40+
let file_io = FileIOBuilder::new("memory").build()?;
41+
// Connect to a catalog.
42+
let catalog = MemoryCatalog::new(file_io, None);
43+
// Load table from catalog.
44+
let table = catalog
45+
.load_table(&TableIdent::from_strs(["hello", "world"])?)
46+
.await?;
47+
// Build table scan.
48+
let stream = table
49+
.scan()
50+
.select(["name", "id"])
51+
.build()?
52+
.to_arrow()
53+
.await?;
54+
55+
// Consume this stream like arrow record batch stream.
56+
let _data: Vec<_> = stream. try_collect().await?;
57+
Ok(())
58+
}
59+
```

crates/iceberg/src/lib.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,41 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
//! Native Rust implementation of Apache Iceberg
18+
//! Apache Iceberg Official Native Rust Implementation
19+
//!
20+
//! # Examples
21+
//!
22+
//! ## Scan A Table
23+
//!
24+
//! ```rust, no_run
25+
//! use futures::TryStreamExt;
26+
//! use iceberg::io::{FileIO, FileIOBuilder};
27+
//! use iceberg::{Catalog, Result, TableIdent};
28+
//! use iceberg_catalog_memory::MemoryCatalog;
29+
//!
30+
//! #[tokio::main]
31+
//! async fn main() -> Result<()> {
32+
//! // Build your file IO.
33+
//! let file_io = FileIOBuilder::new("memory").build()?;
34+
//! // Connect to a catalog.
35+
//! let catalog = MemoryCatalog::new(file_io, None);
36+
//! // Load table from catalog.
37+
//! let table = catalog
38+
//! .load_table(&TableIdent::from_strs(["hello", "world"])?)
39+
//! .await?;
40+
//! // Build table scan.
41+
//! let stream = table
42+
//! .scan()
43+
//! .select(["name", "id"])
44+
//! .build()?
45+
//! .to_arrow()
46+
//! .await?;
47+
//!
48+
//! // Consume this stream like arrow record batch stream.
49+
//! let _data: Vec<_> = stream.try_collect().await?;
50+
//! Ok(())
51+
//! }
52+
//! ```
1953
2054
#![deny(missing_docs)]
2155

0 commit comments

Comments
 (0)