{"record":{"id":"b1f265d5a3dad5b4","repo":"apache/beam","slug":"received-an-empty-map-but-output-schema-contains-required","errorCode":null,"errorMessage":"Received an empty Map, but output schema contains required fields: %s","messagePattern":"Received an empty Map, but output schema contains required fields: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/YamlUtils.java","lineNumber":164,"sourceCode":"    }\n\n    throw new UnsupportedOperationException(\n        String.format(\n            \"Converting YAML type '%s' to '%s' is not supported\", yamlValue.getClass(), fieldType));\n  }\n\n  @SuppressWarnings(\"nullness\")\n  public static Row toBeamRow(\n      @Nullable Map<String, Object> map, Schema rowSchema, boolean toCamelCase) {\n    if (map == null || map.isEmpty()) {\n      List<Field> requiredFields =\n          rowSchema.getFields().stream()\n              .filter(field -> !field.getType().getNullable())\n              .collect(Collectors.toList());\n      if (requiredFields.isEmpty()) {\n        return Row.nullRow(rowSchema);\n      } else {\n        throw new IllegalArgumentException(\n            String.format(\n                \"Received an empty Map, but output schema contains required fields: %s\",\n                requiredFields));\n      }\n    }\n    return rowSchema.getFields().stream()\n        .map(\n            field ->\n                toBeamValue(\n                    field, map.get(maybeGetSnakeCase(field.getName(), toCamelCase)), toCamelCase))\n        .collect(toRow(rowSchema));\n  }\n\n  private static String maybeGetSnakeCase(String str, boolean getSnakeCase) {\n    return getSnakeCase ? CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, str) : str;\n  }\n\n  public static String yamlStringFromMap(@Nullable Map<String, Object> map) {","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/YamlUtils.java#L146-L182","documentation":"toBeamRow's map overload converts an empty Map<String,Object> to Row.nullRow only if all schema fields are nullable. When the schema has any non-nullable (required) fields, an empty map cannot satisfy them, so this IllegalArgumentException is thrown listing the required fields.","triggerScenarios":"Calling YamlUtils.toBeamRow(new HashMap<>(), rowSchema, ...) (directly, or from toBeamValue when a nested YAML mapping is empty) while rowSchema contains at least one required field.","commonSituations":"Nested YAML objects present but empty (`metadata:` with no children parsed as empty map), or top-level empty YAML documents loaded as empty maps, against schemas with required fields.","solutions":["Populate the map with values for all required fields before conversion.","Make the schema fields nullable if empty objects are legitimate input.","Treat empty maps as missing data and skip/default them before calling toBeamRow.","Fix upstream parsing so empty YAML sections produce a map containing required keys or are dropped."],"exampleFix":"// before\nRow row = YamlUtils.toBeamRow(new HashMap<>(), schema, true); // schema has required fields\n// after\nMap<String, Object> map = new HashMap<>();\nmap.put(\"name\", \"default\");\nRow row = YamlUtils.toBeamRow(map, schema, true);","handlingStrategy":"validation","validationCode":"if (map.isEmpty()) {\n  List<String> required = rowSchema.getFields().stream()\n      .filter(f -> !f.getType().getNullable())\n      .map(Schema.Field::getName)\n      .collect(Collectors.toList());\n  if (!required.isEmpty()) throw new IllegalArgumentException(\"Empty map, required: \" + required);\n}","typeGuard":"boolean canBeEmptyMap(Schema schema) {\n  return schema.getFields().stream().allMatch(f -> f.getType().getNullable());\n}","tryCatchPattern":"try {\n  return YamlUtils.toBeamRow(map, rowSchema, convertNames);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"empty Map\")) {\n    return Row.nullRow(rowSchema); // only valid if all fields nullable\n  }\n  throw e;\n}","preventionTips":["Check maps for emptiness before conversion","Drop empty nested YAML sections instead of converting them","Keep required fields minimal; prefer nullable schema fields"],"tags":["java","yaml","schema","validation"],"backgroundTag":"empty-required-field","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"}