{"record":{"id":"4380bc9908f92315","repo":"apache/beam","slug":"unexpected-beam-type-fieldschema","errorCode":null,"errorMessage":"Unexpected beam type \" + fieldSchema","messagePattern":"Unexpected beam type \" \\+ fieldSchema","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/AvroGenericRecordToStorageApiProto.java","lineNumber":575,"sourceCode":"\n      long picoseconds = nanoAdjustment * PICOS_PER_NANO;\n      return buildTimestampPicosMessage(\n          Preconditions.checkNotNull(descriptor).getMessageType(), seconds, picoseconds);\n    }\n    LogicalType logicalType = LogicalTypes.fromSchema(type.getType());\n\n    if (logicalType != null) {\n      @Nullable\n      BiFunction<LogicalType, Object, Object> logicalTypeEncoder =\n          LOGICAL_TYPE_ENCODERS.get(logicalType.getName());\n      if (logicalTypeEncoder == null) {\n        throw new IllegalArgumentException(\"Unsupported logical type \" + logicalType.getName());\n      }\n      return logicalTypeEncoder.apply(logicalType, value);\n    } else {\n      @Nullable Function<Object, Object> encoder = PRIMITIVE_ENCODERS.get(type.getType().getType());\n      if (encoder == null) {\n        throw new RuntimeException(\"Unexpected beam type \" + fieldSchema);\n      }\n      return encoder.apply(value);\n    }\n  }\n}\n","sourceCodeStart":557,"sourceCodeEnd":581,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/AvroGenericRecordToStorageApiProto.java#L557-L581","documentation":"scalarToProtoValue falls back to PRIMITIVE_ENCODERS keyed by the Avro primitive type when no logical type is present. If the Avro type has no registered primitive encoder, it throws RuntimeException(\"Unexpected beam type ...\"). This means the field's Avro type is one the BigQuery Storage API conversion doesn't handle (e.g. BYTES/NULL/FIXED in some positions).","triggerScenarios":"Converting an Avro field whose primitive type isn't in PRIMITIVE_ENCODERS (e.g. FIXED, NULL-typed union branches resolved oddly) when writing GenericRecords to BigQuery Storage API","commonSituations":"Schemas using Avro FIXED types, fields typed NULL, or schema/type drift between data and declared table schema.","solutions":["Change the field's Avro type to a supported primitive (STRING, LONG, DOUBLE, BOOLEAN, BYTES where supported)","Inspect the logged fieldSchema to identify the offending type and align your schema with the BigQuery column type","Convert FIXED to BYTES or STRING before writing","Upgrade Beam for newer type support"],"exampleFix":"// before\nSchema fixed = Schema.createFixed(\"Md5\", null, null, 16);\n// after\nSchema fixed = Schema.create(Schema.Type.BYTES);","handlingStrategy":"validation","validationCode":"// Java\nSet<Schema.Type> supported = Set.of(STRING, LONG, DOUBLE, BOOLEAN, BYTES, INT);\nif (!supported.contains(avroType.getType())) {\n  throw new IllegalStateException(\"Unsupported Avro primitive: \" + avroType.getType());\n}","typeGuard":"// Java\nFunction<Object, Object> enc = PRIMITIVE_ENCODERS.get(type.getType().getType());\nif (enc != null) { /* encodable */ }","tryCatchPattern":"// Java\ntry {\n  return scalarToProtoValue(fieldSchema, type, value);\n} catch (RuntimeException e) {\n  if (e.getMessage().startsWith(\"Unexpected beam type\")) {\n    // convert the field to a supported primitive upstream\n  }\n  throw e;\n}","preventionTips":["Avoid Avro FIXED and NULL-only types in BigQuery sink schemas","Map unsupported primitives (e.g. FIXED) to BYTES/STRING upstream","Keep your Avro schema and BigQuery table schema aligned"],"tags":["java","bigquery","avro","type-mismatch"],"backgroundTag":"type-mismatch","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"}