{"record":{"id":"28a9dc435a0c0bc9","repo":"prestodb/presto","slug":"hive-invalid-metadata-28a9dc","errorCode":"HIVE_INVALID_METADATA","errorMessage":"Expected %d partition key values, but got %d","messagePattern":"Expected (.+?) partition key values, but got (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/HiveMaterializedViewUtils.java","lineNumber":170,"sourceCode":"                throw new PrestoException(\n                        NOT_SUPPORTED,\n                        String.format(\"Unsupported Hive type %s found in partition keys of table %s.%s\", hiveType, table.getDatabaseName(), table.getTableName()));\n            }\n        }\n\n        List<HiveColumnHandle> partitionKeyColumnHandles = getPartitionKeyColumnHandles(table);\n        Map<String, Type> partitionTypes = partitionKeyColumnHandles.stream()\n                .collect(toImmutableMap(HiveColumnHandle::getName, column -> typeManager.getType(column.getTypeSignature())));\n\n        List<PartitionNameWithVersion> partitionNames = metastore.getPartitionNames(metastoreContext, table.getDatabaseName(), table.getTableName())\n                .orElseThrow(() -> new TableNotFoundException(new SchemaTableName(table.getDatabaseName(), table.getTableName())));\n\n        ImmutableList.Builder<TupleDomain<String>> partitionNamesAndValues = ImmutableList.builder();\n        for (PartitionNameWithVersion partitionName : partitionNames) {\n            ImmutableMap.Builder<String, NullableValue> partitionNameAndValuesMap = ImmutableMap.builder();\n            Map<String, String> partitions = toPartitionNamesAndValues(partitionName.getPartitionName());\n            if (partitionColumns.size() != partitions.size()) {\n                throw new PrestoException(HIVE_INVALID_METADATA, String.format(\n                        \"Expected %d partition key values, but got %d\", partitionColumns.size(), partitions.size()));\n            }\n            partitionTypes.forEach((name, type) -> {\n                String value = partitions.get(name);\n                if (value == null) {\n                    throw new PrestoException(HIVE_INVALID_PARTITION_VALUE, String.format(\"partition key value cannot be null for field: %s\", name));\n                }\n\n                partitionNameAndValuesMap.put(name, parsePartitionValue(Optional.of(session), name, value, type, timeZone));\n            });\n\n            TupleDomain<String> tupleDomain = TupleDomain.fromFixedValues(partitionNameAndValuesMap.build());\n            partitionNamesAndValues.add(tupleDomain);\n        }\n\n        return new MaterializedDataPredicates(partitionNamesAndValues.build(), partitionColumns.stream()\n                .map(Column::getName)\n                .collect(toImmutableList()));","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/HiveMaterializedViewUtils.java#L152-L188","documentation":"While building materialized data predicates, each partition name string is parsed into key/value pairs and compared to the table's declared partition columns. If the count of parsed partition key values does not match the number of partition columns, the metastore data is inconsistent and HIVE_INVALID_METADATA is thrown.","triggerScenarios":"Calling refresh/analysis paths that pass PartitionNameWithVersion entries whose partition name string parses to a different number of key=value components than table.getPartitionColumns().size().","commonSituations":"Corrupted or hand-edited partition names in the metastore; partitions created by a different engine with a different partition schema; the table's partition columns changed (ALTER) without fixing existing partitions; stale cached partition lists after schema evolution.","solutions":["Run SHOW PARTITIONS / MSCK REPAIR to inspect and reconcile metastore partitions","Drop the malformed partition(s) and re-add them with the correct schema","Alter the table to restore the original partition column count","Repair the metastore entries directly (Hive metastore client) for the offending partition names"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"Map<String, String> parts = toPartitionNamesAndValues(partitionName);\nif (parts.size() != table.getPartitionColumns().size()) {\n    throw new IllegalStateException(\"Partition spec arity mismatch for \" + partitionName);\n}","typeGuard":null,"tryCatchPattern":"try {\n    // use partition predicates\n} catch (PrestoException e) {\n    if (e.getErrorCode().getCode() == HIVE_INVALID_METADATA.toErrorCode().getCode()) {\n        // trigger MSCK REPAIR or drop/re-add offending partition\n    } else throw e;\n}","preventionTips":["Run MSCK REPAIR TABLE periodically to keep metastore partitions consistent","Avoid manually editing partition directory names or metastore records","Freeze partition-column schema before loading data; evolve via new tables","Validate partition names after migrations between engines"],"tags":["hive","partitioning","metadata","metastore"],"backgroundTag":"partition-metadata-mismatch","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"}