prestodb/presto · error · TableNotFoundException

Table not found: ${databaseName}.${tableName}

Error message

Table not found: ${databaseName}.${tableName}

What it means

Thrown as TableNotFoundException when renameTable cannot find the source table in the metastore before attempting the rename. The Thrift delegate's getTable returned empty, so the operation aborts with the qualified name in the message.

Source

Thrown at presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/thrift/BridgingHiveMetastore.java:227

    @Override
    public void dropTable(MetastoreContext metastoreContext, String databaseName, String tableName, boolean deleteData)
    {
        delegate.dropTable(metastoreContext, databaseName, tableName, deleteData);
    }

    @Override
    public MetastoreOperationResult replaceTable(MetastoreContext metastoreContext, String databaseName, String tableName, Table newTable, PrincipalPrivileges principalPrivileges)
    {
        checkArgument(!newTable.getTableType().equals(TEMPORARY_TABLE), "temporary tables must never be stored in the metastore");
        return alterTable(metastoreContext, databaseName, tableName, toMetastoreApiTable(newTable, principalPrivileges, metastoreContext.getColumnConverter()));
    }

    @Override
    public MetastoreOperationResult renameTable(MetastoreContext metastoreContext, String databaseName, String tableName, String newDatabaseName, String newTableName)
    {
        Optional<org.apache.hadoop.hive.metastore.api.Table> source = delegate.getTable(metastoreContext, databaseName, tableName);
        if (!source.isPresent()) {
            throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
        }
        org.apache.hadoop.hive.metastore.api.Table table = source.get();
        table.setDbName(newDatabaseName);
        table.setTableName(newTableName);
        return alterTable(metastoreContext, databaseName, tableName, table);
    }

    @Override
    public MetastoreOperationResult addColumn(MetastoreContext metastoreContext, String databaseName, String tableName, String columnName, HiveType columnType, String columnComment)
    {
        Optional<org.apache.hadoop.hive.metastore.api.Table> source = delegate.getTable(metastoreContext, databaseName, tableName);
        if (!source.isPresent()) {
            throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
        }
        org.apache.hadoop.hive.metastore.api.Table table = source.get();
        Column column = new Column(columnName, columnType, Optional.ofNullable(columnComment), Optional.empty());
        table.getSd().getCols().add(metastoreContext.getColumnConverter().fromColumn(column));
        return alterTable(metastoreContext, databaseName, tableName, table);

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Verify the table exists: SELECT * FROM system.metadata.tables WHERE schema_name='db' AND table_name='tbl' (or SHOW TABLES FROM db).
  2. Check the session catalog points to the intended Hive metastore.
  3. Fix typos and match exact case of schema/table names.
  4. Confirm no concurrent job renamed or dropped the table; adjust your workflow.

Example fix

// before
ALTER TABLE web.logs RENAME TO web.logsv2; -- logs does not exist
// after
SHOW TABLES FROM web; -- confirm exact name first
ALTER TABLE web.logs_v1 RENAME TO web.logs_v2;
Defensive patterns

Strategy: validation

Validate before calling

// verify before ALTER TABLE ... RENAME
SHOW TABLES FROM <database> LIKE '<tableName>';
-- or
SELECT * FROM system.metadata.tables
WHERE table_schema = '<database>' AND table_name = '<tableName>';

Try / catch

try {
    metadata.renameTable(session, tableHandle, newTableName);
} catch (TableNotFoundException e) {
    LOG.error("Table %s missing in metastore: %s", tableName, e.getMessage());
}

Prevention

When it happens

Trigger: Calling renameTable / ALTER TABLE ... RENAME TO when databaseName.tableName does not exist in the Hive metastore, or the caller lacks permission to see it (metastore hides it).

Common situations: Typo in schema or table name; table was already renamed or dropped by another job; wrong catalog selected in the session; case-sensitivity mismatch; metastore connectivity pointed at a different HMS instance.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/748267f139232a2a. Report an issue: GitHub.