nastra commented on a change in pull request #4241:
URL: https://github.com/apache/iceberg/pull/4241#discussion_r819658001



##########
File path: core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
##########
@@ -319,6 +381,556 @@ public void testNamespaceWithDot() {
     Assert.assertFalse("Namespace should not exist", 
catalog.namespaceExists(withDot));
   }
 
+  @Test

Review comment:
       nit: would it make sense to pull these out into a separate PR so that we 
get those in sooner? Unless this PR won't take too long to be merged of course 

##########
File path: core/src/main/java/org/apache/iceberg/rest/RESTCatalogAdapter.java
##########
@@ -0,0 +1,352 @@
+/*
+ * Licensed 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.io.Closeable;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+import org.apache.iceberg.catalog.Catalog;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.SupportsNamespaces;
+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.ForbiddenException;
+import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
+import org.apache.iceberg.exceptions.NoSuchIcebergTableException;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.apache.iceberg.exceptions.NoSuchTableException;
+import org.apache.iceberg.exceptions.NotAuthorizedException;
+import org.apache.iceberg.exceptions.RESTException;
+import org.apache.iceberg.exceptions.ValidationException;
+import org.apache.iceberg.relocated.com.google.common.base.Splitter;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.rest.requests.CreateNamespaceRequest;
+import org.apache.iceberg.rest.requests.CreateTableRequest;
+import org.apache.iceberg.rest.requests.UpdateNamespacePropertiesRequest;
+import org.apache.iceberg.rest.requests.UpdateTableRequest;
+import org.apache.iceberg.rest.responses.ErrorResponse;
+import org.apache.iceberg.util.Pair;
+
+/**
+ * Adaptor class to translate REST requests into {@link Catalog} API calls.
+ */
+public class RESTCatalogAdapter implements RESTClient {
+  private static final Splitter SLASH = Splitter.on('/');
+  private static final Splitter NULL = Splitter.on('\0');
+
+  private static final Map<Class<? extends Exception>, Integer> 
EXCEPTION_ERROR_CODES = ImmutableMap
+      .<Class<? extends Exception>, Integer>builder()
+      .put(IllegalArgumentException.class, 400)
+      .put(ValidationException.class, 400)
+      .put(NamespaceNotEmptyException.class, 400) // TODO: should this be more 
specific?
+      .put(NotAuthorizedException.class, 401)
+      .put(ForbiddenException.class, 403)
+      .put(NoSuchNamespaceException.class, 404)
+      .put(NoSuchTableException.class, 404)
+      .put(NoSuchIcebergTableException.class, 404)
+      .put(UnsupportedOperationException.class, 406)
+      .put(AlreadyExistsException.class, 409)
+      .put(CommitFailedException.class, 409)
+      .put(CatalogHandlers.UnprocessableEntityException.class, 422)
+      .put(CommitStateUnknownException.class, 500)
+      .build();
+
+  private final Catalog catalog;
+  private final SupportsNamespaces asNamespaceCatalog;
+  private final Consumer<ErrorResponse> defaultErrorHandler;
+
+  public RESTCatalogAdapter(Catalog catalog, Consumer<ErrorResponse> 
defaultErrorHandler) {
+    this.catalog = catalog;
+    this.asNamespaceCatalog = catalog instanceof SupportsNamespaces ? 
(SupportsNamespaces) catalog : null;
+    this.defaultErrorHandler = defaultErrorHandler;
+  }
+
+  private enum HTTPMethod {
+    GET,
+    HEAD,
+    POST,
+    DELETE
+  }
+
+  private enum Route {
+    CONFIG(HTTPMethod.GET, "v1/config"),
+    LIST_NAMESPACES(HTTPMethod.GET, "v1/namespaces"),
+    CREATE_NAMESPACE(HTTPMethod.POST, "v1/namespaces"),
+    LOAD_NAMESPACE(HTTPMethod.GET, "v1/namespaces/{namespace}"),
+    DROP_NAMESPACE(HTTPMethod.DELETE, "v1/namespaces/{namespace}"),
+    UPDATE_NAMESPACE(HTTPMethod.POST, "v1/namespaces/{namespace}/properties"),
+    LIST_TABLES(HTTPMethod.GET, "v1/namespaces/{namespace}/tables"),
+    CREATE_TABLE(HTTPMethod.POST, "v1/namespaces/{namespace}/tables"),
+    LOAD_TABLE(HTTPMethod.GET, "v1/namespaces/{namespace}/tables/{table}"),
+    UPDATE_TABLE(HTTPMethod.POST, "v1/namespaces/{namespace}/tables/{table}"),
+    DROP_TABLE(HTTPMethod.DELETE, "v1/namespaces/{namespace}/tables/{table}");
+
+    private final HTTPMethod method;
+    private final int requriedLength;
+    private final Map<Integer, String> requirements;
+    private final Map<Integer, String> variables;
+
+    Route(HTTPMethod method, String pattern) {
+      this.method = method;
+
+      // parse the pattern into requirements and variables
+      List<String> parts = SLASH.splitToList(pattern);
+      ImmutableMap.Builder<Integer, String> requirementsBuilder = 
ImmutableMap.builder();
+      ImmutableMap.Builder<Integer, String> variablesBuilder = 
ImmutableMap.builder();
+      for (int pos = 0; pos < parts.size(); pos += 1) {
+        String part = parts.get(pos);
+        if (part.startsWith("{") && part.endsWith("}")) {
+          variablesBuilder.put(pos, part.substring(1, part.length() - 1));
+        } else {
+          requirementsBuilder.put(pos, part);
+        }
+      }
+
+      this.requriedLength = parts.size();

Review comment:
       nit: typo in `requriedLength`

##########
File path: core/src/main/java/org/apache/iceberg/rest/RESTCatalogAdapter.java
##########
@@ -0,0 +1,352 @@
+/*
+ * Licensed 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.io.Closeable;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+import org.apache.iceberg.catalog.Catalog;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.SupportsNamespaces;
+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.ForbiddenException;
+import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
+import org.apache.iceberg.exceptions.NoSuchIcebergTableException;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.apache.iceberg.exceptions.NoSuchTableException;
+import org.apache.iceberg.exceptions.NotAuthorizedException;
+import org.apache.iceberg.exceptions.RESTException;
+import org.apache.iceberg.exceptions.ValidationException;
+import org.apache.iceberg.relocated.com.google.common.base.Splitter;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.rest.requests.CreateNamespaceRequest;
+import org.apache.iceberg.rest.requests.CreateTableRequest;
+import org.apache.iceberg.rest.requests.UpdateNamespacePropertiesRequest;
+import org.apache.iceberg.rest.requests.UpdateTableRequest;
+import org.apache.iceberg.rest.responses.ErrorResponse;
+import org.apache.iceberg.util.Pair;
+
+/**
+ * Adaptor class to translate REST requests into {@link Catalog} API calls.
+ */
+public class RESTCatalogAdapter implements RESTClient {

Review comment:
       would it make sense to have a separate test class for this adapter to 
make sure routing and other stuff is properly tested?




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