Skip to content

Commit

Permalink
chore: improve and fix the rest example (#842)
Browse files Browse the repository at this point in the history
  • Loading branch information
goldmedal authored Dec 24, 2024
1 parent f33628e commit 5400bbe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 6 additions & 1 deletion crates/examples/src/rest_catalog_namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ use std::collections::HashMap;
use iceberg::{Catalog, NamespaceIdent};
use iceberg_catalog_rest::{RestCatalog, RestCatalogConfig};

/// It a simple example that demonstrates how to create a namespace in a REST catalog.
/// It requires a running instance of the iceberg-rest catalog for the port 8181.
/// You can find how to run the iceberg-rest catalog in the official documentation.
///
/// [Quickstart](https://iceberg.apache.org/spark-quickstart/)
#[tokio::main]
async fn main() {
// ANCHOR: create_catalog
// Create catalog
let config = RestCatalogConfig::builder()
.uri("http://localhost:8080".to_string())
.uri("http://localhost:8181".to_string())
.build();

let catalog = RestCatalog::new(config);
Expand Down
13 changes: 9 additions & 4 deletions crates/examples/src/rest_catalog_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ use iceberg::spec::{NestedField, PrimitiveType, Schema, Type};
use iceberg::{Catalog, TableCreation, TableIdent};
use iceberg_catalog_rest::{RestCatalog, RestCatalogConfig};

/// This is a simple example that demonstrates how to create a table in a REST catalog and get it back.
/// It requires a running instance of the iceberg-rest catalog for the port 8080.
/// You can find how to run the iceberg-rest catalog in the official documentation.
///
/// [Quickstart](https://iceberg.apache.org/spark-quickstart/)
#[tokio::main]
async fn main() {
// Create catalog
let config = RestCatalogConfig::builder()
.uri("http://localhost:8080".to_string())
.uri("http://localhost:8181".to_string())
.build();

let catalog = RestCatalog::new(config);
Expand Down Expand Up @@ -60,10 +65,10 @@ async fn main() {
// ANCHOR_END: create_table

// ANCHOR: load_table
let table2 = catalog
.load_table(&TableIdent::from_strs(["default", "t2"]).unwrap())
let table_created = catalog
.load_table(&TableIdent::from_strs(["default", "t1"]).unwrap())
.await
.unwrap();
println!("{:?}", table2.metadata());
println!("{:?}", table_created.metadata());
// ANCHOR_END: load_table
}

0 comments on commit 5400bbe

Please sign in to comment.