{"record":{"id":"4a76c2ee312c5c7f","repo":"apache/iceberg","slug":"failed-to-serialize-pk-index-key","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/v1.20/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/v1.20/flink/src/main/java/org/apache/iceberg/flink/maintenance/operator/StructLikeSerializer.java#L50-L86","documentation":"StructLikeSerializer.serializeKey wraps any IOException thrown while writing a primary-key index key (a StructLike) into an UncheckedIOException. Since serialization to a ByteArrayOutputStream should not fail in practice, this signals an unexpected internal failure, typically from the underlying DataOutput writer.","triggerScenarios":"Calling serializeKey on a StructLike whose fields cannot be written by writeField (e.g. an unsupported/odd field type or an internal writer error) causing an IOException mid-write.","commonSituations":"Using Flink sink upsert/primary-key flows where the PK struct contains field types not handled by the serializer path, or internal buffer issues.","solutions":["Inspect the wrapped cause IOException for the actual failing field/type.","Confirm the table's primary key schema contains only types supported by the serializer (check writeField switch).","Upgrade Iceberg; if reproducible on supported types, file a bug with the schema."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Ensure all PK field types are in the supported set before enabling upsert\nschema.columns().stream().map(Types.NestedField::type).forEach(t -> check(supported.contains(t), \"Unsupported PK type: \" + t));","typeGuard":null,"tryCatchPattern":"try { key = serializer.serializeKey(pk); } catch (UncheckedIOException e) { LOG.error(\"PK key serialization failed\", e.getCause()); throw e; }","preventionTips":["Check the table primary key schema only uses supported types","Catch UncheckedIOException and inspect the cause for the failing field","Keep Iceberg versions current to get serializer fixes"],"tags":["flink","serialization","upsert"],"backgroundTag":"json-serialization-failed","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}