Skip to content

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

Merged
liurenjie1024 merged 7 commits intoapache:mainfrom
lliangyu-lin:catalog-builder
Aug 11, 2025
Merged

feat(catalog): Add catalog loader and builder implementation for rest catalog#1580
liurenjie1024 merged 7 commits intoapache:mainfrom
lliangyu-lin:catalog-builder

Conversation

@lliangyu-lin
Copy link
Copy Markdown
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
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.


/// Rest catalog configuration.
#[derive(Clone, Debug, TypedBuilder)]
pub struct RestCatalogConfig {
Copy link
Copy Markdown
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
Copy Markdown
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.

RegisterTableRequest, RenameTableRequest,
};

const REST_CATALOG_PROP_URI: &str = "uri";
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator

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
Yiyang-C pushed a commit to Yiyang-C/iceberg-rust that referenced this pull request Aug 26, 2025
… catalog (apache#1580)

## Which issue does this PR close?

- Part of apache#1260 
- Closes apache#1255

## What changes are included in this PR?

* Some of the implementations are directly coming from the design in
apache#1231
* Added a new crate `loader` for loading catalog based on type. 
* Implement the CatalogBuilder trait for rest catalog

## Are these changes tested?

Yes, by unit tests

---------

Co-authored-by: liurenjie1024 <liurenjie2008@gmail.com>
Yiyang-C pushed a commit to Yiyang-C/iceberg-rust that referenced this pull request Aug 26, 2025
## Which issue does this PR close?


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


## Are these changes tested?
Using the existing uts
@colinmarc
Copy link
Copy Markdown
Contributor

Hi, this change (particularly removing RestCatalogConfig) made the API even more unergonomic than it was before. What's the rational for moving from a typed interface to an untyped one (hashmap of strings)? At the risk of being glib, this reads more like Java than Rust 🙃

@liurenjie1024
Copy link
Copy Markdown
Contributor

Hi, this change (particularly removing RestCatalogConfig) made the API even more unergonomic than it was before. What's the rational for moving from a typed interface to an untyped one (hashmap of strings)? At the risk of being glib, this reads more like Java than Rust 🙃

The motivation behind the refactoring is to have an unified way to load catalogs. We had some discussions about type safe configs, but we need to a design for it. The old RestCatalogConfig approach is not the desired approach for type safe configs.

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.

4 participants