{"record":{"id":"d65f4f03852fb791","repo":"apache/beam","slug":"raw-output-only-supported-for-single-field-schemas-got-s","errorCode":null,"errorMessage":"Raw output only supported for single-field schemas, got %s","messagePattern":"Raw output only supported for single-field schemas, got (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PubsubWriteSchemaTransformProvider.java","lineNumber":191,"sourceCode":"      List<String> attributes = configuration.getAttributes();\n      String attributesMap = configuration.getAttributesMap();\n      if (attributes == null && attributesMap == null) {\n        payloadSchema = beamSchema;\n      } else {\n        Schema.Builder payloadSchemaBuilder = Schema.builder();\n        for (Schema.Field f : beamSchema.getFields()) {\n          boolean isAttribute = attributes != null && attributes.contains(f.getName());\n          boolean isAttributesMap = f.getName().equals(attributesMap);\n          if (!isAttribute && !isAttributesMap) {\n            payloadSchemaBuilder.addField(f);\n          }\n        }\n        payloadSchema = payloadSchemaBuilder.build();\n      }\n      SerializableFunction<Row, byte[]> fn;\n      if (Objects.equals(format, \"RAW\")) {\n        if (payloadSchema.getFieldCount() != 1) {\n          throw new IllegalArgumentException(\n              String.format(\n                  \"Raw output only supported for single-field schemas, got %s\", payloadSchema));\n        }\n        if (payloadSchema.getField(0).getType().equals(Schema.FieldType.BYTES)) {\n          fn = row -> checkArgumentNotNull(row.getBytes(0), \"Payload bytes value cannot be null\");\n        } else if (payloadSchema.getField(0).getType().equals(Schema.FieldType.STRING)) {\n          fn =\n              row ->\n                  checkArgumentNotNull(row.getString(0), \"Payload string value cannot be null\")\n                      .getBytes(StandardCharsets.UTF_8);\n        } else {\n          throw new IllegalArgumentException(\n              String.format(\n                  \"Raw output only supports bytes and string fields, got %s\",\n                  payloadSchema.getField(0)));\n        }\n      } else if (Objects.equals(format, \"JSON\")) {\n        fn = JsonUtils.getRowToJsonBytesFunction(payloadSchema);","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PubsubWriteSchemaTransformProvider.java#L173-L209","documentation":"PubsubWriteSchemaTransform.expand throws IllegalArgumentException when format is RAW but the payload schema does not have exactly one field. RAW mode serializes a single bytes/string field directly as the message payload, so multi-field (or zero-field) schemas cannot be published raw. The message includes the offending schema.","triggerScenarios":"Configuring format=RAW with a schema having multiple columns (e.g. {id: INT64, payload: BYTES}) or an empty schema, typically from an inferred table schema in Beam YAML/SQL.","commonSituations":"Passing a full row schema from a database read straight into a RAW Pubsub sink; schema changed to add a column, breaking a previously working RAW sink.","solutions":["Use format=JSON (or AVRO) for multi-field schemas instead of RAW.","If RAW is required, project exactly one bytes/string field upstream (e.g. Select or SqlTransform selecting only the payload column).","Verify payloadSchema.getFieldCount() == 1 in your pipeline construction before applying the transform."],"exampleFix":"// before\ntransform = PubsubWriteSchemaTransformProvider...\n  .from(config.toBuilder().setFormat(\"RAW\").build()); // schema has 2 fields\n// after\nrow.apply(Select.fieldNames(\"payload\")) // keep single field\n   .apply(pubsubWrite.withFormat(\"RAW\"));\n// or switch:\n.from(config.toBuilder().setFormat(\"JSON\").build());","handlingStrategy":"validation","validationCode":"if (\"RAW\".equals(format) && payloadSchema.getFieldCount() != 1) throw new IllegalArgumentException(\"RAW requires exactly one field, got \" + payloadSchema.getFieldCount());","typeGuard":"null","tryCatchPattern":"try { expand(input); } catch (IllegalArgumentException e) { /* switch to JSON or project a single field */ }","preventionTips":["Only pair RAW with explicitly declared single-field schemas.","Project/Select the payload column before the sink.","Add a schema check step in pipeline construction for RAW sinks."],"tags":["java","pubsub","schema","beam-yaml"],"backgroundTag":"schema-validation-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}