Skip to content

Commit 826d98f

Browse files
335gYoshiki Kudo
andauthored
feat(catalog): impl builder for SqlCatalog (apache#1666)
## Which issue does this PR close? - Closes apache#1626 ## What changes are included in this PR? - Introduced a new `SqlCatalogBuilder` implementation for `iceberg::CatalogBuilder`. - By transitioning the builder implementation from `SqlCatalogConfig` to `SqlCatalogBuilder`, we've simplified the process for creating `SqlCatalog` objects. - Enabled generation of `Box<dyn BoxedCatalogBuilder>` for the `SqlCatalog` via the `load` function (apache#1260) ## Are these changes tested? Yes (only tested whether it could be made) --------- Co-authored-by: Yoshiki Kudo <actionstar619@yahoo.co.jp>
1 parent 856597b commit 826d98f

File tree

7 files changed

+434
-27
lines changed

7 files changed

+434
-27
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ http = "1.2"
7878
iceberg = { version = "0.7.0", path = "./crates/iceberg" }
7979
iceberg-catalog-glue = { version = "0.7.0", path = "./crates/catalog/glue" }
8080
iceberg-catalog-hms = { version = "0.7.0", path = "./crates/catalog/hms" }
81+
iceberg-catalog-sql = { version = "0.7.0", path = "./crates/catalog/sql" }
8182
iceberg-catalog-rest = { version = "0.7.0", path = "./crates/catalog/rest" }
8283
iceberg-catalog-s3tables = { version = "0.7.0", path = "./crates/catalog/s3tables" }
8384
iceberg-datafusion = { version = "0.7.0", path = "./crates/integrations/datafusion" }
@@ -111,6 +112,7 @@ serde_repr = "0.1.16"
111112
serde_with = "3.4"
112113
smol = "2.0.2"
113114
sqllogictest = "0.28.3"
115+
sqlx = { version = "0.8.1", default-features = false }
114116
stacker = "0.1.20"
115117
strum = "0.27.2"
116118
tempfile = "3.18"

crates/catalog/loader/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,10 @@ iceberg-catalog-rest = { workspace = true }
3434
iceberg-catalog-glue = { workspace = true }
3535
iceberg-catalog-s3tables = { workspace = true }
3636
iceberg-catalog-hms = { workspace = true }
37+
iceberg-catalog-sql = { workspace = true }
3738
tokio = { workspace = true }
3839
async-trait = { workspace = true }
40+
41+
[dev-dependencies]
42+
sqlx = { workspace = true, features = ["runtime-tokio", "sqlite", "migrate"] }
43+
tempfile = { workspace = true }

crates/catalog/loader/src/lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use iceberg_catalog_glue::GlueCatalogBuilder;
2424
use iceberg_catalog_hms::HmsCatalogBuilder;
2525
use iceberg_catalog_rest::RestCatalogBuilder;
2626
use iceberg_catalog_s3tables::S3TablesCatalogBuilder;
27+
use iceberg_catalog_sql::SqlCatalogBuilder;
2728

2829
/// A CatalogBuilderFactory creating a new catalog builder.
2930
type CatalogBuilderFactory = fn() -> Box<dyn BoxedCatalogBuilder>;
@@ -34,6 +35,7 @@ static CATALOG_REGISTRY: &[(&str, CatalogBuilderFactory)] = &[
3435
("glue", || Box::new(GlueCatalogBuilder::default())),
3536
("s3tables", || Box::new(S3TablesCatalogBuilder::default())),
3637
("hms", || Box::new(HmsCatalogBuilder::default())),
38+
("sql", || Box::new(SqlCatalogBuilder::default())),
3739
];
3840

3941
/// Return the list of supported catalog types.
@@ -108,6 +110,9 @@ impl CatalogLoader<'_> {
108110
mod tests {
109111
use std::collections::HashMap;
110112

113+
use sqlx::migrate::MigrateDatabase;
114+
use tempfile::TempDir;
115+
111116
use crate::{CatalogLoader, load};
112117

113118
#[tokio::test]
@@ -220,6 +225,35 @@ mod tests {
220225
assert!(catalog.is_ok());
221226
}
222227

228+
fn temp_path() -> String {
229+
let temp_dir = TempDir::new().unwrap();
230+
temp_dir.path().to_str().unwrap().to_string()
231+
}
232+
233+
#[tokio::test]
234+
async fn test_catalog_loader_pattern_sql_catalog() {
235+
use iceberg_catalog_sql::{SQL_CATALOG_PROP_URI, SQL_CATALOG_PROP_WAREHOUSE};
236+
237+
let uri = format!("sqlite:{}", temp_path());
238+
sqlx::Sqlite::create_database(&uri).await.unwrap();
239+
240+
let catalog_loader = load("sql").unwrap();
241+
let catalog = catalog_loader
242+
.load(
243+
"sql".to_string(),
244+
HashMap::from([
245+
(SQL_CATALOG_PROP_URI.to_string(), uri),
246+
(
247+
SQL_CATALOG_PROP_WAREHOUSE.to_string(),
248+
"s3://warehouse".to_string(),
249+
),
250+
]),
251+
)
252+
.await;
253+
254+
assert!(catalog.is_ok());
255+
}
256+
223257
#[tokio::test]
224258
async fn test_error_message_includes_supported_types() {
225259
let err = match load("does-not-exist") {

crates/catalog/sql/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ repository = { workspace = true }
3232
async-trait = { workspace = true }
3333
iceberg = { workspace = true }
3434
sqlx = { version = "0.8.1", features = ["any"], default-features = false }
35-
typed-builder = { workspace = true }
35+
strum = { workspace = true }
3636

3737
[dev-dependencies]
38-
iceberg_test_utils = { path = "../../test_utils", features = ["tests"] }
3938
itertools = { workspace = true }
4039
regex = "1.10.5"
4140
sqlx = { version = "0.8.1", features = [

0 commit comments

Comments
 (0)