apache/cassandra · error · InvalidRequestException

Invalid element access syntax for non-collection column %s

Error message

Invalid element access syntax for non-collection column %s

What it means

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.

Source

Thrown at src/java/org/apache/cassandra/cql3/ElementExpression.java:220

        public Kind kind()
        {
            return kind;
        }

        /**
         * Bind this {@link Raw} instance to the schema and return the resulting {@link ElementExpression}.
         *
         * @param column     the column
         * @return the {@link ElementExpression} resulting from the schema binding
         */
        ElementExpression prepare(ColumnMetadata column)
        {
            if (kind == Kind.COLLECTION_ELEMENT)
            {
                AbstractType<?> baseType = column.type.unwrap();

                if (!(baseType.isCollection()))
                    throw invalidRequest("Invalid element access syntax for non-collection column %s", column.name);

                Term term = prepareCollectionElement(column);
                CollectionType<?> collectionType = (CollectionType<?>) baseType;
                AbstractType<?> elementType = collectionType.valueComparator();
                AbstractType<?> keyOrIndexType = collectionType.isMap() ? ((MapType<?, ?>) collectionType).getKeysType() : Int32Type.instance;
                return new ElementExpression(kind, elementType, keyOrIndexType, term);
            }

            UserType userType = (UserType) column.type;
            int fieldPosition = userType.fieldPosition(udtField);
            if (fieldPosition == -1)
                throw invalidRequest("Unknown field %s for column %s", udtField, column.name);

            return new ElementExpression(kind,
                                         userType.type(fieldPosition),
                                         UTF8Type.instance,
                                         new Constants.Value(udtField.bytes));
        }

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Verify with `DESCRIBE TABLE` that the column is a map, list, or set before using element access syntax
  2. If the column should be a collection, fix the schema with ALTER TABLE (or migrate data) to restore the map/list/set type
  3. Correct the statement to reference the intended collection column, or drop the element access and compare the scalar column directly
  4. For UDT columns, use field access syntax (`udt_col.field`) instead of element access (`udt_col['field']`)

Example fix

// before
SELECT * FROM users WHERE age['primary'] = 42;  -- age is int
// after
SELECT * FROM users WHERE age = 42;
Defensive patterns

Strategy: validation

Validate before calling

// Before sending CQL with col[key] syntax, check the column type from cluster metadata
ColumnMetadata col = session.getMetadata().getKeyspace(ks).getTable(table).getColumn(colName);
AbstractType<?> t = col.getType().unwrap();
if (!(t instanceof CollectionType))
    throw new IllegalArgumentException("Column " + colName + " is not a collection; element access not allowed");

Type guard

boolean isCollectionColumn(ColumnMetadata col) {
    return col.getType().unwrap() instanceof CollectionType;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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]`).

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/3c114465997faa1a. Report an issue: GitHub.