{"record":{"id":"16c9295a283e5091","repo":"apache/iceberg","slug":"failed-to-serialize-pk-index-key-16c929","errorCode":null,"errorMessage":"Failed to serialize PK index key","messagePattern":"Failed to serialize PK index key","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"error","filePath":"flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/maintenance/operator/StructLikeSerializer.java","lineNumber":68,"sourceCode":"  private final ByteArrayOutputStream baos = new ByteArrayOutputStream();\n  private final DataOutputStream dos = new DataOutputStream(baos);\n\n  public SerializedEqualityValues serializeKey(StructLike key, Types.StructType keyType) {\n    baos.reset();\n    try {\n      List<Types.NestedField> fields = keyType.fields();\n      dos.writeInt(fields.size());\n      for (Types.NestedField field : fields) {\n        dos.writeInt(field.fieldId());\n      }\n\n      for (int i = 0; i < fields.size(); i++) {\n        writeField(key, i, fields.get(i).type());\n      }\n\n      dos.flush();\n    } catch (IOException e) {\n      throw new UncheckedIOException(\"Failed to serialize PK index key\", e);\n    }\n\n    return new SerializedEqualityValues(baos.toByteArray());\n  }\n\n  public byte[] encodePartition(StructLike partition, Types.StructType partitionType) {\n    List<Types.NestedField> fields = partitionType.fields();\n    if (fields.isEmpty()) {\n      return EMPTY_PARTITION;\n    }\n\n    baos.reset();\n    try {\n      for (int i = 0; i < fields.size(); i++) {\n        writeField(partition, i, fields.get(i).type());\n      }\n\n      dos.flush();","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/maintenance/operator/StructLikeSerializer.java#L50-L86","documentation":"StructLikeSerializer.serializeKey writes each primary-key field of a StructLike row into a byte buffer for the equality-delete PK index. Any IOException from the underlying DataOutputStream (or from writeField) is wrapped in an UncheckedIOException 'Failed to serialize PK index key'.","triggerScenarios":"serializeKey is called on a StructLike whose PK field values cannot be written by writeField — e.g. a field type not handled by writeField, or the buffer/data output failing mid-write.","commonSituations":"Table schema changed the PK columns' types after the index was built (e.g. adding a nested/complex type the serializer does not support); a null or unexpected value in a key field reaching an unhandled branch.","solutions":["Inspect the wrapped cause (e.getCause()) to find which field type writeField rejected; ensure the equality-delete/PK columns use supported primitive types.","Re-run the maintenance index rebuild after schema changes so keys are serialized against the current schema.","If a new Iceberg type is involved, upgrade to an Iceberg version whose StructLikeSerializer handles it, or exclude that field from the PK index."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"for (Types.NestedField f : schema.primaryKeyFields()) {\n  Preconditions.checkArgument(\n      f.type().isPrimitiveType(),\n      \"Unsupported PK field type for index key: %s\", f.type());\n}","typeGuard":null,"tryCatchPattern":"try {\n  SerializedEqualityValues key = serializer.serializeKey(row, pkFields);\n} catch (UncheckedIOException e) {\n  LOG.error(\"PK key serialization failed: {}\", e.getCause().getMessage());\n  throw e; // index consistency requires failing the cycle\n}","preventionTips":["Keep equality-delete/PK columns to supported primitive types","Rebuild the index after any schema change to PK columns","Always inspect e.getCause() to identify the failing field type"],"tags":["serialization","flink","structlike","pk-index"],"backgroundTag":"json-marshal-failed","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}