{"record":{"id":"d21a5d1c318fbb89","repo":"apache/iceberg","slug":"failed-to-encode-partition-d21a5d","errorCode":null,"errorMessage":"Failed to encode partition","messagePattern":"Failed to encode partition","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"error","filePath":"flink/v2.3/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.3/flink/src/main/java/org/apache/iceberg/flink/maintenance/operator/StructLikeSerializer.java#L70-L106","documentation":"encodePartition() serializes a StructLike partition tuple to bytes (length-prefixed, per-field). An IOException from the underlying write path is wrapped in UncheckedIOException. It almost always signals that a partition value cannot be converted to the declared partition field type via Conversions.toByteBuffer.","triggerScenarios":"Passing a partition StructLike whose values don't match partitionType (e.g. mismatched types after spec/schema changes); a null-typed or custom StructLike returning an unexpected object type.","commonSituations":"Partition spec evolved and the encoder is given old partition objects with a new partition type; manually constructed PartitionData with wrong value types; rows produced by an engine writing partition values in a different representation.","solutions":["Ensure the StructLike partition values match partitionType exactly (use PartitionData built from the same Types.StructType)","Re-derive partitions from the table's current spec rather than reusing cached ones from before a spec change","Check for type mismatches like Integer vs Long for int/long partition fields and fix the producer","Catch the UncheckedIOException and log the partition type and values to identify the offending field"],"exampleFix":"// before\nPartitionData p = new PartitionData(oldSpecPartitionType);\np.set(0, \"2024-01-01\"); // string for a date field\n// after\nPartitionData p = new PartitionData(table.spec().partitionType());\np.set(0, LocalDate.parse(\"2024-01-01\"));","handlingStrategy":"validation","validationCode":"Types.StructType partType = table.spec().partitionType();\nfor (int i = 0; i < partType.fields().size(); i++) {\n  Object v = partition.get(i, Object.class);\n  Preconditions.checkState(v == null || v.getClass() == expectedJavaClass(partType.fields().get(i).type()),\n      \"Partition field %s expects %s but got %s\", partType.fields().get(i).name(),\n      partType.fields().get(i).type(), v == null ? null : v.getClass());\n}","typeGuard":null,"tryCatchPattern":"try {\n  byte[] encoded = serializer.encodePartition(partition, partitionType);\n} catch (UncheckedIOException e) {\n  LOG.error(\"Partition encode failed for type {} values {}\", partitionType, partition, e);\n  throw e;\n}","preventionTips":["Always derive partition StructLike values from the table's current spec","Recompute partition objects after any partition spec evolution","Write round-trip tests for encodePartition/decodePartition when touching specs"],"tags":["flink","serialization","partition","unchecked-io"],"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-23T08:17:48.524Z"}