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


##########
nessie/src/test/java/org/apache/iceberg/nessie/TestNessieTable.java:
##########
@@ -323,22 +321,35 @@ public void testExistingTableUpdate() {
   }
 
   @Test
-  public void testFailure() throws NessieNotFoundException, 
NessieConflictException {
+  public void testCommitsOutsideOfCatalogApi() throws NessieNotFoundException, 
NessieConflictException {
     Table icebergTable = catalog.loadTable(TABLE_IDENTIFIER);
     Branch branch = (Branch) api.getReference().refName(BRANCH).get();
-
-    IcebergTable table = getTable(BRANCH, KEY);
+    
Assertions.assertThat(api.getCommitLog().refName(BRANCH).get().getLogEntries())
+        .extracting(e -> e.getCommitMeta().getHash())
+        .hasSize(1)
+        .containsExactly(branch.getHash());
 
     IcebergTable value = IcebergTable.of("dummytable.metadata.json", 42, 42, 
42, 42, "cid");
-    api.commitMultipleOperations().branch(branch)
+    // we do a separate manual commit outside of the catalog API
+    Branch commit = api.commitMultipleOperations().branch(branch)
         .operation(Operation.Put.of(KEY, value))
         .commitMeta(CommitMeta.fromMessage(""))
         .commit();
-
-    Assertions.assertThatThrownBy(() -> 
icebergTable.updateSchema().addColumn("data", Types.LongType.get()).commit())
-        .isInstanceOf(CommitFailedException.class)
-        .hasMessage(
-            "Cannot commit: Reference hash is out of date. Update the 
reference iceberg-table-test and try again");
+    
Assertions.assertThat(api.getCommitLog().refName(BRANCH).get().getLogEntries())
+        .extracting(e -> e.getCommitMeta().getHash())
+        .hasSize(2)
+        .containsExactly(commit.getHash(), branch.getHash());
+
+    // previously this would fail with "Cannot commit: Reference hash is out 
of date. Update the reference ..."

Review Comment:
   done



##########
nessie/src/main/java/org/apache/iceberg/nessie/NessieIcebergClient.java:
##########
@@ -0,0 +1,334 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iceberg.nessie;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.exceptions.AlreadyExistsException;
+import org.apache.iceberg.exceptions.CommitFailedException;
+import org.apache.iceberg.exceptions.CommitStateUnknownException;
+import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.apache.iceberg.exceptions.NoSuchTableException;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.util.Tasks;
+import org.projectnessie.client.NessieConfigConstants;
+import org.projectnessie.client.api.CommitMultipleOperationsBuilder;
+import org.projectnessie.client.api.NessieApiV1;
+import org.projectnessie.client.http.HttpClientException;
+import org.projectnessie.error.BaseNessieClientServerException;
+import org.projectnessie.error.NessieConflictException;
+import org.projectnessie.error.NessieNamespaceAlreadyExistsException;
+import org.projectnessie.error.NessieNamespaceNotEmptyException;
+import org.projectnessie.error.NessieNamespaceNotFoundException;
+import org.projectnessie.error.NessieNotFoundException;
+import org.projectnessie.error.NessieReferenceNotFoundException;
+import org.projectnessie.model.Branch;
+import org.projectnessie.model.Content;
+import org.projectnessie.model.ContentKey;
+import org.projectnessie.model.EntriesResponse;
+import org.projectnessie.model.GetNamespacesResponse;
+import org.projectnessie.model.IcebergTable;
+import org.projectnessie.model.Operation;
+import org.projectnessie.model.Reference;
+import org.projectnessie.model.Tag;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NessieIcebergClient implements AutoCloseable {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(NessieIcebergClient.class);
+
+  private final NessieApiV1 api;
+  private final Supplier<UpdateableReference> reference;
+  private final Map<String, String> catalogOptions;
+
+  public NessieIcebergClient(
+      NessieApiV1 api, String requestedRef, String requestedHash, Map<String, 
String> catalogOptions) {
+    this.api = api;
+    this.catalogOptions = catalogOptions;
+    this.reference = () -> loadReference(requestedRef, requestedHash);
+  }
+
+  public NessieApiV1 getApi() {
+    return api;
+  }
+
+  public UpdateableReference getRef() {
+    return reference.get();
+  }
+
+  public void refresh() throws NessieNotFoundException {
+    getRef().refresh(api);
+  }
+
+  public NessieIcebergClient withReference(String requestedRef, String hash) {
+    if (null == requestedRef) {
+      return this;
+    }
+    return new NessieIcebergClient(getApi(), requestedRef, hash, 
catalogOptions);
+  }
+
+  private UpdateableReference loadReference(String requestedRef, String hash) {
+    try {
+      Reference ref =
+          requestedRef == null ? api.getDefaultBranch() : 
api.getReference().refName(requestedRef).get();
+      if (hash != null) {
+        if (ref instanceof Branch) {
+          ref = Branch.of(ref.getName(), hash);
+        } else {
+          ref = Tag.of(ref.getName(), hash);
+        }
+      }
+      return new UpdateableReference(ref, hash != null);
+    } catch (NessieNotFoundException ex) {
+      if (requestedRef != null) {
+        throw new IllegalArgumentException(String.format("Nessie ref '%s' does 
not exist. This ref must exist " +
+            "before creating a NessieCatalog.", requestedRef), ex);

Review Comment:
   updated



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to