-
Notifications
You must be signed in to change notification settings - Fork 297
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
Conversation
use iceberg_catalog_rest::RestCatalogBuilder; | ||
|
||
#[async_trait] | ||
pub trait BoxedCatalogBuilder { |
There was a problem hiding this comment.
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/
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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.
crates/catalog/rest/src/catalog.rs
Outdated
@@ -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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
crates/catalog/rest/src/catalog.rs
Outdated
@@ -45,13 +46,113 @@ use crate::types::{ | |||
RegisterTableRequest, RenameTableRequest, | |||
}; | |||
|
|||
const REST_CATALOG_PROP_URI: &str = "uri"; |
There was a problem hiding this comment.
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.
crates/catalog/rest/src/catalog.rs
Outdated
/// 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(); | ||
/// } | ||
/// ``` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
crates/catalog/rest/src/catalog.rs
Outdated
/// .load( | ||
/// "rest", | ||
/// HashMap::from([ | ||
/// ("uri".to_string(), "http://localhost:8181".to_string()), |
There was a problem hiding this comment.
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.
There was a problem hiding this 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!
It seems this PR didn't include the |
## 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
Which issue does this PR close?
What changes are included in this PR?
loader
for loading catalog based on type.Are these changes tested?
Yes, by unit tests