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
- Verify the table exists: SHOW TABLES FROM <schema> and check the exact name
- Refresh/SHOW COLUMNS or re-run the query if the table was just recreated
- Check you are connected to the correct catalog and metastore (dev vs prod)
- 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
- Validate table existence (SHOW TABLES / information_schema.tables) before analysis jobs
- Avoid dropping/recreating tables while queries referencing them are planning
- Qualify names with the exact catalog and schema to avoid cross-catalog typos
- Re-check names after metastore replication or migration activities
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
- HIVE_CORRUPTED_COLUMN_STATISTICS
- HIVE_UNKNOWN_COLUMN_STATISTIC_TYPE
- HIVE_PARTITION_DROPPED_DURING_QUERY
- Table not found: ${databaseName}.${tableName}
- Table not found: ${databaseName}.${tableName}
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/714746f208094322.
Report an issue: GitHub.