{"record":{"id":"64a5631670ff033e","repo":"apache/beam","slug":"unsupported-underlying-type-for-producing-logicaltype-via","errorCode":null,"errorMessage":"Unsupported underlying type for producing LogicalType via coder.","messagePattern":"Unsupported underlying type for producing LogicalType via coder\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/SchemaTranslation.java","lineNumber":765,"sourceCode":"\n  /** Converts logical type value to a proto using a default type coder. */\n  private static LogicalTypeValue logicalTypeToProto(\n      FieldType baseType, FieldType inputType, Object value) {\n    try {\n      PipedInputStream in = new PipedInputStream();\n      PipedOutputStream out = new PipedOutputStream(in);\n      SchemaCoderHelpers.coderForFieldType(inputType).encode(value, out);\n      out.close(); // Close required for toByteArray.\n      Object baseObject;\n      switch (baseType.getTypeName()) {\n        case INT64:\n          baseObject = new DataInputStream(in).readLong();\n          break;\n        case BYTES:\n          baseObject = ByteStreams.toByteArray(in);\n          break;\n        default:\n          throw new UnsupportedOperationException(\n              \"Unsupported underlying type for producing LogicalType via coder.\");\n      }\n      return LogicalTypeValue.newBuilder()\n          .setValue(fieldValueToProto(baseType, baseObject))\n          .build();\n    } catch (IOException e) {\n      throw new RuntimeException(e);\n    }\n  }\n\n  private static LogicalTypeValue logicalTypeToProto(LogicalType logicalType, Object value) {\n    return LogicalTypeValue.newBuilder()\n        .setValue(\n            fieldValueToProto(\n                logicalType.getBaseType(), SchemaUtils.toLogicalBaseType(logicalType, value)))\n        .build();\n  }\n","sourceCodeStart":747,"sourceCodeEnd":783,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/SchemaTranslation.java#L747-L783","documentation":"logicalTypeToProto encodes a logical type value via its representation coder into a proto. After encoding, it reads the raw representation back out of the stream; only INT64, DOUBLE, STRING, and BYTES atomic cases are supported. Any other representation type hits this UnsupportedOperationException because the encoded representation cannot be mapped to a proto AtomicTypeValue.","triggerScenarios":"fieldValueToProto → logicalTypeToProto with a FieldType whose logical type representation is a non-atomic or unsupported FieldType (e.g. ARRAY, ROW, MAP, ITERABLE) routed through the coder-based path.","commonSituations":"Custom logical type declaring a complex representation type; Beam version where the coder path doesn't support the representation used; schema translated from another system mapping a structured representation onto a Beam logical type.","solutions":["Change the logical type's representation to a primitive (BYTES is the usual safe choice) and serialize complex representations to bytes yourself.","Upgrade Beam if a newer version supports your representation case in this path.","Bypass the coder path by ensuring the logical type is registered with a standard URN so logicalTypeToProto(LogicalType, Object) is used instead."],"exampleFix":"// before\npublic FieldType getRepresentation() { return FieldType.row(mySchema); }\n// after\npublic FieldType getRepresentation() { return FieldType.BYTES; } // serialize struct to bytes in toBaseType","handlingStrategy":"type-guard","validationCode":"FieldType rep = logicalType.getRepresentation(); if (!coderSafeRepresentation(rep)) throw new IllegalArgumentException(\"representation \" + rep + \" unsupported for coder-based logical type encoding\");","typeGuard":"boolean encodableRepresentation(FieldType rep) { switch (rep.getTypeName()) { case INT64: case DOUBLE: case STRING: case BYTES: return true; default: return false; } }","tryCatchPattern":"try { rowToProto(row); } catch (UnsupportedOperationException e) { if (e.getMessage().contains(\"Unsupported underlying type for producing LogicalType\")) { /* change representation to BYTES */ } else { throw e; } }","preventionTips":["Declare primitive (ideally BYTES) representations for custom logical types","Manually serialize structured representations into BYTES","Round-trip test custom logical types through SchemaTranslation","Prefer standard logical types with registered URNs"],"tags":["java","logical-type","unsupported-type","serialization"],"backgroundTag":"unsupported-operation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}