{"record":{"id":"90d0489c666831f5","repo":"apache/cassandra","slug":"secondary-indexes-are-not-supported-on-udts-contai","errorCode":null,"errorMessage":"Secondary indexes are not supported on UDTs containing durations","messagePattern":"Secondary indexes are not supported on UDTs containing durations","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateIndexStatement.java","lineNumber":274,"sourceCode":"\n        AbstractType<?> baseType = column.type.unwrap();\n\n        boolean isNonSAIIndex = !isSAIIndex(attrs);\n\n        // TODO: this check needs to be removed with CASSANDRA-20235\n        if ((kind == IndexMetadata.Kind.CUSTOM))\n            validateCustomIndexColumnName(target.column.toString());\n\n        if (column.type.referencesDuration())\n        {\n            if (column.type.isCollection())\n                throw ire(COLLECTIONS_WITH_DURATIONS_NOT_SUPPORTED);\n\n            if (column.type.isTuple())\n                throw ire(TUPLES_WITH_DURATIONS_NOT_SUPPORTED);\n\n            if (column.type.isUDT())\n                throw  ire(UDTS_WITH_DURATIONS_NOT_SUPPORTED);\n\n            throw ire(DURATIONS_NOT_SUPPORTED);\n        }\n\n        if (table.isCompactTable())\n        {\n            TableMetadata.CompactTableMetadata compactTable = (TableMetadata.CompactTableMetadata) table;\n            if (column.isPrimaryKeyColumn())\n                throw new InvalidRequestException(PRIMARY_KEY_IN_COMPACT_STORAGE);\n            if (compactTable.compactValueColumn.equals(column))\n                throw new InvalidRequestException(COMPACT_COLUMN_IN_COMPACT_STORAGE);\n        }\n\n        if (column.isPartitionKey() && table.partitionKeyColumns().size() == 1)\n            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);","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateIndexStatement.java#L256-L292","documentation":"Cassandra rejects secondary indexes on user-defined types (UDTs) that contain a `duration` field. Since UDT fields are not individually indexable anyway and duration is unindexable, any UDT referencing duration is rejected. Raised in validateIndexTarget when the column type is a UDT referencing duration.","triggerScenarios":"`CREATE INDEX ON t (udt_col)` where udt_col's type definition includes a duration field (e.g. CREATE TYPE interval (start timestamp, len duration)), including frozen and non-frozen UDTs.","commonSituations":"Indexing a frozen UDT with full() after adding a duration field; shared UDT reused across tables where one table's index DDL no longer validates.","solutions":["Remove the duration field from the UDT or change it to bigint/timestamp.","Create a narrower UDT without duration for the indexed column.","Denormalize the fields you need to query into a dedicated indexed column."],"exampleFix":"// before\nCREATE TYPE interval (start_ts timestamp, len duration);\nCREATE INDEX ON schedules (span); // span frozen<interval>\n// after\nCREATE TYPE interval_idx (start_ts timestamp, len_ms bigint);\nCREATE INDEX ON schedules (span);","handlingStrategy":"validation","validationCode":"if (column.type.isUDT() && column.type.referencesDuration()) throw new Error('unindexable UDT: contains duration field');","typeGuard":"const isIndexableUdt = (t) => t.isUDT() && !t.referencesDuration();","tryCatchPattern":"try { session.execute(ddl); } catch (e) { if (/not supported on UDTs containing durations/.test(e.message)) { /* revise UDT definition */ } else throw e; }","preventionTips":["Keep duration out of UDTs that participate in indexes","Audit shared UDT definitions before adding indexes in any table"],"tags":["cassandra","cql","udt","duration","secondary-index"],"backgroundTag":"schema-validation-failed","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"}