prestodb/presto · error · TableNotFoundException
errorDetail.errorMessage()
Error message
errorDetail.errorMessage()
What it means
GlueHiveMetastore translates AWS Glue catalog exceptions into Presto exceptions. When Glue reports AlreadyExistsException the metastore throws PrestoException(ALREADY_EXISTS); when it reports EntityNotFoundException it throws TableNotFoundException. The message is the raw errorMessage() string returned by AWS Glue.
Source
Thrown at presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/glue/GlueHiveMetastore.java:1276
}
private static void propagateBatchUpdatePartitionErrorToPrestoException(String databaseName, String tableName, List<BatchUpdatePartitionFailureEntry> failureEntries)
{
if (failureEntries != null && !failureEntries.isEmpty()) {
ErrorDetail errorDetail = failureEntries.get(0).errorDetail();
propagateErrorDetailToPrestoException(databaseName, tableName, errorDetail);
}
}
private static void propagateErrorDetailToPrestoException(String databaseName, String tableName, ErrorDetail errorDetail)
{
String glueExceptionCode = errorDetail.errorCode();
switch (glueExceptionCode) {
case "AlreadyExistsException":
throw new PrestoException(ALREADY_EXISTS, errorDetail.errorMessage());
case "EntityNotFoundException":
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), errorDetail.errorMessage());
default:
throw new PrestoException(HIVE_METASTORE_ERROR, errorDetail.errorCode() + ": " + errorDetail.errorMessage());
}
}
@Override
public void dropPartition(MetastoreContext metastoreContext, String databaseName, String tableName, List<String> parts, boolean deleteData)
{
Table table = getTableOrElseThrow(metastoreContext, databaseName, tableName);
Partition partition = getPartition(metastoreContext, databaseName, tableName, parts)
.orElseThrow(() -> new PartitionNotFoundException(new SchemaTableName(databaseName, tableName), parts));
try {
awsSyncRequest(
glueClient::deletePartition,
DeletePartitionRequest.builder()
.catalogId(catalogId)
.databaseName(databaseName)View on GitHub (pinned to 55bb57d202)
Solutions
- Check existence first: call getDatabase/getTable and handle AlreadyExists semantics in the caller before issuing the create
- If using CREATE TABLE/IF NOT EXISTS, catch PrestoException with code ALREADY_EXISTS and treat it as success if the existing definition is compatible
- For EntityNotFoundException, verify the database and table names (case sensitivity, quotes) against the Glue catalog before retrying
- Inspect errorMessage() contents; Glue may report a missing table vs database and the message includes the entity name
Example fix
// before
metastore.createDatabase(new Database(name, ...));
// after
if (metastore.getDatabase(name).isEmpty()) {
metastore.createDatabase(new Database(name, ...));
} Defensive patterns
Strategy: try-catch
Validate before calling
Optional<Database> db = metastore.getDatabase(name, metastoreContext);
if (db.isPresent()) { /* skip create or reconcile */ } Try / catch
try {
metastore.createDatabase(db);
} catch (PrestoException e) {
if (e.getErrorCode().equals(StandardErrorCode.ALREADY_EXISTS.toErrorCode())) {
// treat as success or verify existing entity
} else {
throw e;
}
} Prevention
- Check existence before create operations
- Handle idempotent creation explicitly instead of relying on errors
- Watch for EntityNotFoundException from Glue meaning database missing, not only table
When it happens
Trigger: Calling any GlueHiveMetastore method (createDatabase, createTable, etc.) via invokeGlueClient when the Glue API returns an error detail with errorCode AlreadyExistsException or EntityNotFoundException. Note EntityNotFoundException maps to TableNotFoundException regardless of whether the missing entity is actually a table.
Common situations: Creating a database or table that already exists in the Glue catalog; concurrent CREATE TABLE race; CREATE TABLE ... IF NOT EXISTS handled without checking first; a database rename or stale cache leaving the catalog inconsistent.
Related errors
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/79a91154816c8e9d.
Report an issue: GitHub.