prestodb/presto · error · TableNotFoundException

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

Error message

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

What it means

TableNotFoundException is thrown by ThriftHiveMetastore.getTableColumnStatistics when the Hive Metastore reports NoSuchObjectException while fetching column statistics for databaseName.tableName. The table the query referenced does not exist in the metastore at statistics-fetch time.

Source

Thrown at presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/thrift/ThriftHiveMetastore.java:494

                .map(FieldSchema::getName)
                .collect(toImmutableList());
        HiveBasicStatistics basicStatistics = getHiveBasicStatistics(table.getParameters());
        Map<String, HiveColumnStatistics> columnStatistics = getTableColumnStatistics(metastoreContext, databaseName, tableName, dataColumns, basicStatistics.getRowCount());
        return new PartitionStatistics(basicStatistics, columnStatistics);
    }

    private Map<String, HiveColumnStatistics> getTableColumnStatistics(MetastoreContext metastoreContext, String databaseName, String tableName, List<String> columns, OptionalLong rowCount)
    {
        try {
            return retry()
                    .stopOn(NoSuchObjectException.class, HiveViewNotSupportedException.class)
                    .stopOnIllegalExceptions()
                    .run("getTableColumnStatistics", stats.getGetTableColumnStatistics().wrap(() ->
                            getMetastoreClientThenCall(metastoreContext, client ->
                                    groupStatisticsByColumn(client.getTableColumnStatistics(databaseName, tableName, columns), rowCount))));
        }
        catch (NoSuchObjectException e) {
            throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
        }
        catch (TException e) {
            throw new PrestoException(HIVE_METASTORE_ERROR, e);
        }
        catch (Exception e) {
            throw propagate(e);
        }
    }

    @Override
    public Map<String, PartitionStatistics> getPartitionStatistics(MetastoreContext metastoreContext, String databaseName, String tableName, Set<String> partitionNames)
    {
        Table table = getTable(metastoreContext, databaseName, tableName)
                .orElseThrow(() -> new TableNotFoundException(new SchemaTableName(databaseName, tableName)));
        List<String> dataColumns = table.getSd().getCols().stream()
                .map(FieldSchema::getName)
                .collect(toImmutableList());
        List<String> partitionColumns = table.getPartitionKeys().stream()

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Verify the table exists: SHOW TABLES FROM <schema> and check the exact name
  2. Refresh/SHOW COLUMNS or re-run the query if the table was just recreated
  3. Check you are connected to the correct catalog and metastore (dev vs prod)
  4. Recreate the table or fix the DROP that removed it

Example fix

-- before
SELECT * FROM hive.sales.salez;
-- after (corrected table name)
SELECT * FROM hive.sales.sales;
Defensive patterns

Strategy: validation

Validate before calling

// Confirm the table exists before requesting column statistics
boolean exists = metastore.getTable(databaseName, tableName).isPresent();
if (!exists) {
    throw new IllegalStateException("Table " + databaseName + "." + tableName + " does not exist in the metastore");
}

Try / catch

try {
    return columnStatistics(tableHandle, columns);
}
catch (TableNotFoundException e) {
    // table vanished mid-query; surface a clear message or fall back to empty stats
    return Optional.empty();
}

Prevention

When it happens

Trigger: Calling getTableColumnStatistics (from columnStatistics during query planning) with a database/tableName for which client.getTableColumnStatistics raises NoSuchObjectException.

Common situations: Table dropped between query submission and planning; typo in table or schema name; querying a table that exists only in another catalog; stale metadata after metastore replication lag.

Related errors


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