|
24 | 24 | import org.apache.paimon.catalog.CatalogLockFactory;
|
25 | 25 | import org.apache.paimon.catalog.Database;
|
26 | 26 | import org.apache.paimon.catalog.Identifier;
|
| 27 | +import org.apache.paimon.catalog.PropertyChange; |
27 | 28 | import org.apache.paimon.fs.FileIO;
|
28 | 29 | import org.apache.paimon.fs.Path;
|
29 | 30 | import org.apache.paimon.operation.Lock;
|
|
33 | 34 | import org.apache.paimon.schema.SchemaChange;
|
34 | 35 | import org.apache.paimon.schema.SchemaManager;
|
35 | 36 | import org.apache.paimon.schema.TableSchema;
|
| 37 | +import org.apache.paimon.utils.Pair; |
36 | 38 | import org.apache.paimon.utils.Preconditions;
|
37 | 39 |
|
38 | 40 | import org.apache.paimon.shade.guava30.com.google.common.collect.ImmutableMap;
|
39 | 41 | import org.apache.paimon.shade.guava30.com.google.common.collect.Lists;
|
40 | 42 | import org.apache.paimon.shade.guava30.com.google.common.collect.Maps;
|
| 43 | +import org.apache.paimon.shade.guava30.com.google.common.collect.Sets; |
41 | 44 |
|
42 | 45 | import org.slf4j.Logger;
|
43 | 46 | import org.slf4j.LoggerFactory;
|
|
52 | 55 | import java.util.List;
|
53 | 56 | import java.util.Map;
|
54 | 57 | import java.util.Optional;
|
| 58 | +import java.util.Set; |
55 | 59 | import java.util.stream.Collectors;
|
56 | 60 |
|
57 | 61 | import static org.apache.paimon.jdbc.JdbcCatalogLock.acquireTimeout;
|
58 | 62 | import static org.apache.paimon.jdbc.JdbcCatalogLock.checkMaxSleep;
|
| 63 | +import static org.apache.paimon.jdbc.JdbcUtils.deleteProperties; |
59 | 64 | import static org.apache.paimon.jdbc.JdbcUtils.execute;
|
60 | 65 | import static org.apache.paimon.jdbc.JdbcUtils.insertProperties;
|
| 66 | +import static org.apache.paimon.jdbc.JdbcUtils.updateProperties; |
61 | 67 | import static org.apache.paimon.jdbc.JdbcUtils.updateTable;
|
62 | 68 |
|
63 | 69 | /* This file is based on source code from the Iceberg Project (http://iceberg.apache.org/), licensed by the Apache
|
@@ -197,6 +203,45 @@ protected void dropDatabaseImpl(String name) {
|
197 | 203 | execute(connections, JdbcUtils.DELETE_ALL_DATABASE_PROPERTIES_SQL, catalogKey, name);
|
198 | 204 | }
|
199 | 205 |
|
| 206 | + @Override |
| 207 | + protected void alterDatabaseImpl(String name, List<PropertyChange> changes) { |
| 208 | + Pair<Map<String, String>, Set<String>> setPropertiesToRemoveKeys = |
| 209 | + PropertyChange.getSetPropertiesToRemoveKeys(changes); |
| 210 | + Map<String, String> setProperties = setPropertiesToRemoveKeys.getLeft(); |
| 211 | + Set<String> removeKeys = setPropertiesToRemoveKeys.getRight(); |
| 212 | + Map<String, String> startingProperties = fetchProperties(name); |
| 213 | + Map<String, String> inserts = Maps.newHashMap(); |
| 214 | + Map<String, String> updates = Maps.newHashMap(); |
| 215 | + Set<String> removes = Sets.newHashSet(); |
| 216 | + if (!setProperties.isEmpty()) { |
| 217 | + setProperties.forEach( |
| 218 | + (k, v) -> { |
| 219 | + if (!startingProperties.containsKey(k)) { |
| 220 | + inserts.put(k, v); |
| 221 | + } else { |
| 222 | + updates.put(k, v); |
| 223 | + } |
| 224 | + }); |
| 225 | + } |
| 226 | + if (!removeKeys.isEmpty()) { |
| 227 | + removeKeys.forEach( |
| 228 | + k -> { |
| 229 | + if (startingProperties.containsKey(k)) { |
| 230 | + removes.add(k); |
| 231 | + } |
| 232 | + }); |
| 233 | + } |
| 234 | + if (!inserts.isEmpty()) { |
| 235 | + insertProperties(connections, catalogKey, name, inserts); |
| 236 | + } |
| 237 | + if (!updates.isEmpty()) { |
| 238 | + updateProperties(connections, catalogKey, name, updates); |
| 239 | + } |
| 240 | + if (!removes.isEmpty()) { |
| 241 | + deleteProperties(connections, catalogKey, name, removes); |
| 242 | + } |
| 243 | + } |
| 244 | + |
200 | 245 | @Override
|
201 | 246 | protected List<String> listTablesImpl(String databaseName) {
|
202 | 247 | return fetch(
|
|
0 commit comments