Skip to content

Commit

Permalink
[core] Introduce DelegateCatalog
Browse files Browse the repository at this point in the history
  • Loading branch information
JingsongLi committed Jul 28, 2024
1 parent c9e62d7 commit 12931a2
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -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<String, String> options() {
return wrapped.options();
}

@Override
public FileIO fileIO() {
return wrapped.fileIO();
}

@Override
public Optional<CatalogLockFactory> lockFactory() {
return wrapped.lockFactory();
}

@Override
public Optional<CatalogLockContext> lockContext() {
return wrapped.lockContext();
}

@Override
public Optional<MetastoreClient.Factory> metastoreClientFactory(Identifier identifier) {
return wrapped.metastoreClientFactory(identifier);
}

@Override
public List<String> 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<String, String> properties)
throws DatabaseAlreadyExistException {
wrapped.createDatabase(name, ignoreIfExists, properties);
}

@Override
public Map<String, String> 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<String> 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<SchemaChange> 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<String, String> partitions)
throws TableNotExistException, PartitionNotExistException {
wrapped.dropPartition(identifier, partitions);
}

@Override
public void close() throws Exception {
wrapped.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> USER =
ConfigOptions.key("user").stringType().defaultValue(PrivilegeManager.USER_ANONYMOUS);
Expand All @@ -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;
}

Expand All @@ -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<String, String> options() {
return wrapped.options();
}

@Override
public FileIO fileIO() {
return wrapped.fileIO();
}

@Override
public Optional<CatalogLockFactory> lockFactory() {
return wrapped.lockFactory();
}

@Override
public Optional<CatalogLockContext> lockContext() {
return wrapped.lockContext();
}

@Override
public Optional<MetastoreClient.Factory> metastoreClientFactory(Identifier identifier) {
return wrapped.metastoreClientFactory(identifier);
}

@Override
public List<String> listDatabases() {
return wrapped.listDatabases();
}

@Override
public boolean databaseExists(String databaseName) {
return wrapped.databaseExists(databaseName);
}

@Override
public void createDatabase(String name, boolean ignoreIfExists)
throws DatabaseAlreadyExistException {
Expand All @@ -121,12 +71,6 @@ public void createDatabase(String name, boolean ignoreIfExists, Map<String, Stri
wrapped.createDatabase(name, ignoreIfExists, properties);
}

@Override
public Map<String, String> loadDatabaseProperties(String name)
throws DatabaseNotExistException {
return wrapped.loadDatabaseProperties(name);
}

@Override
public void dropDatabase(String name, boolean ignoreIfNotExists, boolean cascade)
throws DatabaseNotExistException, DatabaseNotEmptyException {
Expand All @@ -135,16 +79,6 @@ public void dropDatabase(String name, boolean ignoreIfNotExists, boolean cascade
privilegeManager.objectDropped(name);
}

@Override
public List<String> 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 {
Expand Down Expand Up @@ -207,11 +141,6 @@ public void dropPartition(Identifier identifier, Map<String, String> partitions)
wrapped.dropPartition(identifier, partitions);
}

@Override
public void close() throws Exception {
wrapped.close();
}

public void createPrivilegedUser(String user, String password) {
privilegeManager.createUser(user, password);
}
Expand Down

0 comments on commit 12931a2

Please sign in to comment.