apache/beam · error · IllegalArgumentException

Schema must contain at least one field. Schema

Error message

Schema must contain at least one field. Schema: %s

What it means

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.

Solutions

  1. Add at least one field to the input schema before applying PubsubRowToMessage.
  2. Check that the schema source (Avro/JSON schema string, Schema.builder()) actually produced fields.
  3. Ensure no upstream transform is stripping all fields from the PCollection's schema.

Example fix

// before
Schema schema = Schema.builder().build(); // 0 fields
// after
Schema schema = Schema.builder().addStringField("payload").build();
Defensive patterns

Strategy: validation

Validate before calling

if (input.getSchema().getFieldCount() == 0) { throw new IllegalArgumentException("Input schema has no fields; add at least one before PubsubRowToMessage"); }

Try / catch

try { rowToMessage.expand(input); } catch (IllegalArgumentException e) { if (e.getMessage().contains("at least one field")) { /* rebuild schema with fields */ } throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/ac939c583bd96e80. Report an issue: GitHub.

Appendix: source

Thrown at sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PubsubRowToMessage.java:178

  String getAttributesKeyName() {
    return getKeyPrefix() + ATTRIBUTES_KEY_NAME;
  }

  /** Returns the name of the source timestamp key, prefixed with {@link #getKeyPrefix()}. */
  String getSourceEventTimestampKeyName() {
    return getKeyPrefix() + EVENT_TIMESTAMP_KEY_NAME;
  }

  /** Returns the name of the source payload key, prefixed with {@link #getKeyPrefix()}. */
  String getPayloadKeyName() {
    return getKeyPrefix() + PAYLOAD_KEY_NAME;
  }

  /** Validates an input's {@link Schema} for correctness. */
  void validate(Schema schema) {

    if (schema.getFieldCount() == 0) {
      throw new IllegalArgumentException(
          String.format("Schema must contain at least one field. Schema: %s", schema));
    }

    validateAttributesField(schema);
    validateSourceEventTimeStampField(schema);
    validateSerializableFields(schema);
  }

  /**
   * Validates an input's {@link Schema} for its {@link #getAttributesKeyName()} field correctness,
   * if exists.
   */
  void validateAttributesField(Schema schema) {
    String attributesKeyName = getAttributesKeyName();
    if (!schema.hasField(attributesKeyName)) {
      return;
    }
    checkArgument(

View on GitHub (pinned to 12126d8942)