Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions crates/integrations/playground/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@ fs-err = { workspace = true }
home = { workspace = true }
iceberg = { workspace = true }
iceberg-catalog-rest = { workspace = true }
iceberg-catalog-sql = { workspace = true }
iceberg-datafusion = { workspace = true }
sqlx = { workspace = true, features = ["runtime-tokio", "sqlite", "migrate"] }
mimalloc = { workspace = true }
stacker = { workspace = true }
tokio = { workspace = true }
toml = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }

[dev-dependencies]
uuid = { workspace = true, features = ["v4"] }

[package.metadata.cargo-machete]
# These dependencies are added to ensure minimal dependency version
ignored = ["stacker", "mimalloc", "home"]
43 changes: 41 additions & 2 deletions crates/integrations/playground/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use fs_err::read_to_string;
use iceberg::CatalogBuilder;
use iceberg::memory::MemoryCatalogBuilder;
use iceberg_catalog_rest::RestCatalogBuilder;
use iceberg_catalog_sql::SqlCatalogBuilder;
use iceberg_datafusion::IcebergCatalogProvider;
use toml::{Table as TomlTable, Value};

Expand Down Expand Up @@ -97,10 +98,11 @@ impl IcebergCatalogList {
// Create catalog based on type using the appropriate builder
let catalog: Arc<dyn iceberg::Catalog> = match r#type {
"rest" => Arc::new(RestCatalogBuilder::default().load(name, props).await?),
"sql" => Arc::new(SqlCatalogBuilder::default().load(name, props).await?),
"memory" => Arc::new(MemoryCatalogBuilder::default().load(name, props).await?),
_ => {
return Err(anyhow::anyhow!(
"Unsupported catalog type: '{type}'. Supported types: rest, memory"
"Unsupported catalog type: '{type}'. Supported types: rest, sql, memory"
));
}
};
Expand Down Expand Up @@ -139,8 +141,45 @@ impl CatalogProviderList for IcebergCatalogList {

#[cfg(test)]
mod tests {
use sqlx::migrate::MigrateDatabase;

use super::*;

fn temp_path() -> String {
let uuid = uuid::Uuid::new_v4();
format!("/tmp/iceberg-test-{uuid}")
}

#[tokio::test]
async fn test_parse_sql_catalog() {
let db_path = temp_path();
let sql_uri = format!("sqlite:{db_path}");

// Create the SQLite database file first
sqlx::Sqlite::create_database(&sql_uri).await.unwrap();

let config = format!(
r#"
[[catalogs]]
name = "test_sql"
type = "sql"
[catalogs.config]
uri = "{sql_uri}"
warehouse = "/tmp/sql-warehouse"
"#
);

let toml_table: TomlTable = toml::from_str(&config).unwrap();
let catalog_list = IcebergCatalogList::parse_table(&toml_table).await.unwrap();

assert!(
catalog_list
.catalog_names()
.contains(&"test_sql".to_string())
);
assert!(catalog_list.catalog("test_sql").is_some());
}

#[tokio::test]
async fn test_parse_memory_catalog() {
let config = r#"
Expand Down Expand Up @@ -179,7 +218,7 @@ mod tests {
let err_msg = result.unwrap_err().to_string();
assert!(err_msg.contains("Unsupported catalog type"));
assert!(err_msg.contains("hive"));
assert!(err_msg.contains("rest, memory"));
assert!(err_msg.contains("rest, sql, memory"));
}

#[tokio::test]
Expand Down
Loading