{"record":{"id":"d544f4316f559e9e","repo":"vectordotdev/vector","slug":"invalid-map-schema-for-field-field-name-reas","errorCode":null,"errorMessage":"Invalid Map schema for field '{field_name}': {reason}","messagePattern":"Invalid Map schema for field '(.+?)': (.+?)","errorType":"error_code","errorClass":"ArrowEncodingError::InvalidMapSchema","httpStatus":null,"severity":"error","filePath":"lib/codecs/src/encoding/format/arrow.rs","lineNumber":256,"sourceCode":"        DataType::List(inner_field) => DataType::List(make_field_nullable(inner_field)?.into()),\n        DataType::Struct(fields) => DataType::Struct(\n            fields\n                .iter()\n                .map(|f| make_field_nullable(f))\n                .collect::<Result<Vec<_>, _>>()?\n                .into(),\n        ),\n        DataType::Map(inner, sorted) => {\n            // A Map's inner field is a \"entries\" Struct<Key, Value>\n            let DataType::Struct(fields) = inner.data_type() else {\n                return InvalidMapSchemaSnafu {\n                    field_name: field.name(),\n                    reason: format!(\"inner type must be Struct, found {:?}\", inner.data_type()),\n                }\n                .fail();\n            };\n\n            ensure!(\n                fields.len() == 2,\n                InvalidMapSchemaSnafu {\n                    field_name: field.name(),\n                    reason: format!(\"expected 2 fields (key, value), found {}\", fields.len()),\n                },\n            );\n            let key_field = &fields[0];\n            let value_field = &fields[1];\n\n            let new_struct_fields: Fields =\n                [key_field.clone(), make_field_nullable(value_field)?.into()].into();\n\n            // Reconstruct the inner \"entries\" field\n            // The inner field itself must be non-nullable (only the Map wrapper is nullable)\n            let new_inner_field = inner\n                .as_ref()\n                .clone()\n                .with_data_type(DataType::Struct(new_struct_fields))","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/codecs/src/encoding/format/arrow.rs#L238-L274","documentation":"The Arrow encoder validates that a Map-typed field follows the Arrow Map schema: a struct with exactly two child fields (key, value). This error is thrown by make_field_nullable when a Map field's inner struct does not have exactly two fields. Such a schema cannot be mapped to Arrow's Map type.","triggerScenarios":"Building an Arrow schema from events where a field's inferred type is Map whose inner struct has fewer or more than 2 child fields (e.g. only a key, or key+value+extra metadata); passing a hand-built DataType::Map with a malformed inner Struct.","commonSituations":"Encoding events with map values of inconsistent shape; schema inference over heterogeneous events; custom Arrow DataType construction with a legacy or non-standard map layout.","solutions":["Ensure the map's inner Struct contains exactly the two fields 'key' and 'value'.","Normalize/rewrite malformed map fields before feeding them to the encoder.","If the inner type is not a Struct at all, fix the source type first (this is a separate branch of the same validation)."],"exampleFix":"// before\nDataType::Map(inner_struct_with_3_fields.into())\n// after\nDataType::Map(Arc::new(Struct::new(\n    Some(\"entries\".into()),\n    vec![\n        Field::new(\"key\", DataType::Utf8, false),\n        Field::new(\"value\", DataType::Utf8, true),\n    ],\n)))","handlingStrategy":"validation","validationCode":"fn is_valid_arrow_map(dt: &DataType) -> bool {\n    if let DataType::Map(entries, _) = dt {\n        if let DataType::Struct(fields) = entries.data_type() {\n            return fields.len() == 2;\n        }\n    }\n    false\n}","typeGuard":"fn is_arrow_map_type(field: &Field) -> bool {\n    matches!(field.data_type(), DataType::Map(_, _))\n}","tryCatchPattern":"match schema_generator.infer_schema(&events) {\n    Ok(schema) => schema,\n    Err(e) if e.to_string().contains(\"Invalid Map schema\") => {\n        // normalize map fields and retry\n        todo!(\"normalize\")\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always construct Arrow Map types via the standard key/value struct layout.","Validate inferred schemas against the Arrow spec before encoding.","Test with representative heterogeneous event batches."],"tags":["arrow","schema","encoding"],"backgroundTag":"schema-validation-failed","analyzedSha":"bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}