{"record":{"id":"15b29747a2382f81","repo":"prestodb/presto","slug":"table-not-found-databasename-tablename-15b297","errorCode":null,"errorMessage":"Table not found: ${databaseName}.${tableName}","messagePattern":"Table not found: (.+?)\\.(.+?)","errorType":"exception","errorClass":"TableNotFoundException","httpStatus":null,"severity":"error","filePath":"presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/thrift/HiveMetastore.java","lineNumber":179,"sourceCode":"    }\n\n    default void setPartitionLeases(MetastoreContext metastoreContext, String databaseName, String tableName, Map<String, String> partitionNameToLocation, Duration leaseDuration)\n    {\n        throw new UnsupportedOperationException();\n    }\n\n    default boolean isTableOwner(MetastoreContext metastoreContext, String user, String databaseName, String tableName)\n    {\n        // a table can only be owned by a user\n        Optional<Table> table = getTable(metastoreContext, databaseName, tableName);\n        return table.isPresent() && user.equals(table.get().getOwner());\n    }\n\n    default Optional<List<FieldSchema>> getFields(MetastoreContext metastoreContext, String databaseName, String tableName)\n    {\n        Optional<Table> table = getTable(metastoreContext, databaseName, tableName);\n        if (!table.isPresent()) {\n            throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));\n        }\n\n        if (table.get().getSd() == null) {\n            throw new PrestoException(HIVE_INVALID_METADATA, \"Table is missing storage descriptor\");\n        }\n\n        return Optional.of(table.get().getSd().getCols());\n    }\n\n    default Optional<PrimaryKeyConstraint<String>> getPrimaryKey(MetastoreContext metastoreContext, String databaseName, String tableName)\n    {\n        return Optional.empty();\n    }\n\n    default List<UniqueConstraint<String>> getUniqueConstraints(MetastoreContext metastoreContext, String databaseName, String tableName)\n    {\n        return ImmutableList.of();\n    }","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/thrift/HiveMetastore.java#L161-L197","documentation":"HiveMetastore.getFields is a default interface method that resolves the table then returns its storage descriptor columns. If getTable finds no table it throws TableNotFoundException with the qualified name rather than returning Optional.empty.","triggerScenarios":"Calling getFields (used by metadata/preview paths) for a databaseName.tableName absent from the metastore.","commonSituations":"Stale cached metadata pointing at a dropped table; typos in generated queries; querying a table in a different catalog; permission-filtered visibility in secured metastores.","solutions":["Confirm the table exists via SHOW TABLES / SHOW CREATE TABLE before calling metadata APIs.","Refresh Presto metadata caches if the table was recently created or dropped (or restart/reconnect).","Check the catalog and schema qualifiers in the query.","Verify metastore permissions for the executing principal."],"exampleFix":"// before\nColumnHandle ch = metadata.getFields(session, new SchemaTableName(\"web\", \"logs\")); // logs absent\n// after\nif (metadata.getTableHandle(session, new SchemaTableName(\"web\", \"logs\")) != null) {\n    metadata.getFields(session, new SchemaTableName(\"web\", \"logs\"));\n}","handlingStrategy":"validation","validationCode":"// caller-side existence check\nboolean present = metadata.getTableHandle(session, qualifiedTableName) != null;\nif (!present) { throw new UserInputError(\"table not found: \" + qualifiedTableName); }","typeGuard":null,"tryCatchPattern":"try {\n    columns = metadata.getColumnHandles(session, tableHandle);\n} catch (TableNotFoundException e) {\n    LOG.error(\"getFields failed: %s\", e.getMessage());\n    // refresh metadata cache or re-resolve the table handle\n}","preventionTips":["Refresh or invalidate metadata caches after DDL","Resolve table handles via metadata APIs rather than cached names","Use qualified names and verify against system.metadata.tables","Check metastore visibility permissions for the principal"],"tags":["hive","table-not-found","metastore","metadata"],"backgroundTag":"table-not-found","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}