{"record":{"id":"2bd31779d5ae5e5f","repo":"apache/iceberg","slug":"unknown-type-for-binary-field-type-name","errorCode":null,"errorMessage":"Unknown type for binary field. Type name: ","messagePattern":"Unknown type for binary field\\. Type name: ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/data/StructRowData.java","lineNumber":238,"sourceCode":"    return isNullAt(pos) ? null : getBinaryInternal(pos);\n  }\n\n  private byte[] getBinaryInternal(int pos) {\n    Object bytes = struct.get(pos, Object.class);\n\n    // should only be either ByteBuffer or byte[]\n    if (bytes instanceof ByteBuffer) {\n      return ByteBuffers.toByteArray((ByteBuffer) bytes);\n    } else if (bytes instanceof byte[]) {\n      return (byte[]) bytes;\n    } else if (bytes instanceof UUID) {\n      UUID uuid = (UUID) bytes;\n      ByteBuffer bb = ByteBuffer.allocate(16);\n      bb.putLong(uuid.getMostSignificantBits());\n      bb.putLong(uuid.getLeastSignificantBits());\n      return bb.array();\n    } else {\n      throw new IllegalStateException(\n          \"Unknown type for binary field. Type name: \" + bytes.getClass().getName());\n    }\n  }\n\n  @Override\n  public ArrayData getArray(int pos) {\n    return isNullAt(pos)\n        ? null\n        : (ArrayData)\n            convertValue(type.fields().get(pos).type().asListType(), struct.get(pos, List.class));\n  }\n\n  @Override\n  public MapData getMap(int pos) {\n    return isNullAt(pos)\n        ? null\n        : (MapData)\n            convertValue(type.fields().get(pos).type().asMapType(), struct.get(pos, Map.class));","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/data/StructRowData.java#L220-L256","documentation":"StructRowData.getBinaryInternal converts a struct field to a Flink byte[], accepting byte[], ByteBuffer and UUID (converted to its 16-byte representation). Any other class raises this IllegalStateException. It indicates a binary-typed field holds an unexpected Java object.","triggerScenarios":"Calling getBinary(pos) (which delegates to getBinaryInternal) where the field value is not byte[], ByteBuffer, or UUID, e.g. a String or BigDecimal.","commonSituations":"Writers encoding binary/UUID data as Strings or hex text; UUID stored as String rather than java.util.UUID; fixed/decimal values routed into binary columns.","solutions":["Write binary fields as byte[]/ByteBuffer (or java.util.UUID for UUID-typed fields).","If the value is a String, decode it (e.g. Base64/hex) to bytes before storing.","Check the Flink type mapping: BINARY/VARBINARY columns must contain byte[] in the struct."],"exampleFix":"// before\nrow.setField(pos, uuidString); // String\n\n// after\nUUID uuid = UUID.fromString(uuidString);\nrow.setField(pos, uuid); // supported by getBinaryInternal","handlingStrategy":"type-guard","validationCode":"Object v = struct.getField(pos);\nif (!(v instanceof byte[] || v instanceof ByteBuffer || v instanceof UUID)) {\n  throw new IllegalArgumentException(\"Unexpected class for binary field: \" + v.getClass());\n}","typeGuard":"boolean isBinaryCompatible(Object v) {\n  return v instanceof byte[] || v instanceof ByteBuffer || v instanceof UUID;\n}","tryCatchPattern":"try {\n  byte[] b = rowData.getBinary(pos);\n} catch (IllegalStateException e) {\n  // decode the value (e.g. Base64 string -> bytes) and retry\n}","preventionTips":["Write binary fields as byte[] or ByteBuffer; UUIDs as java.util.UUID.","Never store hex/Base64 strings in binary columns.","Add writer-side schema-to-class checks for BINARY/VARBINARY/UUID fields."],"tags":["flink","binary","type-mismatch"],"backgroundTag":"type-mismatch","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"}