{"record":{"id":"20463d1d369d8de5","repo":"apache/beam","slug":"unable-to-convert-map-key-type","errorCode":null,"errorMessage":"unable to convert map key type","messagePattern":"unable to convert map key type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/graphx/schema/schema.go","lineNumber":778,"sourceCode":"\nfunc (r *Registry) fieldTypeToReflectType(sft *pipepb.FieldType, opts []*pipepb.Option) (reflect.Type, error) {\n\tvar t reflect.Type\n\tswitch sft.GetTypeInfo().(type) {\n\tcase *pipepb.FieldType_AtomicType:\n\t\tvar ok bool\n\t\tif t, ok = atomicTypeToReflectType[sft.GetAtomicType()]; !ok {\n\t\t\treturn nil, errors.Errorf(\"unknown atomic type: %v\", sft.GetAtomicType())\n\t\t}\n\tcase *pipepb.FieldType_ArrayType:\n\t\trt, err := r.fieldTypeToReflectType(sft.GetArrayType().GetElementType(), nil)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"unable to convert array element type\")\n\t\t}\n\t\tt = reflect.SliceOf(rt)\n\tcase *pipepb.FieldType_MapType:\n\t\tkt, err := r.fieldTypeToReflectType(sft.GetMapType().GetKeyType(), nil)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"unable to convert map key type\")\n\t\t}\n\t\tvt, err := r.fieldTypeToReflectType(sft.GetMapType().GetValueType(), nil)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"unable to convert map value type\")\n\t\t}\n\t\tt = reflect.MapOf(kt, vt) // Panics for invalid map keys (slices/iterables)\n\tcase *pipepb.FieldType_RowType:\n\t\trt, err := r.toType(sft.GetRowType().GetSchema())\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrapf(err, \"unable to convert row type: %v\", sft.GetRowType().GetSchema().GetId())\n\t\t}\n\t\tt = rt\n\t// case *pipepb.FieldType_IterableType:\n\t// TODO(BEAM-9615): handle IterableTypes (eg. CoGBK values)\n\n\tcase *pipepb.FieldType_LogicalType:\n\t\tlst := sft.GetLogicalType()\n\t\tidentifier := lst.GetUrn()","sourceCodeStart":760,"sourceCodeEnd":796,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/graphx/schema/schema.go#L760-L796","documentation":"Wrapper error raised when the key type of a MapType field fails conversion in Registry.fieldTypeToReflectType. Beam/Go require map keys to be comparable and schema-representable; if the key's FieldType cannot be turned into a reflect.Type, this error names the map context. Note the adjacent comment: reflect.MapOf panics for invalid keys (slices/iterables), so key failures should be caught here first.","triggerScenarios":"toType/fieldToStructField encountering a schema MapType whose KeyType fails fieldTypeToReflectType — e.g. key is an array type, logical type resolving to a slice, or unknown atomic.","commonSituations":"Schemas produced by other SDKs (Java/Python allow richer map key logical types) or hand-built schemas with non-convertible keys being loaded via ToType in Go.","solutions":["Inspect the wrapped error to find why the key type failed","Change the map key to a schema-supported comparable atomic (string, int, bool, bytes)","Register the key's logical type so it resolves to a comparable Go type","Restructure the schema to use a repeated row of {key,value} instead of a map when keys aren't convertible"],"exampleFix":"// before: map with array key\n// after: represent as list of pairs\nfields: [ {name: \"entries\", type: array<row{key: string, value: int64}>} ]","handlingStrategy":"validation","validationCode":"func mapKeysSchemaSafe(s *pipepb.Schema) error {\n  for _, f := range s.GetFields() {\n    if mt := f.GetType().GetMapType(); mt != nil {\n      if mt.GetKeyType().GetAtomicType() == pipepb.AtomicType_ATOMIC_TYPE_UNSPECIFIED {\n        return fmt.Errorf(\"map field %q key must be an atomic type\", f.GetName())\n      }\n    }\n  }\n  return nil\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"unable to convert map key type\") {\n  return fmt.Errorf(\"map key must be a comparable atomic: %w\", err)\n}","preventionTips":["Only use atomic (string/int/bool/bytes) map keys in schemas","Model complex keys as arrays of key/value rows instead of maps","Remember Go's reflect.MapOf panics on non-comparable keys — validate before conversion"],"tags":["go","apache-beam","schema","map"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}