XJDKC commented on code in PR #14465: URL: https://github.com/apache/iceberg/pull/14465#discussion_r2535001342
########## core/src/main/java/org/apache/iceberg/rest/RESTOperationsFactory.java: ########## @@ -0,0 +1,145 @@ +/* + * 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.Map; +import java.util.Set; +import java.util.function.Supplier; +import org.apache.iceberg.MetadataUpdate; +import org.apache.iceberg.TableMetadata; +import org.apache.iceberg.io.FileIO; +import org.apache.iceberg.view.ViewMetadata; + +/** + * A factory interface for creating {@link RESTTableOperations} and {@link RESTViewOperations} + * instances for REST catalogs. + * + * <p>This interface allows custom implementations of table and view operations to be injected into + * {@link RESTSessionCatalog} and {@link RESTCatalog}, enabling extensibility for specialized use + * cases. + * + * <p>Example usage: + * + * <pre> + * RESTOperationsFactory customFactory = new RESTOperationsFactory() { + * {@literal @}Override + * public RESTTableOperations createTableOperations( + * RESTClient client, + * String path, + * Supplier<Map<String, String>> headers, + * FileIO io, + * TableMetadata current, + * Set<Endpoint> endpoints) { + * return new CustomRESTTableOperations(client, path, headers, io, current, endpoints); + * } + * + * {@literal @}Override + * public RESTViewOperations createViewOperations( + * RESTClient client, + * String path, + * Supplier<Map<String, String>> headers, + * ViewMetadata current, + * Set<Endpoint> endpoints) { + * return new CustomRESTViewOperations(client, path, headers, current, endpoints); + * } + * }; + * + * RESTSessionCatalog catalog = new RESTSessionCatalog(clientBuilder, ioBuilder, customFactory); + * </pre> + */ +public interface RESTOperationsFactory { Review Comment: Hey @amogh-jahagirdar, thanks for reviewing the PR, what you mentioned makes sense to me. The reason I went with a builder/factory approach is mainly to stay consistent with the existing pattern, since we already have builders for components like `RESTClient` and `FileIO`. That said, I'm fine with either direction. If we go with your suggested approach, we need a builder / factory for `RESTSessionCatalog` or maybe a method called `newSessionCatalog`, and users need to extend the `RESTSessionCatalog` to provide the custom `TableOperations` and also extend the `RESTCatalog` to provide the custom `RESTSessionCatalog`. ```java class RESTSessionCatalog { // xxx RESTTableOperations newTableOps(xxx) { // replace this with custom Table Operations RESTTableOperations ops = new RESTTableOperations( tableClient, paths.table(finalIdentifier), Map::of, tableFileIO(context, tableConf, response.credentials()), tableMetadata, endpoints); } // xxx } class RESTCatalog { // xxx public RESTCatalog( SessionCatalog.SessionContext context, Function<Map<String, String>, RESTClient> clientBuilder) { this.sessionCatalog = newSessionCatalog(clientBuilder, null); this.delegate = sessionCatalog.asCatalog(context); this.nsDelegate = (SupportsNamespaces) delegate; this.context = context; this.viewSessionCatalog = sessionCatalog.asViewCatalog(context); } RESTSessionCatalog newSessionCatalog(xxx) { // replace this with the custom RESTSessionCatalog that provides the custom Table Operations return new RESTSessionCatalog(clientBuilder, null); } // xxx } ``` Actually, I think that’s a cleaner solution and provides more flexibility overall. WDYT? cc: @stevenzwu @flyrain -- 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]
