{"record":{"id":"52246901408b4ff4","repo":"apache/beam","slug":"input-should-be-array-map-numeric-or-row","errorCode":null,"errorMessage":"input should be array, map, numeric or row","messagePattern":"input should be array, map, numeric or row","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/transforms/Cast.java","lineNumber":443,"sourceCode":"          Object outputKey =\n              castValue(entry.getKey(), input.getMapKeyType(), output.getMapKeyType());\n          Object outputValue =\n              castValue(entry.getValue(), input.getMapValueType(), output.getMapValueType());\n\n          outputMap.put(outputKey, outputValue);\n        }\n\n        return outputMap;\n\n      default:\n        if (inputType.equals(outputType)) {\n          return inputValue;\n        }\n\n        if (inputType.isNumericType()) {\n          return castNumber((Number) inputValue, inputType, outputType);\n        } else {\n          throw new IllegalArgumentException(\"input should be array, map, numeric or row\");\n        }\n    }\n  }\n}\n","sourceCodeStart":425,"sourceCodeEnd":448,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/transforms/Cast.java#L425-L448","documentation":"Cast.castValue's switch handles ARRAY, MAP, ROW, and numeric input types; any other input type (e.g. STRING, BOOLEAN, DATETIME, primitive wrappers outside numeric) falls to the default and throws IllegalArgumentException because the default cast logic does not support it.","triggerScenarios":"Applying Cast.to(outputSchema) when a field has a scalar non-numeric input type such as STRING or BOOLEAN that the switch cannot dispatch on, even if the output type matches.","commonSituations":"Casting schemas containing string/boolean/datetime fields; users expecting Cast to be an arbitrary value converter when it only handles structural types and numbers.","solutions":["Handle non-numeric scalar fields with an explicit Map/MapElements transform instead of Cast.","Write a custom cast function: rows.apply(Cast.to(schema).withCastFunction(...)) or castRow with per-field functions.","Check which fields are non-numeric scalars via input.getSchema() and either drop or transform them before casting.","Upgrade Beam: support for more scalar types in castValue may have been added in later versions."],"exampleFix":"// before (STRING field hits default branch)\nrows.apply(Cast.to(outSchema));\n// after: transform string field explicitly first\nrows.apply(MapElements.into(TypeDescriptor.of(Row.class))\n    .via(r -> convertStringFields(r))).apply(Cast.to(outSchema));","handlingStrategy":"validation","validationCode":"for (Schema.Field f : inSchema.getFields()) {\n  TypeName t = f.getType().getTypeName();\n  boolean supported = EnumSet.of(TypeName.ARRAY, TypeName.MAP, TypeName.ROW).contains(t) || t.isNumericType();\n  if (!supported) throw new IllegalStateException(\"field not castable: \" + f.getName());\n}","typeGuard":"static boolean castableByDefault(Schema.Field f) {\n  TypeName t = f.getType().getTypeName();\n  return t == TypeName.ARRAY || t == TypeName.MAP || t == TypeName.ROW || t.isNumericType();\n}","tryCatchPattern":"try { rows.apply(Cast.to(outSchema)); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"array, map, numeric or row\")) { /* route field through MapElements */ } else throw e; }","preventionTips":["Inventory scalar non-numeric fields (STRING, BOOLEAN, DATETIME) before casting","Use withCastFunction for schemas containing such fields","Add a schema pre-flight check in pipeline construction tests"],"tags":["java","apache-beam","cast","unsupported-type"],"backgroundTag":"unsupported-operation","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"}