{"record":{"id":"07befe67c60aef34","repo":"apache/beam","slug":"failed-to-extract-logical-type","errorCode":null,"errorMessage":"Failed to extract logical type","messagePattern":"Failed to extract logical type","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/singlestore/src/main/java/org/apache/beam/sdk/io/singlestore/SingleStoreDefaultUserDataMapper.java","lineNumber":49,"sourceCode":"\n/**\n * UserDataMapper that maps {@link Row} objects. ARRAYs, ITTERABLEs, MAPs and nested ROWs are not\n * supported.\n */\nfinal class SingleStoreDefaultUserDataMapper implements SingleStoreIO.UserDataMapper<Row> {\n\n  private final transient DateTimeFormatter formatter =\n      DateTimeFormat.forPattern(\"yyyy-MM-DD' 'HH:mm:ss.SSS\");\n\n  private String convertLogicalTypeFieldToString(Schema.FieldType type, Object value) {\n    checkArgument(\n        type.getTypeName().isLogicalType(),\n        \"convertLogicalTypeFieldToString accepts only logical types\");\n\n    Schema.LogicalType<Object, Object> logicalType =\n        (Schema.LogicalType<Object, Object>) type.getLogicalType();\n    if (logicalType == null) {\n      throw new UnsupportedOperationException(\"Failed to extract logical type\");\n    }\n\n    Schema.FieldType baseType = logicalType.getBaseType();\n    Object baseValue = logicalType.toBaseType(value);\n    return convertFieldToString(baseType, baseValue);\n  }\n\n  private String convertFieldToString(Schema.FieldType type, Object value) {\n    switch (type.getTypeName()) {\n      case BYTE:\n        return ((Byte) value).toString();\n      case INT16:\n        return ((Short) value).toString();\n      case INT32:\n        return ((Integer) value).toString();\n      case INT64:\n        return ((Long) value).toString();\n      case DECIMAL:","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/singlestore/src/main/java/org/apache/beam/sdk/io/singlestore/SingleStoreDefaultUserDataMapper.java#L31-L67","documentation":"convertLogicalTypeFieldToString() asserts the field type is a logical type, then extracts the Schema.LogicalType via type.getLogicalType(). If the cast/lookup yields null, an internal invariant was violated (type claims to be logical but carries no LogicalType instance), so it throws UnsupportedOperationException(\"Failed to extract logical type\").","triggerScenarios":"A Beam Schema.FieldType with isLogicalType()==true but getLogicalType() returning null is passed to convertFieldToString on a LOGICAL_TYPE field while mapping rows for a SingleStoreIO write with the default UserDataMapper.","commonSituations":"Custom logical types whose getLogicalType() implementation returns null; Beam version incompatibilities where logical type metadata is dropped during schema serialization; constructing FieldType programmatically with a null logical type argument.","solutions":["Fix the schema so logical fields carry a real LogicalType instance (verify the FieldType construction)","Avoid custom logical types: convert the value to its base type in your PTransform before writing","Provide a custom UserDataMapper that handles the field without relying on getLogicalType()","Check Beam version for known logical-type metadata bugs and upgrade"],"exampleFix":"// before\nFieldType ft = FieldType.logicalType(null); // invalid, getLogicalType()==null\n// after\nFieldType ft = FieldType.logicalType(MyInstantLogicalType.INSTANCE); // real LogicalType","handlingStrategy":"type-guard","validationCode":"if (type.isLogicalType() && type.getLogicalType() == null) { throw new IllegalArgumentException(\"FieldType claims logical type but getLogicalType() is null\"); }","typeGuard":"boolean hasLogicalType(Schema.FieldType t) { return t.isLogicalType() && t.getLogicalType() != null; }","tryCatchPattern":"try { mapper.mapRow(row); } catch (UnsupportedOperationException e) { if (e.getMessage().equals(\"Failed to extract logical type\")) { /* fall back to base-type conversion */ } throw e; }","preventionTips":["Construct logical FieldTypes only via FieldType.logicalType(nonNullInstance)","Unit-test custom LogicalTypes to ensure getLogicalType() survives schema round-trips","Prefer converting to base types in your transform before the sink"],"tags":["java","beam","schema","logical-type"],"backgroundTag":"internal-invariant-violation","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"}