{"record":{"id":"1b7422c6934fa687","repo":"prestodb/presto","slug":"type-must-be-a-maptype-for-mapvector","errorCode":null,"errorMessage":"Type must be a MapType for MapVector","messagePattern":"Type must be a MapType for MapVector","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common-arrow/src/main/java/com/facebook/plugin/arrow/ArrowBlockBuilder.java","lineNumber":724,"sourceCode":"            throw new IllegalArgumentException(\"Expected TimestampType but got \" + type.getClass().getName());\n        }\n\n        for (int i = startIndex; i < endIndex; i++) {\n            if (vector.isNull(i)) {\n                builder.appendNull();\n            }\n            else {\n                long micros = vector.get(i);\n                long millis = TimeUnit.MICROSECONDS.toMillis(micros);\n                type.writeLong(builder, millis);\n            }\n        }\n    }\n\n    public void assignBlockFromMapVector(MapVector vector, Type type, BlockBuilder builder, int startIndex, int endIndex)\n    {\n        if (!(type instanceof MapType)) {\n            throw new IllegalArgumentException(\"Type must be a MapType for MapVector\");\n        }\n\n        MapType mapType = (MapType) type;\n        StructVector entryVector = (StructVector) vector.getDataVector();\n        ValueVector keyVector = entryVector.getChildByOrdinal(0);\n        ValueVector valueVector = entryVector.getChildByOrdinal(1);\n\n        for (int i = startIndex; i < endIndex; i++) {\n            if (vector.isNull(i)) {\n                builder.appendNull();\n            }\n            else {\n                BlockBuilder entryBuilder = builder.beginBlockEntry();\n                int entryStart = vector.getElementStartIndex(i);\n                int entryEnd = vector.getElementEndIndex(i);\n                for (int entryIndex = entryStart; entryIndex < entryEnd; entryIndex++) {\n                    assignBlockFromValueVector(keyVector, mapType.getKeyType(), entryBuilder, entryIndex, entryIndex + 1);\n                    assignBlockFromValueVector(valueVector, mapType.getValueType(), entryBuilder, entryIndex, entryIndex + 1);","sourceCodeStart":706,"sourceCodeEnd":742,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common-arrow/src/main/java/com/facebook/plugin/arrow/ArrowBlockBuilder.java#L706-L742","documentation":"assignBlockFromMapVector converts an Arrow MapVector into a Presto map block. It requires the Presto Type to be MapType because it needs the map's key/value types to build BlockMapGetter-style accessors and recursively convert entries. A non-MapType makes this impossible, so it throws this IllegalArgumentException.","triggerScenarios":"Calling assignBlockFromMapVector (directly or via assignBlockFromValueVector) with a non-MapType, e.g. an ARRAY or ROW column type paired with a MapVector, or a scalar type.","commonSituations":"Arrow producer encodes a column as MAP while the Presto table declares it as array(row) or json; schema mismatch after producer-side type change; column-index misalignment in the dispatch switch.","solutions":["Declare the Presto column as a map of matching key/value types (MapType)","Fix the Type supplied in the assignBlockFromValueVector dispatch so the MapVector gets its own MapType","Verify the Arrow child field (keys/values) types match the Presto map's key/value types"],"exampleFix":"// before\nassignBlockFromMapVector(mapVector, ArrayType.from(rowType), builder, start, end);\n// after\nassignBlockFromMapVector(mapVector, MapType.from(keyType, valueType), builder, start, end);","handlingStrategy":"type-guard","validationCode":"if (!(columnType instanceof MapType)) {\n    throw new IllegalStateException(\"Column '\" + name + \"' must be MapType to receive MapVector, got \" + columnType);\n}","typeGuard":"boolean isMapColumn(Type type) {\n    return type instanceof MapType;\n}","tryCatchPattern":"try {\n    builder.assignBlockFromMapVector(vector, type, blockBuilder, start, end);\n} catch (IllegalArgumentException e) {\n    if (!e.getMessage().contains(\"MapType for MapVector\")) throw e;\n    // coerce (e.g. array(row) -> map) or fail with context\n}","preventionTips":["Map Arrow MAP fields to map(k,v) Presto types, not array(row)","Verify MapVector child (key/value) types match the declared MapType","Keep Arrow-schema-derived metadata as the single source of truth"],"tags":["arrow","type-mismatch","map"],"backgroundTag":"arrow-vector-type-mismatch","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}