Skip to content

feat(catalog): Add catalog loader and builder implementation for rest catalog #1580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 11, 2025

Conversation

lliangyu-lin
Copy link
Contributor

Which issue does this PR close?

What changes are included in this PR?

Are these changes tested?

Yes, by unit tests

use iceberg_catalog_rest::RestCatalogBuilder;

#[async_trait]
pub trait BoxedCatalogBuilder {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just put this in builder.rs under /crates/catalog/rest/src/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look!
I'm not sure if it's necessary because I think BoxedCatalogBuilder is suppose to be generic to use for all catalog builder implementations. Like in L42, we simply call the load method in the trait to return the corresponding catalog and can be extended to add more catalogs in load, so it's not really rest catalog specific.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I meant the common code like this can be put under crates/iceberg/src/catalog/mod.rs. I don't see the need of adding another module here, maybe I'm missing anything?

Also I'm thinking if Box<Self> will be common across all catalog builders, maybe we can just change the CatalogBuilder trait to be self: Arc<Self> or self: Box<Self>, so we don't need to define a wrapper trait like this, wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For putting these in crates/iceberg/src/catalog/mod.rs, I think it's fine, but if we want to add it as dependency to playground or integration test framework, does it mean we need to import the catalog crate individually?

For the Box<Self>, I think we are only consuming the CatalogBuilder and doesn't need to share it, so I think Box<Self> is fine. cc: @liurenjie1024 wondering if you have any suggestion on this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the Box, I think we are only consuming the CatalogBuilder and doesn't need to share it, so I think Box is fine.

+1. I think it's fine to put the BoxedCatalogBuilder here since it's mainly used by load function.

Copy link
Contributor

@liurenjie1024 liurenjie1024 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lliangyu-lin for this pr, generally LGTM! Just missing some doc and a little change.

use iceberg_catalog_rest::RestCatalogBuilder;

#[async_trait]
pub trait BoxedCatalogBuilder {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the Box, I think we are only consuming the CatalogBuilder and doesn't need to share it, so I think Box is fine.

+1. I think it's fine to put the BoxedCatalogBuilder here since it's mainly used by load function.

@@ -45,13 +46,18 @@ use crate::types::{
RegisterTableRequest, RenameTableRequest,
};

const REST_CATALOG_PROP_URI: &str = "uri";
const REST_CATALOG_PROP_WAREHOUSE: &str = "warehouse";
const ICEBERG_REST_SPEC_VERSION: &str = "0.14.1";
const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
const PATH_V1: &str = "v1";

/// Rest catalog configuration.
#[derive(Clone, Debug, TypedBuilder)]
pub struct RestCatalogConfig {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mark this as crate private, and adding doc to explain how to load a RestCatalog with the new approach, e.g. using the RestCatalogBuilder. Otherwise user will be confusing since we will have two methods for building rest catalog.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the RestCatalogConfig crate private, seems like it's backward incompatible change as previous catalog new will require a RestCatalogConfig.

@@ -45,13 +46,113 @@ use crate::types::{
RegisterTableRequest, RenameTableRequest,
};

const REST_CATALOG_PROP_URI: &str = "uri";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make them public as users are epxecting to use these constants rather than raw string.

Comment on lines 55 to 79
/// Builder for [`RestCatalog`].
/// To build a rest catalog with configurations
///
/// # Example
///
/// ```rust, no_run
/// use std::collections::HashMap;
///
/// use iceberg::CatalogBuilder;
/// use iceberg_catalog_rest::RestCatalogBuilder;
///
/// #[tokio::main]
/// async fn main() {
/// let catalog = RestCatalogBuilder::default()
/// .load(
/// "rest",
/// HashMap::from([
/// ("uri".to_string(), "http://localhost:8181".to_string()),
/// ("warehouse".to_string(), "s3://warehouse".to_string()),
/// ]),
/// )
/// .await
/// .unwrap();
/// }
/// ```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving this crate's doc, e.g. in lib.rs? This should be the first thing a user sees when using this crate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I think moving to lib.rs make sense.

/// .load(
/// "rest",
/// HashMap::from([
/// ("uri".to_string(), "http://localhost:8181".to_string()),
Copy link
Contributor

@liurenjie1024 liurenjie1024 Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use constants rather than raw string as better practice. Please change all occurences.

Copy link
Contributor

@liurenjie1024 liurenjie1024 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lliangyu-lin for this pr!

@liurenjie1024 liurenjie1024 merged commit b174c45 into apache:main Aug 11, 2025
18 checks passed
@CTTY
Copy link
Contributor

CTTY commented Aug 11, 2025

It seems this PR didn't include the Cargo.lock changes, I've put up a minor follow-up here: #1596

liurenjie1024 pushed a commit that referenced this pull request Aug 12, 2025
## Which issue does this PR close?


- None
## What changes are included in this PR?
- Auto-update `Cargo.lock` based on the changes from #1580 


## Are these changes tested?
Using the existing uts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement rest catalog loader.
3 participants