You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "nastra (via GitHub)" <gi...@apache.org> on 2023/02/02 15:45:01 UTC

[GitHub] [iceberg] nastra commented on a diff in pull request #6712: Nessie: Support ApiV2 for Nessie client

nastra commented on code in PR #6712:
URL: https://github.com/apache/iceberg/pull/6712#discussion_r1094703306


##########
nessie/src/main/java/org/apache/iceberg/nessie/NessieCatalog.java:
##########
@@ -88,11 +89,22 @@ public void initialize(String name, Map<String, String> options) {
         options.get(removePrefix.apply(NessieConfigConstants.CONF_NESSIE_REF));
     String requestedHash =
         options.get(removePrefix.apply(NessieConfigConstants.CONF_NESSIE_REF_HASH));
-    NessieApiV1 api =
+
+    NessieClientBuilder<?> nessieClientBuilder =
         createNessieClientBuilder(
                 options.get(NessieConfigConstants.CONF_NESSIE_CLIENT_BUILDER_IMPL))
-            .fromConfig(x -> options.get(removePrefix.apply(x)))
-            .build(NessieApiV1.class);
+            .fromConfig(x -> options.get(removePrefix.apply(x)));
+    final String apiVersion = options.get(NessieUtil.CLIENT_API_VERSION);
+    NessieApiV1 api;
+    if (apiVersion == null || apiVersion.equalsIgnoreCase("v1")) {
+      // default version is set to v1.
+      api = nessieClientBuilder.build(NessieApiV1.class);
+    } else if (apiVersion.equalsIgnoreCase("v2")) {
+      api = nessieClientBuilder.build(NessieApiV2.class);
+    } else {
+      throw new IllegalArgumentException(
+          "Unsupported client-api-version: " + apiVersion + ". Can only be v1 or v2");

Review Comment:
   should this be using whatever `NessieUtil.CLIENT_API_VERSION` is set to?



##########
nessie/src/test/java/org/apache/iceberg/nessie/TestNamespace.java:
##########
@@ -73,6 +77,48 @@ public void testListNamespaces() {
     Assertions.assertThat(namespaces).isNotNull().hasSize(2);
   }
 
+  @Test
+  @NessieApiVersions(versions = NessieApiVersion.V1)
+  public void testNamespacesWithV1Api() {
+    createNamespacesAndTables();
+
+    testListTables();
+
+    List<Namespace> namespaces;
+    namespaces = catalog.listNamespaces(Namespace.of("foo"));
+    // NessieApiV1 should include both implicit and explicit namespaces
+    Assertions.assertThat(namespaces)
+        .containsExactlyInAnyOrder(Namespace.of("foo"), Namespace.of("foo", "bar"));
+  }
+
+  @Test
+  @NessieApiVersions(versions = NessieApiVersion.V2)
+  public void testNamespacesWithV2Api() {

Review Comment:
   could we have a single test and dynamically pick a different assertion based on the given API version? I think that would be better than having two separate tests



##########
nessie/src/test/java/org/apache/iceberg/nessie/TestNamespace.java:
##########
@@ -73,6 +77,48 @@ public void testListNamespaces() {
     Assertions.assertThat(namespaces).isNotNull().hasSize(2);
   }
 
+  @Test
+  @NessieApiVersions(versions = NessieApiVersion.V1)
+  public void testNamespacesWithV1Api() {
+    createNamespacesAndTables();
+
+    testListTables();
+
+    List<Namespace> namespaces;
+    namespaces = catalog.listNamespaces(Namespace.of("foo"));
+    // NessieApiV1 should include both implicit and explicit namespaces
+    Assertions.assertThat(namespaces)
+        .containsExactlyInAnyOrder(Namespace.of("foo"), Namespace.of("foo", "bar"));
+  }
+
+  @Test
+  @NessieApiVersions(versions = NessieApiVersion.V2)
+  public void testNamespacesWithV2Api() {
+    createNamespacesAndTables();
+
+    testListTables();
+
+    List<Namespace> namespaces;
+    namespaces = catalog.listNamespaces(Namespace.of("foo"));
+    // NessieApiV2 will not list the implicit namespaces
+    Assertions.assertThat(namespaces).isEqualTo(Collections.singletonList(Namespace.of("foo")));
+  }
+
+  private void testListTables() {

Review Comment:
   maybe rather name it `verifyListingTables` or something along those lines



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

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org