apache/beam · error · IllegalArgumentException
'${fieldName}' field is invalid at the top level for Kafka i
Error message
'${fieldName}' field is invalid at the top level for Kafka in the nested schema. What it means
Thrown by Schemas.validateNestedSchema when a field of a Kafka table's nested schema has a top-level name that is not one of the recognized Kafka schema fields (e.g. 'key', 'value', 'timestamp', 'headers'). The switch over field names has a default branch that rejects unknown fields with IllegalArgumentException.
Source
Thrown at sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/meta/provider/kafka/Schemas.java:100
case HEADERS_FIELD:
checkFieldHasType(field, HEADERS_FIELD_TYPE);
break;
case EVENT_TIMESTAMP_FIELD:
checkFieldHasType(field, FieldType.DATETIME);
break;
case MESSAGE_KEY_FIELD:
checkFieldHasType(field, FieldType.BYTES);
break;
case PAYLOAD_FIELD:
checkArgument(
fieldHasType(field, FieldType.BYTES)
|| field.getType().getTypeName().equals(TypeName.ROW),
String.format(
"'%s' field must either have a 'BYTES NOT NULL' or 'ROW' schema.",
field.getName()));
break;
default:
throw new IllegalArgumentException(
String.format(
"'%s' field is invalid at the top level for Kafka in the nested schema.",
field.getName()));
}
}
}
}
View on GitHub (pinned to 12126d8942)
Solutions
- Use only the supported top-level Kafka fields (key, value, timestamp, headers, event_timestamp etc.) in the nested schema.
- Move custom columns into a ROW-typed 'value' field instead of declaring them at the top level.
- Fix spelling/case of the field names and mark key/value as BYTES NOT NULL or ROW as required by validateNestedSchema.
Example fix
// before CREATE EXTERNAL TABLE t (payload BYTES NOT NULL, `timestamp` TIMESTAMP) TYPE 'kafka' // after CREATE EXTERNAL TABLE t (value BYTES NOT NULL, `timestamp` TIMESTAMP) TYPE 'kafka'
Defensive patterns
Strategy: validation
Validate before calling
Set<String> topLevel = Set.of("key", "value", "headers", "timestamp");
for (Field f : schema.getFields()) {
if (!topLevel.contains(f.getName())) throw new IllegalArgumentException("Invalid top-level field: " + f.getName());
} Try / catch
try { validateNestedSchema(schema); } catch (IllegalArgumentException e) { /* fix schema or fall back to key/value BYTES schema */ } Prevention
- Nest custom columns under a ROW-typed 'value' field
- Validate the schema string before executing the DDL
- Reference a working example schema
When it happens
Trigger: Declaring a Kafka external table whose schema contains a top-level field not in the supported set — e.g. adding a field 'payload' or misspelling 'value' as 'values' in a nested Kafka schema definition.
Common situations: Misspelling the reserved field names; attempting to add custom top-level columns that must instead be nested inside a ROW-typed 'value' field; copying a schema from a different provider whose field naming differs.
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
- Unable to convert logical type ${identifier}
- Unable to convert ${typeName}
- Unable to find value #${index}
- Unable to get ${typeName}
- Unknown watermark type: ${type}. Supported types are Process
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/8d3f66c10b51c9de.
Report an issue: GitHub.