{"record":{"id":"c23f11efdf2be035","repo":"prestodb/presto","slug":"hive-invalid-partition-value","errorCode":"HIVE_INVALID_PARTITION_VALUE","errorMessage":"partition key value cannot be null for field: %s","messagePattern":"partition key value cannot be null for field: (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/HiveMaterializedViewUtils.java","lineNumber":176,"sourceCode":"        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()));\n    }\n\n    // Every table on outer join side, must have a partition which is in EQ clause and present in Materialized View as well.\n    // For a given base table, this function computes partition columns of Materialized View which are not directly mapped to base table,\n    // and are directly mapped to some other base table which is not on outer join side.\n    // For example:","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/HiveMaterializedViewUtils.java#L158-L194","documentation":"When parsing each partition name's key/value map for data predicates, every declared partition key must be present. If a partition key name is missing from the parsed map (null value), Presto throws HIVE_INVALID_PARTITION_VALUE, since a partition value cannot be null.","triggerScenarios":"A partition name string in the metastore that omits one of the table's declared partition key fields, so partitions.get(name) returns null during getMaterializedDataPredicates.","commonSituations":"Partitions created before a partition column was added; malformed partition directory names (missing a key=value component); metastore entries written by other tooling with incomplete partition specs.","solutions":["Drop and re-add the affected partitions with complete key=value specs","Run MSCK REPAIR TABLE to resync partition metadata","Inspect the partition directory names on storage and fix the missing key","Fix the metastore partition record directly if the storage layout is correct"],"exampleFix":"-- before\nALTER TABLE t ADD PARTITION (ds='2024-01-01'); -- table has (ds, hr)\n-- after\nALTER TABLE t ADD PARTITION (ds='2024-01-01', hr='00');","handlingStrategy":"validation","validationCode":"partitionTypes.forEach((name, type) -> {\n    if (parts.get(name) == null) {\n        throw new IllegalStateException(\"Missing partition value for key: \" + name);\n    }\n});","typeGuard":"boolean isCompletePartitionSpec(Map<String,String> spec, List<String> keys) {\n    return keys.stream().allMatch(spec::containsKey);\n}","tryCatchPattern":"try {\n    // parse partition values\n} catch (PrestoException e) {\n    if (e.getErrorCode().getCode() == HIVE_INVALID_PARTITION_VALUE.toErrorCode().getCode()) {\n        // drop and re-add the malformed partition\n    } else throw e;\n}","preventionTips":["Always supply every partition key when adding partitions","Verify partition directory names contain all key=value components","Run MSCK REPAIR TABLE after bulk-loading data","Add schema-evolution checks when adding partition columns to existing tables"],"tags":["hive","partitioning","metadata","null-value"],"backgroundTag":"invalid-partition-value","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"}