{"record":{"id":"0142b9efc49f2953","repo":"apache/cassandra","slug":"cannot-create-index-on-s-of-column-s-with-non-ma","errorCode":null,"errorMessage":"Cannot create index on %s of column %s with non-map type","messagePattern":"Cannot create index on (.+?) of column (.+?) with non-map type","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateIndexStatement.java","lineNumber":307,"sourceCode":"            throw ire(ONLY_PARTITION_KEY, column);\n\n        if (target.type == Type.FULL && isNonSAIIndex && (!baseType.isCollection() || column.type.isMultiCell()))\n            throw ire(FULL_ON_FROZEN_COLLECTIONS);\n\n        if (!baseType.isCollection() && target.type != Type.SIMPLE)\n            throw ire(NON_COLLECTION_SIMPLE_INDEX, target.type, column);\n\n        // Frozen collections are only supported with SAI indexes.\n        if (isNonSAIIndex && baseType.isCollection() && !column.type.isMultiCell())\n        {\n            if (target.type == Type.VALUES || target.type == Type.KEYS || target.type == Type.KEYS_AND_VALUES)\n            {\n                throw ire(CREATE_ON_FROZEN_COLUMN, target.type.toString(), column.name, column.name);\n            }\n        }\n\n        if (!(baseType instanceof MapType) && (target.type == Type.KEYS || target.type == Type.KEYS_AND_VALUES ))\n            throw ire(CREATE_WITH_NON_MAP_TYPE, target.type, column);\n\n        // Can't query map[key]=value on clustering key columns, so ENTRIES index would be not queryable.\n        if (column.isClusteringColumn() && baseType instanceof MapType && !column.type.isMultiCell()\n            && target.type == Type.KEYS_AND_VALUES)\n            throw ire(ENTRIES_INDEX_ON_FROZEN_MAP_CLUSTERING_KEY_NOT_SUPPORTED, column.name);\n\n        if (column.type.isUDT() && column.type.isMultiCell())\n            throw ire(CREATE_ON_NON_FROZEN_UDT, column);\n    }\n\n    /**\n     * Checks if the given index attributes represent a Storage Attached Index.\n     */\n    private boolean isSAIIndex(IndexAttributes attrs)\n    {\n        return attrs.isCustom && IndexMetadata.isSAIIndex(attrs.customClass);\n    }\n","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateIndexStatement.java#L289-L325","documentation":"KEYS and KEYS_AND_VALUES (ENTRIES-style) index targets are only valid on map columns, since only maps have keys. Applying them to a list or set (or any non-map type) is rejected. Raised when baseType is not a MapType and target.type is KEYS or KEYS_AND_VALUES.","triggerScenarios":"`CREATE INDEX ON t (keys(my_list))` or `keys_and_values(my_set)` where the column is list<...>, set<...>, or a non-collection type.","commonSituations":"Confusing list indexes (VALUES only) with map indexes; script-generated index DDL applying keys() to all collections; switching a column from map to list without updating indexes.","solutions":["For lists and sets use a plain (VALUES) index: CREATE INDEX ON t (my_list).","Keep keys()/entries() only for map<...> columns.","If key-based lookup is needed on list data, remodel as a map or a query table."],"exampleFix":"// before\nCREATE INDEX ON t (keys(scores)); // scores: list<int>\n// after\nCREATE INDEX ON t (scores);","handlingStrategy":"validation","validationCode":"if (!(baseType instanceof MapType) && ['KEYS','KEYS_AND_VALUES'].includes(target.type)) throw new Error('keys()/entries() targets must be map columns');","typeGuard":"const keysTargetValid = (t) => t instanceof MapType;","tryCatchPattern":"try { session.execute(ddl); } catch (e) { if (/non-map type/.test(e.message)) { /* use plain index or fix the column */ } else throw e; }","preventionTips":["Only map<...> columns accept keys()/entries()","Re-audit index DDL after changing a column's collection kind"],"tags":["cassandra","cql","secondary-index","map","collections"],"backgroundTag":"invalid-argument-value","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}