apache/seatunnel · error · TException
Unexpected error creating database: ${db}
Error message
Unexpected error creating database: ${db} What it means
A raw org.apache.hadoop.hive.metastore.api.TException thrown by createDatabaseIfNotExists when an unexpected non-Thrift Exception escapes the create path. Unlike the TException branch, this is a defensive catch-all indicating a bug or an unexpected runtime failure (e.g. NPE in client setup) while creating the database.
Source
Thrown at seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveMetaStoreCatalog.java:470
try {
try {
getClient().getDatabase(db);
log.debug("Database {} already exists", db);
return;
} catch (org.apache.hadoop.hive.metastore.api.NoSuchObjectException ignored) {
}
Database database = new Database();
database.setName(db);
log.info("Creating database {}", db);
getClient().createDatabase(database);
} catch (org.apache.hadoop.hive.metastore.api.AlreadyExistsException e) {
log.debug("Database {} already exists (race)", db);
} catch (TException e) {
String errorMsg = String.format("Failed to create database [%s]", db);
throw new HiveConnectorException(
HiveConnectorErrorCode.CREATE_HIVE_TABLE_FAILED, errorMsg, e);
} catch (Exception e) {
throw new TException("Unexpected error creating database: " + db, e);
}
}
public void createTableIfNotExists(@NonNull Table tbl) throws TException {
try {
if (getClient().tableExists(tbl.getDbName(), tbl.getTableName())) {
log.debug("Table {}.{} already exists", tbl.getDbName(), tbl.getTableName());
return;
}
log.info("Creating table {}.{}", tbl.getDbName(), tbl.getTableName());
getClient().createTable(tbl);
} catch (org.apache.hadoop.hive.metastore.api.AlreadyExistsException e) {
log.debug("Table {}.{} already exists (race)", tbl.getDbName(), tbl.getTableName());
} catch (TException e) {
String errorMsg =
String.format(
"Failed to create table [%s.%s]", tbl.getDbName(), tbl.getTableName());
throw new HiveConnectorException(View on GitHub (pinned to cf67b549a7)
Solutions
- Read the chained cause of the TException to identify the actual runtime failure.
- Ensure the catalog is opened (open()) before calling createDatabase.
- If using a custom client factory, verify it returns a fully functional IMetaStoreClient instance.
- Report/log the full stack trace; this catch-all usually signals a bug rather than an expected condition.
Defensive patterns
Strategy: try-catch
Try / catch
try {
catalog.createDatabaseIfNotExists(db);
} catch (TException e) {
log.error("Unexpected database create failure for {}: ", db, e.getCause());
throw e;
} Prevention
- Always call catalog.open() before catalog operations
- Keep the catalog on a single thread or synchronize client access
- Log full stack traces to catch client-initialization bugs early
When it happens
Trigger: Any RuntimeException/Error (except the handled TException/AlreadyExistsException paths) thrown during createDatabaseIfNotExists — e.g. NullPointerException from a mis-initialized metastore client, ClassCastException in config handling.
Common situations: Catalog not properly opened/initialized before use; bug in a custom client factory returning an incompatible client; environment issue (missing Hadoop config) causing unexpected runtime exception.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- CREATE_HIVE_TABLE_FAILED
- Unexpected error creating table: ${dbName}.${tableName}
- Failed to check if database exists: ${dbName}
- GET_HIVE_TABLE_INFORMATION_FAILED
- Hive metastore_uri is required for regex table discovery (us
AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10).
Data as JSON: /api/errors/9129cb9977b99847.
Report an issue: GitHub.