{"record":{"id":"3c114465997faa1a","repo":"apache/cassandra","slug":"invalid-element-access-syntax-for-non-collection-c","errorCode":null,"errorMessage":"Invalid element access syntax for non-collection column %s","messagePattern":"Invalid element access syntax for non-collection column (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/ElementExpression.java","lineNumber":220,"sourceCode":"        public Kind kind()\n        {\n            return kind;\n        }\n\n        /**\n         * Bind this {@link Raw} instance to the schema and return the resulting {@link ElementExpression}.\n         *\n         * @param column     the column\n         * @return the {@link ElementExpression} resulting from the schema binding\n         */\n        ElementExpression prepare(ColumnMetadata column)\n        {\n            if (kind == Kind.COLLECTION_ELEMENT)\n            {\n                AbstractType<?> baseType = column.type.unwrap();\n\n                if (!(baseType.isCollection()))\n                    throw invalidRequest(\"Invalid element access syntax for non-collection column %s\", column.name);\n\n                Term term = prepareCollectionElement(column);\n                CollectionType<?> collectionType = (CollectionType<?>) baseType;\n                AbstractType<?> elementType = collectionType.valueComparator();\n                AbstractType<?> keyOrIndexType = collectionType.isMap() ? ((MapType<?, ?>) collectionType).getKeysType() : Int32Type.instance;\n                return new ElementExpression(kind, elementType, keyOrIndexType, term);\n            }\n\n            UserType userType = (UserType) column.type;\n            int fieldPosition = userType.fieldPosition(udtField);\n            if (fieldPosition == -1)\n                throw invalidRequest(\"Unknown field %s for column %s\", udtField, column.name);\n\n            return new ElementExpression(kind,\n                                         userType.type(fieldPosition),\n                                         UTF8Type.instance,\n                                         new Constants.Value(udtField.bytes));\n        }","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/ElementExpression.java#L202-L238","documentation":"Cassandra throws this when a CQL statement uses element access syntax (e.g. `col[...]`) on a column whose type is not a collection (map, list, or set). During `ElementExpression.prepare()`, the column's base type is unwrapped and checked with `isCollection()`; if it is not a collection there is no valid element/key type to select. The error names the offending column.","triggerScenarios":"Issuing CQL like `SELECT * FROM t WHERE scalar_col['key'] = ...`, `UPDATE t SET int_col[0] = ...`, or a JSON/condition expression using element indexing on a non-collection (scalar, UDT-only, frozen-incompatible) column. Also occurs when the schema changed a column from map/list/set to a scalar and old statements are re-prepared.","commonSituations":"Typo where the wrong column name is used in a `col[key]` filter; schema migration replaced a collection column with a text/int column; confusion between UDT field access (`udt.field`) and collection element access (`col[key]`).","solutions":["Verify with `DESCRIBE TABLE` that the column is a map, list, or set before using element access syntax","If the column should be a collection, fix the schema with ALTER TABLE (or migrate data) to restore the map/list/set type","Correct the statement to reference the intended collection column, or drop the element access and compare the scalar column directly","For UDT columns, use field access syntax (`udt_col.field`) instead of element access (`udt_col['field']`)"],"exampleFix":"// before\nSELECT * FROM users WHERE age['primary'] = 42;  -- age is int\n// after\nSELECT * FROM users WHERE age = 42;","handlingStrategy":"validation","validationCode":"// Before sending CQL with col[key] syntax, check the column type from cluster metadata\nColumnMetadata col = session.getMetadata().getKeyspace(ks).getTable(table).getColumn(colName);\nAbstractType<?> t = col.getType().unwrap();\nif (!(t instanceof CollectionType))\n    throw new IllegalArgumentException(\"Column \" + colName + \" is not a collection; element access not allowed\");","typeGuard":"boolean isCollectionColumn(ColumnMetadata col) {\n    return col.getType().unwrap() instanceof CollectionType;\n}","tryCatchPattern":null,"preventionTips":["Check DESCRIBE TABLE before writing element-access queries against unfamiliar schemas","Remember UDT columns need field access (dot notation), not element access","Re-fetch driver schema metadata after ALTER statements change column types","Add unit tests that run all application CQL against a local Cassandra instance to catch prepare-time validation errors early"],"tags":["cql","validation","collection","query"],"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"}