From 12931a2de4842fda4195696237458a13d8072a70 Mon Sep 17 00:00:00 2001 From: Jingsong Date: Sun, 28 Jul 2024 10:50:16 +0800 Subject: [PATCH] [core] Introduce DelegateCatalog --- .../paimon/catalog/DelegateCatalog.java | 165 ++++++++++++++++++ .../paimon/privilege/PrivilegedCatalog.java | 77 +------- 2 files changed, 168 insertions(+), 74 deletions(-) create mode 100644 paimon-core/src/main/java/org/apache/paimon/catalog/DelegateCatalog.java diff --git a/paimon-core/src/main/java/org/apache/paimon/catalog/DelegateCatalog.java b/paimon-core/src/main/java/org/apache/paimon/catalog/DelegateCatalog.java new file mode 100644 index 000000000000..d11f4f5e1287 --- /dev/null +++ b/paimon-core/src/main/java/org/apache/paimon/catalog/DelegateCatalog.java @@ -0,0 +1,165 @@ +/* + * 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.paimon.catalog; + +import org.apache.paimon.fs.FileIO; +import org.apache.paimon.metastore.MetastoreClient; +import org.apache.paimon.schema.Schema; +import org.apache.paimon.schema.SchemaChange; +import org.apache.paimon.table.Table; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** A {@link Catalog} to delegate all operations to another {@link Catalog}. */ +public class DelegateCatalog implements Catalog { + + protected final Catalog wrapped; + + public DelegateCatalog(Catalog wrapped) { + this.wrapped = wrapped; + } + + @Override + public boolean caseSensitive() { + return wrapped.caseSensitive(); + } + + @Override + public String warehouse() { + return wrapped.warehouse(); + } + + @Override + public Map options() { + return wrapped.options(); + } + + @Override + public FileIO fileIO() { + return wrapped.fileIO(); + } + + @Override + public Optional lockFactory() { + return wrapped.lockFactory(); + } + + @Override + public Optional lockContext() { + return wrapped.lockContext(); + } + + @Override + public Optional metastoreClientFactory(Identifier identifier) { + return wrapped.metastoreClientFactory(identifier); + } + + @Override + public List listDatabases() { + return wrapped.listDatabases(); + } + + @Override + public boolean databaseExists(String databaseName) { + return wrapped.databaseExists(databaseName); + } + + @Override + public void createDatabase(String name, boolean ignoreIfExists) + throws DatabaseAlreadyExistException { + wrapped.createDatabase(name, ignoreIfExists); + } + + @Override + public void createDatabase(String name, boolean ignoreIfExists, Map properties) + throws DatabaseAlreadyExistException { + wrapped.createDatabase(name, ignoreIfExists, properties); + } + + @Override + public Map loadDatabaseProperties(String name) + throws DatabaseNotExistException { + return wrapped.loadDatabaseProperties(name); + } + + @Override + public void dropDatabase(String name, boolean ignoreIfNotExists, boolean cascade) + throws DatabaseNotExistException, DatabaseNotEmptyException { + wrapped.dropDatabase(name, ignoreIfNotExists, cascade); + } + + @Override + public List listTables(String databaseName) throws DatabaseNotExistException { + return wrapped.listTables(databaseName); + } + + @Override + public boolean tableExists(Identifier identifier) { + return wrapped.tableExists(identifier); + } + + @Override + public void dropTable(Identifier identifier, boolean ignoreIfNotExists) + throws TableNotExistException { + wrapped.dropTable(identifier, ignoreIfNotExists); + } + + @Override + public void createTable(Identifier identifier, Schema schema, boolean ignoreIfExists) + throws TableAlreadyExistException, DatabaseNotExistException { + wrapped.createTable(identifier, schema, ignoreIfExists); + } + + @Override + public void renameTable(Identifier fromTable, Identifier toTable, boolean ignoreIfNotExists) + throws TableNotExistException, TableAlreadyExistException { + wrapped.renameTable(fromTable, toTable, ignoreIfNotExists); + } + + @Override + public void alterTable(Identifier identifier, SchemaChange change, boolean ignoreIfNotExists) + throws TableNotExistException, ColumnAlreadyExistException, ColumnNotExistException { + wrapped.alterTable(identifier, change, ignoreIfNotExists); + } + + @Override + public void alterTable( + Identifier identifier, List changes, boolean ignoreIfNotExists) + throws TableNotExistException, ColumnAlreadyExistException, ColumnNotExistException { + wrapped.alterTable(identifier, changes, ignoreIfNotExists); + } + + @Override + public Table getTable(Identifier identifier) throws TableNotExistException { + return wrapped.getTable(identifier); + } + + @Override + public void dropPartition(Identifier identifier, Map partitions) + throws TableNotExistException, PartitionNotExistException { + wrapped.dropPartition(identifier, partitions); + } + + @Override + public void close() throws Exception { + wrapped.close(); + } +} diff --git a/paimon-core/src/main/java/org/apache/paimon/privilege/PrivilegedCatalog.java b/paimon-core/src/main/java/org/apache/paimon/privilege/PrivilegedCatalog.java index 851cc302afd3..cc44706a5dfe 100644 --- a/paimon-core/src/main/java/org/apache/paimon/privilege/PrivilegedCatalog.java +++ b/paimon-core/src/main/java/org/apache/paimon/privilege/PrivilegedCatalog.java @@ -19,11 +19,8 @@ package org.apache.paimon.privilege; import org.apache.paimon.catalog.Catalog; -import org.apache.paimon.catalog.CatalogLockContext; -import org.apache.paimon.catalog.CatalogLockFactory; +import org.apache.paimon.catalog.DelegateCatalog; import org.apache.paimon.catalog.Identifier; -import org.apache.paimon.fs.FileIO; -import org.apache.paimon.metastore.MetastoreClient; import org.apache.paimon.options.ConfigOption; import org.apache.paimon.options.ConfigOptions; import org.apache.paimon.schema.Schema; @@ -34,10 +31,9 @@ import java.util.List; import java.util.Map; -import java.util.Optional; /** {@link Catalog} which supports privilege system. */ -public class PrivilegedCatalog implements Catalog { +public class PrivilegedCatalog extends DelegateCatalog { public static final ConfigOption USER = ConfigOptions.key("user").stringType().defaultValue(PrivilegeManager.USER_ANONYMOUS); @@ -46,11 +42,10 @@ public class PrivilegedCatalog implements Catalog { .stringType() .defaultValue(PrivilegeManager.PASSWORD_ANONYMOUS); - private final Catalog wrapped; private final PrivilegeManager privilegeManager; public PrivilegedCatalog(Catalog wrapped, PrivilegeManager privilegeManager) { - this.wrapped = wrapped; + super(wrapped); this.privilegeManager = privilegeManager; } @@ -62,51 +57,6 @@ public PrivilegeManager privilegeManager() { return privilegeManager; } - @Override - public boolean caseSensitive() { - return wrapped.caseSensitive(); - } - - @Override - public String warehouse() { - return wrapped.warehouse(); - } - - @Override - public Map options() { - return wrapped.options(); - } - - @Override - public FileIO fileIO() { - return wrapped.fileIO(); - } - - @Override - public Optional lockFactory() { - return wrapped.lockFactory(); - } - - @Override - public Optional lockContext() { - return wrapped.lockContext(); - } - - @Override - public Optional metastoreClientFactory(Identifier identifier) { - return wrapped.metastoreClientFactory(identifier); - } - - @Override - public List listDatabases() { - return wrapped.listDatabases(); - } - - @Override - public boolean databaseExists(String databaseName) { - return wrapped.databaseExists(databaseName); - } - @Override public void createDatabase(String name, boolean ignoreIfExists) throws DatabaseAlreadyExistException { @@ -121,12 +71,6 @@ public void createDatabase(String name, boolean ignoreIfExists, Map loadDatabaseProperties(String name) - throws DatabaseNotExistException { - return wrapped.loadDatabaseProperties(name); - } - @Override public void dropDatabase(String name, boolean ignoreIfNotExists, boolean cascade) throws DatabaseNotExistException, DatabaseNotEmptyException { @@ -135,16 +79,6 @@ public void dropDatabase(String name, boolean ignoreIfNotExists, boolean cascade privilegeManager.objectDropped(name); } - @Override - public List listTables(String databaseName) throws DatabaseNotExistException { - return wrapped.listTables(databaseName); - } - - @Override - public boolean tableExists(Identifier identifier) { - return wrapped.tableExists(identifier); - } - @Override public void dropTable(Identifier identifier, boolean ignoreIfNotExists) throws TableNotExistException { @@ -207,11 +141,6 @@ public void dropPartition(Identifier identifier, Map partitions) wrapped.dropPartition(identifier, partitions); } - @Override - public void close() throws Exception { - wrapped.close(); - } - public void createPrivilegedUser(String user, String password) { privilegeManager.createUser(user, password); }