{"record":{"id":"ed85dd5f7c6fed66","repo":"prestodb/presto","slug":"hive-invalid-metadata-ed85dd","errorCode":"HIVE_INVALID_METADATA","errorMessage":"Table is missing storage descriptor","messagePattern":"Table is missing storage descriptor","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/thrift/HiveMetastore.java","lineNumber":183,"sourceCode":"        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    }\n\n    default List<NotNullConstraint<String>> getNotNullConstraints(MetastoreContext metastoreContext, String databaseName, String tableName)\n    {\n        return ImmutableList.of();","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/thrift/HiveMetastore.java#L165-L201","documentation":"The table record was found but its StorageDescriptor (sd) is null, which is malformed Hive metadata — every table should carry a storage descriptor describing columns, input/output formats, and location. getFields throws HIVE_INVALID_METADATA to surface corrupt metastore data instead of a confusing NPE.","triggerScenarios":"Reading fields of a table whose metastore row was written incompletely (failed DDL), hand-edited, or corrupted by a buggy metastore/backup-restore process.","commonSituations":"Interrupted CREATE TABLE leaving partial rows; direct manipulation of the metastore RDBMS; restore from backup losing the SD blob; third-party tools writing tables without an SD; corrupt Glue/metadata sync.","solutions":["Drop and recreate the table from DDL; repopulate data if it lives in the underlying storage.","Inspect the metastore backend ( HMS RDBMS 'SDS' table) to confirm the null SD and repair the row via Hive tooling.","Restore the table metadata from a valid backup or re-run the creating job.","Run msck/repair and Hive 'DESCRIBE' on the table to detect further corruption; upgrade the metastore if a known bug produced null SDs."],"exampleFix":"// before\nSELECT * FROM hive.web.broken; -- sd == null\n// after\nDROP TABLE hive.web.broken;\nCREATE TABLE hive.web.broken (...) WITH (format = 'ORC', location = 's3://...');\nMSCK REPAIR TABLE hive.web.broken;","handlingStrategy":"validation","validationCode":"-- detect malformed table before querying\nSHOW CREATE TABLE <database>.<tableName>;\n-- fails or shows no column/storage info for corrupted tables","typeGuard":null,"tryCatchPattern":"try {\n    columns = metadata.getColumnHandles(session, tableHandle);\n} catch (PrestoException e) {\n    if (HiveErrorCode.HIVE_INVALID_METADATA.toErrorCode().equals(e.getErrorCode())) {\n        // drop/recreate table or restore metastore metadata\n    } else {\n        throw e;\n    }\n}","preventionTips":["Avoid direct edits to the metastore RDBMS","Ensure DDL jobs complete atomically; monitor for failed CREATE TABLE","Keep metastore backups and test restores","Alert on PrestoException HIVE_INVALID_METADATA as an ops signal of corruption"],"tags":["hive","corrupt-metadata","metastore","storage-descriptor"],"backgroundTag":"invalid-metadata","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"}