Skip to content

Commit

Permalink
Hive: Common namespace validation for HiveCatalog
Browse files Browse the repository at this point in the history
  • Loading branch information
nk1506 committed Mar 17, 2024
1 parent 560b723 commit c3f576e
Showing 1 changed file with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public void initialize(String inputName, Map<String, String> properties) {

@Override
public List<TableIdentifier> listTables(Namespace namespace) {
Preconditions.checkArgument(
isValidateNamespace(namespace), "Missing database in namespace: %s", namespace);
checkNamespaceIsValid(namespace);

String database = namespace.level(0);

try {
Expand Down Expand Up @@ -275,12 +275,7 @@ public void renameTable(TableIdentifier from, TableIdentifier originalTo) {

@Override
public void createNamespace(Namespace namespace, Map<String, String> meta) {
Preconditions.checkArgument(
!namespace.isEmpty(), "Cannot create namespace with invalid name: %s", namespace);
Preconditions.checkArgument(
isValidateNamespace(namespace),
"Cannot support multi part namespace in Hive Metastore: %s",
namespace);
checkNamespaceIsValid(namespace);
Preconditions.checkArgument(
meta.get(HMS_DB_OWNER_TYPE) == null || meta.get(HMS_DB_OWNER) != null,
"Create namespace setting %s without setting %s is not allowed",
Expand Down Expand Up @@ -312,7 +307,7 @@ public void createNamespace(Namespace namespace, Map<String, String> meta) {

@Override
public List<Namespace> listNamespaces(Namespace namespace) {
if (!isValidateNamespace(namespace) && !namespace.isEmpty()) {
if (!isValidNamespace(namespace) && !namespace.isEmpty()) {
throw new NoSuchNamespaceException("Namespace does not exist: %s", namespace);
}
if (!namespace.isEmpty()) {
Expand Down Expand Up @@ -340,7 +335,7 @@ public List<Namespace> listNamespaces(Namespace namespace) {

@Override
public boolean dropNamespace(Namespace namespace) {
if (!isValidateNamespace(namespace)) {
if (!isValidNamespace(namespace)) {
return false;
}

Expand Down Expand Up @@ -439,7 +434,7 @@ private void alterHiveDataBase(Namespace namespace, Database database) {

@Override
public Map<String, String> loadNamespaceMetadata(Namespace namespace) {
if (!isValidateNamespace(namespace)) {
if (!isValidNamespace(namespace)) {
throw new NoSuchNamespaceException("Namespace does not exist: %s", namespace);
}

Expand Down Expand Up @@ -482,10 +477,17 @@ private TableIdentifier removeCatalogName(TableIdentifier to) {
return to;
}

private boolean isValidateNamespace(Namespace namespace) {
private boolean isValidNamespace(Namespace namespace) {
return namespace.levels().length == 1;
}

private void checkNamespaceIsValid(Namespace namespace) {
Preconditions.checkArgument(
isValidNamespace(namespace),
"Cannot support empty or multi part namespace in Hive Metastore: %s",
namespace);
}

@Override
public TableOperations newTableOps(TableIdentifier tableIdentifier) {
String dbName = tableIdentifier.namespace().level(0);
Expand Down Expand Up @@ -554,10 +556,6 @@ private Map<String, String> convertToMetadata(Database database) {
}

Database convertToDatabase(Namespace namespace, Map<String, String> meta) {
if (!isValidateNamespace(namespace)) {
throw new NoSuchNamespaceException("Namespace does not exist: %s", namespace);
}

Database database = new Database();
Map<String, String> parameter = Maps.newHashMap();

Expand Down

0 comments on commit c3f576e

Please sign in to comment.