rdblue commented on a change in pull request #2345:
URL: https://github.com/apache/iceberg/pull/2345#discussion_r597299531
##########
File path: nessie/src/main/java/org/apache/iceberg/nessie/NessieCatalog.java
##########
@@ -78,31 +78,63 @@
private UpdateableReference reference;
private String name;
private FileIO fileIO;
+ private boolean initialized;
public NessieCatalog() {
}
@Override
public void initialize(String inputName, Map<String, String> options) {
- String fileIOImpl = options.get(CatalogProperties.FILE_IO_IMPL);
- this.fileIO = fileIOImpl == null ? new HadoopFileIO(config) :
CatalogUtil.loadFileIO(fileIOImpl, options, config);
- this.name = inputName == null ? "nessie" : inputName;
- // remove nessie prefix
- final Function<String, String> removePrefix = x -> x.replace("nessie.",
"");
+ if (initialized) {
+ close();
+ }
+ if (config == null) {
+ throw new IllegalStateException(String.format("setConf() must be called
before initialize() for NessieCatalog '%s'", name));
+ }
+
+ try {
+ String fileIOImpl = options.get(CatalogProperties.FILE_IO_IMPL);
+ this.fileIO = fileIOImpl == null ? new HadoopFileIO(config) :
CatalogUtil.loadFileIO(fileIOImpl, options, config);
+ this.name = inputName == null ? "nessie" : inputName;
+ // remove nessie prefix
+ final Function<String, String> removePrefix = x -> x.replace("nessie.",
"");
- this.client = NessieClient.builder().fromConfig(x ->
options.get(removePrefix.apply(x))).build();
+ this.client = NessieClient.builder().fromConfig(x ->
options.get(removePrefix.apply(x))).build();
- this.warehouseLocation = options.get(CatalogProperties.WAREHOUSE_LOCATION);
- if (warehouseLocation == null) {
- throw new IllegalStateException("Parameter warehouse not set, nessie
can't store data.");
+ this.warehouseLocation =
options.get(CatalogProperties.WAREHOUSE_LOCATION);
+ if (warehouseLocation == null) {
+ throw new IllegalStateException("Parameter warehouse not set, nessie
can't store data.");
+ }
+ final String requestedRef =
options.get(removePrefix.apply(NessieConfigConstants.CONF_NESSIE_REF));
+ this.reference = loadReference(requestedRef);
+
+ this.initialized = true;
+ } catch (RuntimeException e) {
+ close();
+ throw new RuntimeException("Failed to initialize NessieCatalog with
options " + options);
+ }
+ }
+
+ private void assertInitialized() {
Review comment:
We could add static `create` methods that accept the `initialize`
arguments. Then the class could handle it internally:
```java
public static NessieCatalog create(String name, Map<String, String> config) {
NessieCatalog newCatalog = new NessieCatalog();
newCatalog.initialize(name, config);
return newCatalog;
}
```
That seems like the right way to handle direct catalog creation, since we no
longer support the direct constructors.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]