RussellSpitzer commented on a change in pull request #4348:
URL: https://github.com/apache/iceberg/pull/4348#discussion_r831295351



##########
File path: core/src/main/java/org/apache/iceberg/rest/RESTTableOperations.java
##########
@@ -0,0 +1,212 @@
+/*
+ * 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.rest;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Consumer;
+import org.apache.iceberg.LocationProviders;
+import org.apache.iceberg.MetadataUpdate;
+import org.apache.iceberg.TableMetadata;
+import org.apache.iceberg.TableOperations;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.encryption.EncryptionManager;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.LocationProvider;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.rest.requests.UpdateTableRequest;
+import org.apache.iceberg.rest.responses.ErrorResponse;
+import org.apache.iceberg.rest.responses.LoadTableResponse;
+
+class RESTTableOperations implements TableOperations {
+  private static final String METADATA_FOLDER_NAME = "metadata";
+
+  enum UpdateType {
+    CREATE,
+    REPLACE,
+    SIMPLE
+  }
+
+  private final RESTClient client;
+  private final String path;
+  private final FileIO io;
+  private final List<MetadataUpdate> createChanges;
+  private final TableMetadata replaceBase;
+  private UpdateType updateType;
+  private TableMetadata current;
+
+  RESTTableOperations(RESTClient client, String path, FileIO io, TableMetadata 
current) {
+    this(client, path, io, UpdateType.SIMPLE, Lists.newArrayList(), current);
+  }
+
+  RESTTableOperations(RESTClient client, String path, FileIO io, UpdateType 
updateType,
+                      List<MetadataUpdate> createChanges, TableMetadata 
current) {
+    this.client = client;
+    this.path = path;
+    this.io = io;
+    this.updateType = updateType;
+    this.createChanges = createChanges;
+    this.replaceBase = current;
+    if (updateType == UpdateType.CREATE) {
+      this.current = null;
+    } else {
+      this.current = current;
+    }
+  }
+
+  @Override
+  public TableMetadata current() {
+    return current;
+  }
+
+  @Override
+  public TableMetadata refresh() {
+    return updateCurrentMetadata(client.get(path, LoadTableResponse.class, 
ErrorHandlers.tableErrorHandler()));
+  }
+
+  @Override
+  public void commit(TableMetadata base, TableMetadata metadata) {
+    UpdateTableRequest.Builder requestBuilder;
+    List<MetadataUpdate> baseChanges;
+    Consumer<ErrorResponse> errorHandler;
+    switch (updateType) {
+      case CREATE:
+        Preconditions.checkState(base == null, "Invalid base metadata for 
create transaction, expected null: %s", base);
+        requestBuilder = UpdateTableRequest.builderForCreate();
+        baseChanges = createChanges;
+        errorHandler = ErrorHandlers.tableErrorHandler(); // throws 
NoSuchTableException

Review comment:
       I see it has
   
   
https://github.com/apache/iceberg/blob/master/core/src/main/java/org/apache/iceberg/rest/ErrorHandlers.java#L80
   
   Which we do want




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