{"record":{"id":"cadaa8403eb6829f","repo":"apache/seatunnel","slug":"create-hive-table-failed-cadaa8","errorCode":"CREATE_HIVE_TABLE_FAILED","errorMessage":"Failed to create database [${db}]","messagePattern":"Failed to create database \\[(.+?)\\]","errorType":"error_code","errorClass":"HiveConnectorException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveMetaStoreCatalog.java","lineNumber":467,"sourceCode":"    }\n\n    public void createDatabaseIfNotExists(String db) throws TException {\n        try {\n            try {\n                getClient().getDatabase(db);\n                log.debug(\"Database {} already exists\", db);\n                return;\n            } catch (org.apache.hadoop.hive.metastore.api.NoSuchObjectException ignored) {\n            }\n            Database database = new Database();\n            database.setName(db);\n            log.info(\"Creating database {}\", db);\n            getClient().createDatabase(database);\n        } catch (org.apache.hadoop.hive.metastore.api.AlreadyExistsException e) {\n            log.debug(\"Database {} already exists (race)\", db);\n        } catch (TException e) {\n            String errorMsg = String.format(\"Failed to create database [%s]\", db);\n            throw new HiveConnectorException(\n                    HiveConnectorErrorCode.CREATE_HIVE_TABLE_FAILED, errorMsg, e);\n        } catch (Exception e) {\n            throw new TException(\"Unexpected error creating database: \" + db, e);\n        }\n    }\n\n    public void createTableIfNotExists(@NonNull Table tbl) throws TException {\n        try {\n            if (getClient().tableExists(tbl.getDbName(), tbl.getTableName())) {\n                log.debug(\"Table {}.{} already exists\", tbl.getDbName(), tbl.getTableName());\n                return;\n            }\n            log.info(\"Creating table {}.{}\", tbl.getDbName(), tbl.getTableName());\n            getClient().createTable(tbl);\n        } catch (org.apache.hadoop.hive.metastore.api.AlreadyExistsException e) {\n            log.debug(\"Table {}.{} already exists (race)\", tbl.getDbName(), tbl.getTableName());\n        } catch (TException e) {\n            String errorMsg =","sourceCodeStart":449,"sourceCodeEnd":485,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveMetaStoreCatalog.java#L449-L485","documentation":"HiveConnectorException (code CREATE_HIVE_TABLE_FAILED) thrown by createDatabaseIfNotExists when the metastore createDatabase call fails with a generic TException. AlreadyExistsException from concurrent creation is tolerated (logged at debug), but any other metastore-side failure is wrapped with the database name.","triggerScenarios":"Calling createDatabase -> createDatabaseIfNotExists while the metastore rejects the create: invalid database name, metastore connection error, insufficient HDFS/warehouse permissions for the database location, or transactional conflict other than AlreadyExistsException.","commonSituations":"Warehouse directory not writable by the SeaTunnel user; invalid characters in db name; metastore briefly unavailable during job start; race with another job creating the same db where the exception type isn't AlreadyExistsException.","solutions":["Check the chained TException cause to distinguish permission, name-validation, or connectivity issues.","Verify the SeaTunnel process user can write to the Hive warehouse directory on HDFS for the target location.","Ensure the database name is a valid Hive identifier (alphanumeric + underscore).","Confirm the metastore is reachable and retry; if creation races, rely on the AlreadyExistsException tolerance rather than retry loops."],"exampleFix":"// before: assuming failure means the db is missing\ncatalog.createDatabaseIfNotExists(\"etl_db\");\n\n// after: check existence first and skip the create when possible\nif (!catalog.databaseExists(\"etl_db\")) {\n    catalog.createDatabaseIfNotExists(\"etl_db\");\n}","handlingStrategy":"try-catch","validationCode":"if (catalog.databaseExists(db)) return; // skip create","typeGuard":null,"tryCatchPattern":"try {\n    catalog.createDatabaseIfNotExists(db);\n} catch (HiveConnectorException e) {\n    if (!catalog.databaseExists(db)) throw e; // real failure, not a benign race\n}","preventionTips":["Check HDFS warehouse write permissions for the SeaTunnel user","Use valid Hive identifiers for database names","Check existence before creating to avoid races"],"tags":["hive","metastore","database","thrift"],"backgroundTag":"database-write-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}