prestodb/presto · error · TableNotFoundException
Table not found
Error message
Table not found
What it means
dropConstraint in ThriftHiveMetastore first fetches the target table via getTable; if the metastore returns no such table it throws TableNotFoundException, reported to users as 'Table not found'. This is a pre-check so the caller gets a clear table-missing error instead of a raw metastore exception.
Source
Thrown at presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/thrift/ThriftHiveMetastore.java:1651
privileges.addAll(parsePrivilege(hiveObjectPrivilege.getGrantInfo(), Optional.of(grantee)));
}
return privileges.build();
})));
}
catch (TException e) {
throw new PrestoException(HIVE_METASTORE_ERROR, e);
}
catch (Exception e) {
throw propagate(e);
}
}
@Override
public MetastoreOperationResult dropConstraint(MetastoreContext metastoreContext, String databaseName, String tableName, String constraintName)
{
Optional<org.apache.hadoop.hive.metastore.api.Table> source = getTable(metastoreContext, databaseName, tableName);
if (!source.isPresent()) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
}
try {
retry()
.stopOnIllegalExceptions()
.run("dropConstraint", stats.getDropConstraint().wrap(() ->
getMetastoreClientThenCall(metastoreContext, client -> {
client.dropConstraint(databaseName, tableName, constraintName);
return null;
})));
return EMPTY_RESULT;
}
catch (NoSuchObjectException e) {
throw new TableConstraintNotFoundException(Optional.of(constraintName));
}
catch (TException e) {
throw new PrestoException(HIVE_METASTORE_ERROR, e);
}View on GitHub (pinned to 55bb57d202)
Solutions
- Verify the table exists: run SHOW TABLES IN <catalog>.<schema> or call metastore.getTable before dropping the constraint.
- Correct the databaseName/tableName spelling and case (Hive names are lowercase).
- Confirm you are connected to the intended metastore/catalog (environment mismatch is common).
- Recreate the table if it was dropped concurrently, or skip the drop if the table no longer exists.
Example fix
// before: unconditional drop
metastore.dropConstraint(context, db, table, constraintName);
// after: check existence first
if (metastore.getTable(context, db, table).isPresent()) {
metastore.dropConstraint(context, db, table, constraintName);
} Defensive patterns
Strategy: validation
Validate before calling
Optional<Table> t = metastore.getTable(metastoreContext, db, table.toLowerCase(Locale.ROOT));
if (t.isEmpty()) { throw new IllegalArgumentException("Table " + db + "." + table + " does not exist"); } Try / catch
try {
metastore.dropConstraint(context, db, table, constraint);
} catch (TableNotFoundException e) {
// table absent: log and skip
} Prevention
- Always lowercase identifiers before metastore calls.
- Check table existence before constraint DDL.
- Confirm catalog/environment before mutating metadata.
- Handle concurrent drops gracefully in shared environments.
When it happens
Trigger: Calling dropConstraint(metastoreContext, databaseName, tableName, constraintName) where databaseName/tableName do not exist in the Hive metastore (getTable returns Optional.empty()).
Common situations: Typo in table or schema name, table was dropped by another job/user, case-sensitivity mismatch (Hive stores lowercase names), pointing at a different metastore environment (staging vs prod) than expected.
Related errors
- Table not found: ${databaseName}.${tableName}
- HIVE_DATABASE_LOCATION_ERROR
- HIVE_METASTORE_ERROR
- NOT_SUPPORTED
- Table not found: ${databaseName}.${tableName}
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/67d04d58f5785f47.
Report an issue: GitHub.