{"record":{"id":"ac939c583bd96e80","repo":"apache/beam","slug":"schema-must-contain-at-least-one-field-schema-s","errorCode":null,"errorMessage":"Schema must contain at least one field. Schema: %s","messagePattern":"Schema must contain at least one field\\. Schema: (.+?)","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/PubsubRowToMessage.java","lineNumber":178,"sourceCode":"  String getAttributesKeyName() {\n    return getKeyPrefix() + ATTRIBUTES_KEY_NAME;\n  }\n\n  /** Returns the name of the source timestamp key, prefixed with {@link #getKeyPrefix()}. */\n  String getSourceEventTimestampKeyName() {\n    return getKeyPrefix() + EVENT_TIMESTAMP_KEY_NAME;\n  }\n\n  /** Returns the name of the source payload key, prefixed with {@link #getKeyPrefix()}. */\n  String getPayloadKeyName() {\n    return getKeyPrefix() + PAYLOAD_KEY_NAME;\n  }\n\n  /** Validates an input's {@link Schema} for correctness. */\n  void validate(Schema schema) {\n\n    if (schema.getFieldCount() == 0) {\n      throw new IllegalArgumentException(\n          String.format(\"Schema must contain at least one field. Schema: %s\", schema));\n    }\n\n    validateAttributesField(schema);\n    validateSourceEventTimeStampField(schema);\n    validateSerializableFields(schema);\n  }\n\n  /**\n   * Validates an input's {@link Schema} for its {@link #getAttributesKeyName()} field correctness,\n   * if exists.\n   */\n  void validateAttributesField(Schema schema) {\n    String attributesKeyName = getAttributesKeyName();\n    if (!schema.hasField(attributesKeyName)) {\n      return;\n    }\n    checkArgument(","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PubsubRowToMessage.java#L160-L196","documentation":"PubsubRowToMessage.validate() requires the input Beam Schema to contain at least one field. A zero-field schema cannot be converted into a Pubsub message, so validation throws an IllegalArgumentException including the offending schema.","triggerScenarios":"Applying PubsubRowToMessage (via expand()) with an input PCollection whose Schema has getFieldCount() == 0 — e.g. an empty schema was parsed or a Row collection with no fields was piped in.","commonSituations":"Building the schema programmatically and forgetting to add fields; parsing an empty or malformed Avro/JSON schema that yields zero fields; upstream transforms that drop all columns.","solutions":["Add at least one field to the input schema before applying PubsubRowToMessage.","Check that the schema source (Avro/JSON schema string, Schema.builder()) actually produced fields.","Ensure no upstream transform is stripping all fields from the PCollection's schema."],"exampleFix":"// before\nSchema schema = Schema.builder().build(); // 0 fields\n// after\nSchema schema = Schema.builder().addStringField(\"payload\").build();","handlingStrategy":"validation","validationCode":"if (input.getSchema().getFieldCount() == 0) { throw new IllegalArgumentException(\"Input schema has no fields; add at least one before PubsubRowToMessage\"); }","typeGuard":null,"tryCatchPattern":"try { rowToMessage.expand(input); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"at least one field\")) { /* rebuild schema with fields */ } throw e; }","preventionTips":["After building any Schema programmatically, assert getFieldCount() > 0 before use.","Validate parsed Avro/JSON schemas actually produced fields."],"tags":["java","apache-beam","pubsub","schema"],"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-14T16:17:12.679Z"}