Skip to content

Commit

Permalink
Check for the database instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Fokko committed Jun 15, 2023
1 parent 93a0178 commit 4269e50
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
import org.apache.iceberg.catalog.SupportsNamespaces;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.exceptions.AlreadyExistsException;
import org.apache.iceberg.exceptions.ForbiddenException;
import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
import org.apache.iceberg.exceptions.NoSuchNamespaceException;
import org.apache.iceberg.flink.util.FlinkCompatibilityUtil;
Expand Down Expand Up @@ -127,13 +126,13 @@ public FlinkCatalog(
@Override
public void open() throws CatalogException {
// Create the default database if it does not exist.
try {
createDatabase(getDefaultDatabase(), ImmutableMap.of(), true);
} catch (DatabaseAlreadyExistException e) {
// Ignore the exception if it's already exist.
} catch (ForbiddenException e) {
// Ignore if the user doesn't have CREATE DATABASE permissions,
// and we assume that the database already exists
String defaultDatabase = getDefaultDatabase();
if (!databaseExists(defaultDatabase)) {
try {
createDatabase(getDefaultDatabase(), ImmutableMap.of(), true);
} catch (DatabaseAlreadyExistException e) {
// Ignore the exception if it's already exist.
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
import org.apache.iceberg.catalog.SupportsNamespaces;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.exceptions.AlreadyExistsException;
import org.apache.iceberg.exceptions.ForbiddenException;
import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
import org.apache.iceberg.exceptions.NoSuchNamespaceException;
import org.apache.iceberg.flink.util.FlinkCompatibilityUtil;
Expand Down Expand Up @@ -127,13 +126,13 @@ public FlinkCatalog(
@Override
public void open() throws CatalogException {
// Create the default database if it does not exist.
try {
createDatabase(getDefaultDatabase(), ImmutableMap.of(), true);
} catch (DatabaseAlreadyExistException e) {
// Ignore the exception if it's already exist.
} catch (ForbiddenException e) {
// Ignore if the user doesn't have CREATE DATABASE permissions,
// and we assume that the database already exists
String defaultDatabase = getDefaultDatabase();
if (!databaseExists(defaultDatabase)) {
try {
createDatabase(getDefaultDatabase(), ImmutableMap.of(), true);
} catch (DatabaseAlreadyExistException e) {
// Ignore the exception if it's already exist.
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
import org.apache.iceberg.catalog.SupportsNamespaces;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.exceptions.AlreadyExistsException;
import org.apache.iceberg.exceptions.ForbiddenException;
import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
import org.apache.iceberg.exceptions.NoSuchNamespaceException;
import org.apache.iceberg.flink.util.FlinkCompatibilityUtil;
Expand Down Expand Up @@ -127,13 +126,13 @@ public FlinkCatalog(
@Override
public void open() throws CatalogException {
// Create the default database if it does not exist.
try {
createDatabase(getDefaultDatabase(), ImmutableMap.of(), true);
} catch (DatabaseAlreadyExistException e) {
// Ignore the exception if it's already exist.
} catch (ForbiddenException e) {
// Ignore if the user doesn't have CREATE DATABASE permissions,
// and we assume that the database already exists
String defaultDatabase = getDefaultDatabase();
if (!databaseExists(defaultDatabase)) {
try {
createDatabase(getDefaultDatabase(), ImmutableMap.of(), true);
} catch (DatabaseAlreadyExistException e) {
// Ignore the exception if it's already exist.
}
}
}

Expand Down

0 comments on commit 4269e50

Please sign in to comment.