{"record":{"id":"4a518bae7f0537e1","repo":"apache/beam","slug":"partitionspec-with-id-not-found-in-partitionspecs-map","errorCode":null,"errorMessage":"PartitionSpec with id {} not found in partitionSpecs map","messagePattern":"PartitionSpec with id (.+?) not found in partitionSpecs map","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/SerializableTableSpec.java","lineNumber":168,"sourceCode":"        local = cachedPartitionSpecs;\n        if (local == null) {\n          ImmutableMap.Builder<Integer, PartitionSpec> builder = ImmutableMap.builder();\n          for (Map.Entry<Integer, String> entry : getPartitionSpecsJson().entrySet()) {\n            builder.put(\n                entry.getKey(), PartitionSpecParser.fromJson(getSchema(), entry.getValue()));\n          }\n          cachedPartitionSpecs = local = builder.build();\n        }\n      }\n    }\n    return local;\n  }\n\n  @SchemaIgnore\n  public PartitionSpec getPartitionSpec() {\n    PartitionSpec spec = getPartitionSpecs().get(getSpecId());\n    if (spec == null) {\n      throw new IllegalStateException(\n          \"PartitionSpec with id \" + getSpecId() + \" not found in partitionSpecs map\");\n    }\n    return spec;\n  }\n\n  @SchemaIgnore\n  public @Nullable PartitionSpec getPartitionSpec(int specId) {\n    return getPartitionSpecs().get(specId);\n  }\n\n  @SchemaIgnore\n  public Map<Integer, SortOrder> getSortOrders() {\n    Map<Integer, SortOrder> local = cachedSortOrders;\n    if (local == null) {\n      synchronized (this) {\n        local = cachedSortOrders;\n        if (local == null) {\n          ImmutableMap.Builder<Integer, SortOrder> builder = ImmutableMap.builder();","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/SerializableTableSpec.java#L150-L186","documentation":"SerializableTableSpec.getPartitionSpec() resolves the stored specId against the serialized partitionSpecs map and throws IllegalStateException if absent. Like the schema lookup, the map is a snapshot of table.specs(); a miss means the serialized state is inconsistent or the spec was removed/evolved between snapshot and use.","triggerScenarios":"Calling getPartitionSpec() when partitionSpecs lacks the entry for getSpecId(), e.g. deserializing a spec produced by a different table version after partition evolution, or building the object with a specId that was never added.","commonSituations":"Partition spec evolution making an old specId unavailable; restoring stale checkpoint/beam state; tests constructing the object manually with only some fields populated.","solutions":["Rebuild via SerializableTableSpec.from(currentTable) so partitionSpecs comes from table.specs().","Confirm the stored specId exists in the table's spec map; if the spec was dropped, remap to the current spec.","Refresh the table and re-serialize state after partition evolution.","Verify producer and consumer use the same connector/table snapshot."],"exampleFix":"// before\nlong specId = 0; // stale id after partition evolution\nSerializableTableSpec spec = ...withSpecId(specId)...;\n// after\nSerializableTableSpec spec = SerializableTableSpec.from(table); // uses table.currentSpec().specId() with matching map","handlingStrategy":"validation","validationCode":"PartitionSpec ps = spec.getPartitionSpecs().get(spec.getSpecId());\nif (ps == null) {\n  // spec id missing — rebuild from current table or remap to an existing spec\n  spec = SerializableTableSpec.from(table);\n}","typeGuard":null,"tryCatchPattern":"try {\n  PartitionSpec ps = spec.getPartitionSpec();\n} catch (IllegalStateException e) {\n  // rebuild from table / fall back to currentSpec\n}","preventionTips":["Re-serialize specs after any partition evolution.","Don't reuse spec objects across different table snapshots.","Include multi-spec tables in round-trip tests."],"tags":["iceberg","java","serialization","partition-spec","lookup"],"backgroundTag":"record-not-found","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}