{"record":{"id":"379e739af7548927","repo":"apache/beam","slug":"unexpected-field-type","errorCode":null,"errorMessage":"Unexpected field type","messagePattern":"Unexpected field type","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/transforms/AddFields.java","lineNumber":417,"sourceCode":"\n        case MAP:\n          if (original == null) {\n            return Collections.emptyMap();\n          }\n          Map<Object, Object> originalMap = (Map<Object, Object>) original;\n          Map<Object, Object> filledMap = Maps.newHashMapWithExpectedSize(originalMap.size());\n          Schema.FieldType mapValueType = fieldType.getMapValueType();\n          AddFieldsInformation mapValueAddFieldInformation =\n              addFieldsInformation.toBuilder().setOutputFieldType(mapValueType).build();\n          for (Map.Entry<Object, Object> entry : originalMap.entrySet()) {\n            filledMap.put(\n                entry.getKey(),\n                fillNewFields(entry.getValue(), mapValueType, mapValueAddFieldInformation));\n          }\n          return filledMap;\n\n        default:\n          throw new RuntimeException(\"Unexpected field type\");\n      }\n    }\n\n    @Override\n    public PCollection<Row> expand(PCollection<T> input) {\n      final AddFieldsInformation addFieldsInformation =\n          getAddFieldsInformation(input.getSchema(), newFields);\n      Schema outputSchema = checkNotNull(addFieldsInformation.getOutputFieldType().getRowSchema());\n\n      return input\n          .apply(\n              ParDo.of(\n                  new DoFn<T, Row>() {\n                    @ProcessElement\n                    public void processElement(@Element Row row, OutputReceiver<Row> o) {\n                      o.output(fillNewFields(row, addFieldsInformation));\n                    }\n                  }))","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/transforms/AddFields.java#L399-L435","documentation":"AddFields.fillNewFields rebuilds each Row value while inserting the new field. Its switch over the field type has a default branch that throws 'Unexpected field type' because only ARRAY, ITERABLE, MAP, and ROW values can contain nested fields; any other type reaching this recursion is a bug or invalid configuration.","triggerScenarios":"The AddFieldsInformation's resolved target type is not one of ARRAY/ITERABLE/MAP/ROW when fillNewFields is invoked (e.g. from newValue or recursively from fillNewFields), typically because the field path or declared new-field type mismatches the actual schema structure.","commonSituations":"Declaring AddFields.field(\"a.b\", type) where 'a' resolves to a scalar in the resolved schema; internal inconsistency between getAddFieldsInformation's computed type and the actual row values, often after schema evolution or with custom SchemaCoder setups.","solutions":["Check that the parent of the field path is a composite type (ROW, MAP, ARRAY) in the input schema.","Ensure the FieldType passed to AddFields matches the schema; re-derive the schema after upstream transforms.","If the target is a scalar field, add the field at that level instead of descending.","If it appears despite a correct path, file/inspect against Beam version — this is an internal invariant default branch and may indicate a Beam bug."],"exampleFix":"// before\nrows.apply(AddFields.<Row>field(\"scalarField.inner\", FieldType.STRING));\n// after\nrows.apply(AddFields.<Row>field(\"rowField.inner\", FieldType.STRING));","handlingStrategy":"validation","validationCode":"Schema.Field parent = input.getSchema().getField(\"rowField\");\nif (parent.getType().getTypeName() != TypeName.ROW) {\n  throw new IllegalStateException(\"fillNewFields expects ROW/MAP/ARRAY parent\");\n}","typeGuard":"static boolean supportsNestedAdd(Schema.Field f) {\n  switch (f.getType().getTypeName()) {\n    case ROW: case MAP: case ARRAY: case ITERABLE: return true;\n    default: return false;\n  }\n}","tryCatchPattern":"try { out = pc.apply(addFields); } catch (RuntimeException e) { if (e.getMessage().equals(\"Unexpected field type\")) { /* inspect schema/path mismatch */ } else throw e; }","preventionTips":["Ensure the dotted path's parent is a composite type","Keep declared AddFields FieldType consistent with the schema","Pin and test Beam version — this default branch often signals a Beam internal bug"],"tags":["java","apache-beam","schemas","row-processing"],"backgroundTag":"internal-invariant-violation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}