RussellSpitzer commented on code in PR #4491: URL: https://github.com/apache/iceberg/pull/4491#discussion_r853261544
########## 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: Message here may be confusing since this is no longer part of a catalog class, although it only would be called by a catalog class .... -- 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]
