{"record":{"id":"17eddde8daa9dfd3","repo":"apache/iceberg","slug":"failed-to-encode-partition-17eddd","errorCode":null,"errorMessage":"Failed to encode partition","messagePattern":"Failed to encode partition","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":88,"sourceCode":"\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();\n    } catch (IOException e) {\n      throw new UncheckedIOException(\"Failed to encode partition\", e);\n    }\n\n    return baos.toByteArray();\n  }\n\n  public static StructLike decodePartition(byte[] encoded, Types.StructType partitionType) {\n    PartitionData partition = new PartitionData(partitionType);\n    List<Types.NestedField> fields = partitionType.fields();\n    if (fields.isEmpty()) {\n      return partition;\n    }\n\n    try (DataInputStream dis = new DataInputStream(new ByteArrayInputStream(encoded))) {\n      for (int i = 0; i < fields.size(); i++) {\n        boolean isNull = dis.readBoolean();\n        if (isNull) {\n          partition.set(i, null);\n        } else {","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/maintenance/operator/StructLikeSerializer.java#L70-L106","documentation":"StructLikeSerializer.encodePartition serializes each field of a partition StructLike (using the partition spec's struct type) into a byte[] used to group/compare partitions. An IOException while writing is wrapped in an UncheckedIOException 'Failed to encode partition'.","triggerScenarios":"encodePartition is called with a partition StructLike and Types.StructType whose fields writeField cannot encode — typically a partition field type unsupported by writeField or an IO failure on the internal DataOutputStream.","commonSituations":"Partition spec evolved to include a field type the current serializer does not handle; a partition value is null where the encoder expects a value; passing the wrong partitionType (mismatched specId) so fields do not line up.","solutions":["Check the wrapped cause to identify the failing field type; ensure partition fields are supported primitive types.","Pass the correct Types.StructType for the file's specId (table.specs().get(dataFile.specId().partitionType()) style lookup) rather than the default spec's type.","Re-run the maintenance cycle after any partition-spec evolution so partitions are encoded with the current spec metadata."],"exampleFix":"// before\nbyte[] key = serializer.encodePartition(dataFile.partition(), table.spec().partitionType());\n// assumes the file uses the current spec\n\n// after\nTypes.StructType pt = table.specs().get(dataFile.specId()).partitionType();\nbyte[] key = serializer.encodePartition(dataFile.partition(), pt);","handlingStrategy":"validation","validationCode":"Types.StructType partitionType = table.specs().get(dataFile.specId()).partitionType();\nfor (int i = 0; i < partitionType.fields().size(); i++) {\n  Preconditions.checkArgument(\n      partitionType.fields().get(i).type().isPrimitiveType(),\n      \"Unsupported partition field type: %s\", partitionType.fields().get(i).type());\n}","typeGuard":null,"tryCatchPattern":"try {\n  byte[] encoded = serializer.encodePartition(partition, partitionType);\n} catch (UncheckedIOException e) {\n  LOG.error(\"Partition encoding failed: {}\", e.getCause().getMessage());\n  throw e;\n}","preventionTips":["Use the partition type of the file's own specId, not table.spec()","Keep partition fields to supported primitive types","Re-encode partitions after partition-spec evolution instead of reusing old encodings"],"tags":["serialization","flink","partition","structlike"],"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"}