rdblue commented on code in PR #7412: URL: https://github.com/apache/iceberg/pull/7412#discussion_r1335236017
########## gcp/src/main/java/org/apache/iceberg/gcp/biglake/BigLakeClient.java: ########## @@ -0,0 +1,270 @@ +/* + * 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.gcp.biglake; + +import com.google.api.gax.rpc.PermissionDeniedException; +import com.google.cloud.bigquery.biglake.v1.Catalog; +import com.google.cloud.bigquery.biglake.v1.CatalogName; +import com.google.cloud.bigquery.biglake.v1.CreateCatalogRequest; +import com.google.cloud.bigquery.biglake.v1.CreateDatabaseRequest; +import com.google.cloud.bigquery.biglake.v1.CreateTableRequest; +import com.google.cloud.bigquery.biglake.v1.Database; +import com.google.cloud.bigquery.biglake.v1.DatabaseName; +import com.google.cloud.bigquery.biglake.v1.DeleteCatalogRequest; +import com.google.cloud.bigquery.biglake.v1.DeleteDatabaseRequest; +import com.google.cloud.bigquery.biglake.v1.DeleteTableRequest; +import com.google.cloud.bigquery.biglake.v1.GetCatalogRequest; +import com.google.cloud.bigquery.biglake.v1.GetDatabaseRequest; +import com.google.cloud.bigquery.biglake.v1.GetTableRequest; +import com.google.cloud.bigquery.biglake.v1.ListDatabasesRequest; +import com.google.cloud.bigquery.biglake.v1.ListTablesRequest; +import com.google.cloud.bigquery.biglake.v1.LocationName; +import com.google.cloud.bigquery.biglake.v1.MetastoreServiceClient; +import com.google.cloud.bigquery.biglake.v1.MetastoreServiceSettings; +import com.google.cloud.bigquery.biglake.v1.RenameTableRequest; +import com.google.cloud.bigquery.biglake.v1.Table; +import com.google.cloud.bigquery.biglake.v1.TableName; +import com.google.cloud.bigquery.biglake.v1.UpdateDatabaseRequest; +import com.google.cloud.bigquery.biglake.v1.UpdateTableRequest; +import com.google.protobuf.FieldMask; +import java.io.Closeable; +import java.io.IOException; +import java.util.Map; +import java.util.function.Supplier; +import org.apache.iceberg.exceptions.AlreadyExistsException; +import org.apache.iceberg.exceptions.NoSuchNamespaceException; +import org.apache.iceberg.exceptions.NoSuchTableException; +import org.apache.iceberg.exceptions.NotAuthorizedException; + +/** A client of Google BigLake service. */ +final class BigLakeClient implements Closeable { + + private final MetastoreServiceClient stub; + + /** + * Constructs a client of Google BigLake Service. + * + * @param settings BigLake service settings + */ + BigLakeClient(MetastoreServiceSettings settings) throws IOException { + this.stub = MetastoreServiceClient.create(settings); + } + + /** + * Constructs a client of Google BigLake Service. + * + * @param biglakeEndpoint BigLake service gRPC endpoint, e.g., "biglake.googleapis.com:443" + */ + BigLakeClient(String biglakeEndpoint) throws IOException { + this(MetastoreServiceSettings.newBuilder().setEndpoint(biglakeEndpoint).build()); + } + + public Catalog createCatalog(CatalogName name, Catalog catalog) { + return convertException( + () -> { + try { + return stub.createCatalog( + CreateCatalogRequest.newBuilder() + .setParent(LocationName.of(name.getProject(), name.getLocation()).toString()) + .setCatalogId(name.getCatalog()) + .setCatalog(catalog) + .build()); + } catch (com.google.api.gax.rpc.AlreadyExistsException e) { + throw new AlreadyExistsException(e, "Catalog already exists: %s", name.getCatalog()); + } + }, + name.getCatalog()); + } + + public Catalog catalog(CatalogName name) { + try { + return stub.getCatalog(GetCatalogRequest.newBuilder().setName(name.toString()).build()); + } catch (PermissionDeniedException e) { Review Comment: I think it would make sense if everything returned 404, but returning 401/403 and translating that to 404 doesn't make any sense to me. When we last talked, the argument for this behavior was that returning 401/403 leaks the fact that the object exists. But this is actually doing the opposite and hiding the fact that the object doesn't exist by throwing `NoSuchNamespaceException`. I guess that in the end, the service is returning a single response for all 401/403/404 cases, but it's strange to use a permission error rather than a not-exists error. Can you confirm that the service will never return a 404? Also, if the service guarantees that 401, 403, and 404 will result in `PermissionDeniedException`, then that should be documented in this class somewhere, probably in class-level Javadoc. Then maybe we don't need to add the confusing "(or permission denied)" to all of the messages? -- 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]
