{"record":{"id":"f30a649681a9f020","repo":"prestodb/presto","slug":"hive-invalid-metadata-f30a64","errorCode":"HIVE_INVALID_METADATA","errorMessage":"SerDe is not present in StorageFormat","messagePattern":"SerDe is not present in StorageFormat","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/StorageFormat.java","lineNumber":48,"sourceCode":"public class StorageFormat\n{\n    public static final StorageFormat VIEW_STORAGE_FORMAT = StorageFormat.createNullable(null, null, null);\n\n    private final String serDe;\n    private final String inputFormat;\n    private final String outputFormat;\n\n    private StorageFormat(String serDe, String inputFormat, String outputFormat)\n    {\n        this.serDe = serDe;\n        this.inputFormat = inputFormat;\n        this.outputFormat = outputFormat;\n    }\n\n    public String getSerDe()\n    {\n        if (serDe == null) {\n            throw new PrestoException(HIVE_INVALID_METADATA, \"SerDe is not present in StorageFormat\");\n        }\n        return serDe;\n    }\n\n    public String getInputFormat()\n    {\n        if (inputFormat == null) {\n            throw new PrestoException(HIVE_UNSUPPORTED_FORMAT, \"InputFormat is not present in StorageFormat\");\n        }\n        return inputFormat;\n    }\n\n    public String getOutputFormat()\n    {\n        if (outputFormat == null) {\n            throw new PrestoException(HIVE_UNSUPPORTED_FORMAT, \"OutputFormat is not present in StorageFormat\");\n        }\n        return outputFormat;","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive-metastore/src/main/java/com/facebook/presto/hive/metastore/StorageFormat.java#L30-L66","documentation":"StorageFormat is an optional-container for serDe/inputFormat/outputFormat read from Hive storage descriptors. getSerDe() throws HIVE_INVALID_METADATA when the serDe field is null, meaning the table or partition's storage descriptor lacks a SerDe name — the metadata cannot describe how to serialize/deserialize the data, so reads/writes are impossible.","triggerScenarios":"Querying or writing a table/partition whose metastore StorageDescriptor has no SerDe (null serDe in StorageFormat), typically from metadata written without a SerDe or stripped by another tool; getSerDe is called by serde(), fileContent(), createFileWriter(), etc.","commonSituations":"Tables created by external tools with incomplete storage descriptors; partitions added manually to the metastore without serde info; corrupted storage descriptors after migration; CREATE TABLE scripts omitting ROW FORMAT SERDE.","solutions":["Fix the table/partition metadata so the storage descriptor includes a valid SerDe (e.g. ALTER TABLE ... SET SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe')","Drop and re-create the table/partition with a complete ROW FORMAT SERDE clause","Restore the storage descriptor from metastore backup if corrupted","If a partition was added manually, re-add it with MSCK or with full storage descriptor info"],"exampleFix":"// before (metadata without serde)\nCREATE EXTERNAL TABLE t (a int) STORED AS TEXTFILE LOCATION '...';\n// after\nCREATE EXTERNAL TABLE t (a int)\nROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'\nSTORED AS TEXTFILE LOCATION '...';","handlingStrategy":"validation","validationCode":"// Validate storage descriptor before querying the table via Thrift metastore\nStorageDescriptor sd = table.getSd();\nif (sd.getSerdeInfo() == null || sd.getSerdeInfo().getSerializationLib() == null) {\n    throw new IllegalStateException(\"table missing SerDe: \" + table.getTableName());\n}","typeGuard":"boolean hasSerde(StorageFormat format) {\n    return format.getSerDeNullable() != null;\n}","tryCatchPattern":"try {\n    selectFrom(table);\n} catch (PrestoException e) {\n    if (e.getErrorCode().getName().equals(\"HIVE_INVALID_METADATA\")) {\n        // ALTER TABLE ... SET SERDE or recreate the table\n    }\n    throw e;\n}","preventionTips":["Always specify ROW FORMAT SERDE / STORED AS when creating external tables","Run MSCK REPAIR or full-partition adds rather than manual metastore inserts","Audit metastore storage descriptors after migrations","Use getSerDeNullable() to probe instead of getSerDe() when metadata may be incomplete"],"tags":["hive","metadata","serde","storage-format"],"backgroundTag":"missing-serde-in-storage-format","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"}