diff --git a/nessie/src/main/java/org/apache/iceberg/nessie/NessieCatalog.java b/nessie/src/main/java/org/apache/iceberg/nessie/NessieCatalog.java index af5457327442..0c91cfb1dbe1 100644 --- a/nessie/src/main/java/org/apache/iceberg/nessie/NessieCatalog.java +++ b/nessie/src/main/java/org/apache/iceberg/nessie/NessieCatalog.java @@ -95,7 +95,8 @@ public void initialize(String name, Map options) { options.get(NessieConfigConstants.CONF_NESSIE_CLIENT_BUILDER_IMPL)) .fromConfig(x -> options.get(removePrefix.apply(x))); // default version is set to v1. - final String apiVersion = options.getOrDefault(NessieUtil.CLIENT_API_VERSION, "1"); + final String apiVersion = + options.getOrDefault(removePrefix.apply(NessieUtil.CLIENT_API_VERSION), "1"); NessieApiV1 api; switch (apiVersion) { case "1": @@ -108,7 +109,7 @@ public void initialize(String name, Map options) { throw new IllegalArgumentException( String.format( "Unsupported %s: %s. Can only be 1 or 2", - NessieUtil.CLIENT_API_VERSION, apiVersion)); + removePrefix.apply(NessieUtil.CLIENT_API_VERSION), apiVersion)); } initialize( diff --git a/nessie/src/test/java/org/apache/iceberg/nessie/BaseTestIceberg.java b/nessie/src/test/java/org/apache/iceberg/nessie/BaseTestIceberg.java index bbc299dca0ab..5a9bbc273837 100644 --- a/nessie/src/test/java/org/apache/iceberg/nessie/BaseTestIceberg.java +++ b/nessie/src/test/java/org/apache/iceberg/nessie/BaseTestIceberg.java @@ -88,7 +88,7 @@ public abstract class BaseTestIceberg { protected NessieCatalog catalog; protected NessieApiV1 api; - private NessieApiVersion apiVersion; + protected String apiVersion; protected Configuration hadoopConfig; protected final String branch; private String initialHashOfDefaultBranch; @@ -123,7 +123,7 @@ public void beforeEach(NessieClientFactory clientFactory, @NessieClientUri URI n throws IOException { this.uri = nessieUri.toASCIIString(); this.api = clientFactory.make(); - this.apiVersion = clientFactory.apiVersion(); + this.apiVersion = clientFactory.apiVersion() == NessieApiVersion.V2 ? "2" : "1"; Branch defaultBranch = api.getDefaultBranch(); initialHashOfDefaultBranch = defaultBranch.getHash(); @@ -147,10 +147,8 @@ NessieCatalog initCatalog(String ref, String hash) { .put("ref", ref) .put(CatalogProperties.URI, uri) .put("auth-type", "NONE") - .put(CatalogProperties.WAREHOUSE_LOCATION, temp.toUri().toString()); - if (apiVersion == NessieApiVersion.V2) { - options.put(NessieUtil.CLIENT_API_VERSION, "2"); - } + .put(CatalogProperties.WAREHOUSE_LOCATION, temp.toUri().toString()) + .put("client-api-version", apiVersion); if (null != hash) { options.put("ref.hash", hash); } diff --git a/nessie/src/test/java/org/apache/iceberg/nessie/TestCustomNessieClient.java b/nessie/src/test/java/org/apache/iceberg/nessie/TestCustomNessieClient.java index 2a3c0c85e000..40341358073f 100644 --- a/nessie/src/test/java/org/apache/iceberg/nessie/TestCustomNessieClient.java +++ b/nessie/src/test/java/org/apache/iceberg/nessie/TestCustomNessieClient.java @@ -48,7 +48,9 @@ public void testNoCustomClient() { CatalogProperties.WAREHOUSE_LOCATION, temp.toUri().toString(), CatalogProperties.URI, - uri)); + uri, + "client-api-version", + apiVersion)); } @Test @@ -62,7 +64,9 @@ public void testUnnecessaryDefaultCustomClient() { CatalogProperties.URI, uri, NessieConfigConstants.CONF_NESSIE_CLIENT_BUILDER_IMPL, - HttpClientBuilder.class.getName())); + HttpClientBuilder.class.getName(), + "client-api-version", + apiVersion)); } @Test diff --git a/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieCatalog.java b/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieCatalog.java index 77e2de2c341a..130a984fa2a9 100644 --- a/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieCatalog.java +++ b/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieCatalog.java @@ -124,7 +124,7 @@ private NessieCatalog initNessieCatalog(String ref) { .put("auth-type", "NONE") .put(CatalogProperties.WAREHOUSE_LOCATION, temp.toUri().toString()); if (apiVersion == NessieApiVersion.V2) { - options.put(NessieUtil.CLIENT_API_VERSION, "2"); + options.put("client-api-version", "2"); } newCatalog.initialize("nessie", options.buildOrThrow()); return newCatalog; diff --git a/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieIcebergClient.java b/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieIcebergClient.java index 11dd0473a573..12fa807dcfb6 100644 --- a/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieIcebergClient.java +++ b/nessie/src/test/java/org/apache/iceberg/nessie/TestNessieIcebergClient.java @@ -96,10 +96,10 @@ public void testInvalidClientApiVersion() throws IOException { try (NessieCatalog newCatalog = new NessieCatalog()) { newCatalog.setConf(hadoopConfig); ImmutableMap.Builder options = - ImmutableMap.builder().put(NessieUtil.CLIENT_API_VERSION, "3"); + ImmutableMap.builder().put("client-api-version", "3"); Assertions.assertThatThrownBy(() -> newCatalog.initialize("nessie", options.buildOrThrow())) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("Unsupported nessie.client-api-version: 3. Can only be 1 or 2"); + .hasMessage("Unsupported client-api-version: 3. Can only be 1 or 2"); } } }