|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.apache.iceberg.rest; |
| 20 | + |
| 21 | +import java.util.List; |
| 22 | +import java.util.Map; |
| 23 | +import java.util.Set; |
| 24 | +import java.util.function.Supplier; |
| 25 | +import org.apache.iceberg.MetadataUpdate; |
| 26 | +import org.apache.iceberg.TableMetadata; |
| 27 | +import org.apache.iceberg.io.FileIO; |
| 28 | +import org.apache.iceberg.view.ViewMetadata; |
| 29 | + |
| 30 | +/** |
| 31 | + * A builder interface for creating {@link RESTTableOperations} and {@link RESTViewOperations} |
| 32 | + * instances for REST catalogs. |
| 33 | + * |
| 34 | + * <p>This interface allows custom implementations of table and view operations to be injected into |
| 35 | + * {@link RESTSessionCatalog} and {@link RESTCatalog}, enabling extensibility for specialized use |
| 36 | + * cases. |
| 37 | + * |
| 38 | + * <p>Example usage: |
| 39 | + * |
| 40 | + * <pre> |
| 41 | + * RESTOperationsBuilder customBuilder = new RESTOperationsBuilder() { |
| 42 | + * {@literal @}Override |
| 43 | + * public RESTTableOperations createTableOperations( |
| 44 | + * RESTClient client, |
| 45 | + * String path, |
| 46 | + * Supplier<Map<String, String>> headers, |
| 47 | + * FileIO io, |
| 48 | + * TableMetadata current, |
| 49 | + * Set<Endpoint> endpoints) { |
| 50 | + * return new CustomRESTTableOperations(client, path, headers, io, current, endpoints); |
| 51 | + * } |
| 52 | + * |
| 53 | + * {@literal @}Override |
| 54 | + * public RESTViewOperations createViewOperations( |
| 55 | + * RESTClient client, |
| 56 | + * String path, |
| 57 | + * Supplier<Map<String, String>> headers, |
| 58 | + * ViewMetadata current, |
| 59 | + * Set<Endpoint> endpoints) { |
| 60 | + * return new CustomRESTViewOperations(client, path, headers, current, endpoints); |
| 61 | + * } |
| 62 | + * }; |
| 63 | + * |
| 64 | + * RESTSessionCatalog catalog = new RESTSessionCatalog(clientBuilder, ioBuilder, customBuilder); |
| 65 | + * </pre> |
| 66 | + */ |
| 67 | +public interface RESTOperationsBuilder { |
| 68 | + |
| 69 | + /** |
| 70 | + * Create a new {@link RESTTableOperations} instance for simple table operations. |
| 71 | + * |
| 72 | + * <p>The default implementation creates a standard {@link RESTTableOperations} instance. |
| 73 | + * |
| 74 | + * @param client the REST client to use for communicating with the catalog server |
| 75 | + * @param path the REST path for the table |
| 76 | + * @param headers a supplier for additional HTTP headers to include in requests |
| 77 | + * @param io the FileIO implementation for reading and writing table metadata and data files |
| 78 | + * @param current the current table metadata |
| 79 | + * @param endpoints the set of supported REST endpoints |
| 80 | + * @return a new RESTTableOperations instance |
| 81 | + */ |
| 82 | + default RESTTableOperations createTableOperations( |
| 83 | + RESTClient client, |
| 84 | + String path, |
| 85 | + Supplier<Map<String, String>> headers, |
| 86 | + FileIO io, |
| 87 | + TableMetadata current, |
| 88 | + Set<Endpoint> endpoints) { |
| 89 | + return new RESTTableOperations(client, path, headers, io, current, endpoints); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * Create a new {@link RESTTableOperations} instance for transaction-based operations (create or |
| 94 | + * replace). |
| 95 | + * |
| 96 | + * <p>This method is used when creating tables or replacing table metadata within a transaction. |
| 97 | + * The default implementation creates a standard {@link RESTTableOperations} instance. |
| 98 | + * |
| 99 | + * @param client the REST client to use for communicating with the catalog server |
| 100 | + * @param path the REST path for the table |
| 101 | + * @param headers a supplier for additional HTTP headers to include in requests |
| 102 | + * @param io the FileIO implementation for reading and writing table metadata and data files |
| 103 | + * @param updateType the type of update being performed (CREATE, REPLACE, or SIMPLE) |
| 104 | + * @param createChanges the list of metadata updates to apply during table creation or replacement |
| 105 | + * @param current the current table metadata (may be null for CREATE operations) |
| 106 | + * @param endpoints the set of supported REST endpoints |
| 107 | + * @return a new RESTTableOperations instance |
| 108 | + */ |
| 109 | + default RESTTableOperations createTableOperationsForTransaction( |
| 110 | + RESTClient client, |
| 111 | + String path, |
| 112 | + Supplier<Map<String, String>> headers, |
| 113 | + FileIO io, |
| 114 | + RESTTableOperations.UpdateType updateType, |
| 115 | + List<MetadataUpdate> createChanges, |
| 116 | + TableMetadata current, |
| 117 | + Set<Endpoint> endpoints) { |
| 118 | + return new RESTTableOperations( |
| 119 | + client, path, headers, io, updateType, createChanges, current, endpoints); |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * Create a new {@link RESTViewOperations} instance. |
| 124 | + * |
| 125 | + * <p>The default implementation creates a standard {@link RESTViewOperations} instance. |
| 126 | + * |
| 127 | + * @param client the REST client to use for communicating with the catalog server |
| 128 | + * @param path the REST path for the view |
| 129 | + * @param headers a supplier for additional HTTP headers to include in requests |
| 130 | + * @param current the current view metadata |
| 131 | + * @param endpoints the set of supported REST endpoints |
| 132 | + * @return a new RESTViewOperations instance |
| 133 | + */ |
| 134 | + default RESTViewOperations createViewOperations( |
| 135 | + RESTClient client, |
| 136 | + String path, |
| 137 | + Supplier<Map<String, String>> headers, |
| 138 | + ViewMetadata current, |
| 139 | + Set<Endpoint> endpoints) { |
| 140 | + return new RESTViewOperations(client, path, headers, current, endpoints); |
| 141 | + } |
| 142 | + |
| 143 | + /** Default {@link RESTOperationsBuilder} instance. */ |
| 144 | + RESTOperationsBuilder DEFAULT = new RESTOperationsBuilder() {}; |
| 145 | +} |
0 commit comments