Skip to content

Commit f6c5937

Browse files
committed
Loader example
1 parent f162400 commit f6c5937

File tree

4 files changed

+77
-4
lines changed

4 files changed

+77
-4
lines changed

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/catalog/loader/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "iceberg-catalog-loader"
3+
edition = { workspace = true }
4+
homepage = { workspace = true }
5+
rust-version = { workspace = true }
6+
version = { workspace = true }
7+
8+
categories = ["database"]
9+
description = "Apache Iceberg Catalog Loader API"
10+
keywords = ["iceberg", "catalog"]
11+
license = { workspace = true }
12+
repository = { workspace = true }
13+
14+
[dependencies]
15+
iceberg = { workspace = true }
16+
iceberg-catalog-rest = {workspace = true}

crates/catalog/loader/src/lib.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use std::sync::Arc;
2+
use iceberg::{Catalog, CatalogBuilder, Error, ErrorKind, Result};
3+
use iceberg_catalog_rest::RestCatalogBuilder;
4+
5+
6+
pub enum CatalogBuilderDef {
7+
Rest(RestCatalogBuilder),
8+
}
9+
10+
pub fn load(r#type: &str) -> Result<CatalogBuilderDef> {
11+
match r#type {
12+
"rest" => Ok(CatalogBuilderDef::Rest(RestCatalogBuilder::default())),
13+
_ => Err(Error::new(
14+
ErrorKind::FeatureUnsupported,
15+
format!("Unsupported catalog type: {}", r#type),
16+
)),
17+
}
18+
}
19+
20+
impl CatalogBuilderDef {
21+
pub fn name(self, name: impl Into<String>) -> Self {
22+
match self {
23+
CatalogBuilderDef::Rest(builder) => CatalogBuilderDef::Rest(builder.name(name)),
24+
}
25+
}
26+
27+
pub fn uri(self, uri: impl Into<String>) -> Self {
28+
match self {
29+
CatalogBuilderDef::Rest(builder) => CatalogBuilderDef::Rest(builder.uri(uri)),
30+
}
31+
}
32+
33+
pub fn warehouse(self, warehouse: impl Into<String>) -> Self {
34+
match self {
35+
CatalogBuilderDef::Rest(builder) => CatalogBuilderDef::Rest(builder.warehouse(warehouse)),
36+
}
37+
}
38+
39+
pub fn with_prop(self, key: impl Into<String>, value: impl Into<String>) -> Self {
40+
match self {
41+
CatalogBuilderDef::Rest(builder) => CatalogBuilderDef::Rest(builder.with_prop(key, value)),
42+
}
43+
}
44+
45+
pub async fn build(self) -> Result<Arc<dyn Catalog>> {
46+
match self {
47+
CatalogBuilderDef::Rest(builder) => builder.build()
48+
.await
49+
.map(|c| Arc::new(c) as Arc<dyn Catalog>),
50+
}
51+
}
52+
}

crates/iceberg/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ pub use error::{Error, ErrorKind, Result};
6262

6363
mod catalog;
6464

65-
pub use catalog::{
66-
Catalog, CatalogBuilder, Namespace, NamespaceIdent, TableCommit, TableCreation, TableIdent,
67-
TableRequirement, TableUpdate, ViewCreation,
68-
};
65+
pub use catalog::*;
6966

7067
pub mod table;
7168

0 commit comments

Comments
 (0)