Repository navigation
API: Introduce a builder in Catalog - #1409
Conversation
|
@rdblue @RussellSpitzer @rdsr this is the builder we discussed here. |
|
I think there's a slight problem with the approach that this uses. This creates a builder that interacts with the public Since the builder ends up calling Ideally, the builder would create |
|
Random aside, have you guys considered using Immutables? We've started to use it extensively other places as it does a nice job of several things around pojo and builders. It's also nice as it is an annotation processor and creates no runtime dependency (but still produces inspectable code, as opposed to something like lombok, which is pretty much black box) |
| * <p> | ||
| * Call {@link #buildTable(TableIdentifier, Schema)} to create a new builder. | ||
| */ | ||
| interface TableBuilder { |
There was a problem hiding this comment.
I'll need to fix CachingCatalog.
There was a problem hiding this comment.
Also, we will need to add extra validation to the builder in HadoopCatalog.
There was a problem hiding this comment.
Okay, I added validation for HadoopCatalog but we can add support for buildTable in CachingCatalog later. Looks like we will need a separate builder implementation that would delegate to another builder but add caching callbacks.
| * @return the builder to create a table or start a create/replace transaction | ||
| */ | ||
| default TableBuilder buildTable(TableIdentifier identifier, Schema schema) { | ||
| throw new UnsupportedOperationException(this.getClass().getName() + " does not implement buildTable"); |
There was a problem hiding this comment.
I am throwing UnsupportedOperationException to avoid breaking custom catalogs.
| PartitionSpec spec, | ||
| String location, | ||
| Map<String, String> properties) { | ||
| Preconditions.checkArgument(isValidIdentifier(identifier), "Invalid table identifier: %s", identifier); |
There was a problem hiding this comment.
I moved this logic to the builder and use the builder here.
| private String location = null; | ||
|
|
||
| protected BaseMetastoreCatalogTableBuilder(TableIdentifier identifier, Schema schema) { | ||
| Preconditions.checkArgument(isValidIdentifier(identifier), "Invalid table identifier: %s", identifier); |
There was a problem hiding this comment.
We did not validate this for replace transactions before but there should be no harm.
| } | ||
|
|
||
| @Override | ||
| public Table createTable( |
There was a problem hiding this comment.
This is now validated in the builder.
bc31599 to
24fed04
Compare
|
+1 when conflicts are addressed and tests are passing. |
RussellSpitzer
left a comment
There was a problem hiding this comment.
Minor Question on null handling, but this looks much cleaner to me than before!
|
|
||
| @Override | ||
| public TableBuilder withPartitionSpec(PartitionSpec newSpec) { | ||
| if (spec != null) { |
There was a problem hiding this comment.
Why allow null here? We used to allow null for the parameter because you had to pass it, but now you don't have to pass it so maybe we should reject null?
|
|
||
| @Override | ||
| public TableBuilder withProperties(Map<String, String> properties) { | ||
| if (properties != null) { |
There was a problem hiding this comment.
We used to have this because overloaded createTable methods pass null for props:
Map<String, String> tableProperties = properties != null ? properties : Maps.newHashMap();
Since we are using the builder for the root createTable now, I added handling here too. For partition spec, it is optional but probably makes sense for consistency.
24fed04 to
bc9e2f0
Compare
|
@jacques-n, I haven't seen immutables before. How is your impression? Is the naming of generated methods fixed? |
I'm not sure whether you mean "fixed" as in broken or "fixed" as in not-customizable. If the former, I'm not sure what you're referring to. If the latter, yes there is some control to customize the method names: We find that it is relatively painless to use, has good IDE integration and removes a lot of boilerplate code. Allows us to do a better job of creating domain specific model classes in different layers rather than over-sharing them. |
This PR introduces a builder in
Catalogto avoid duplicating the number of methods each time we introduce a new param.