apache/cassandra · error · InvalidRequestException
A user type cannot contain counters
Error message
A user type cannot contain counters
What it means
Validation guard in CreateTypeStatement.apply() fired while creating a user-defined type: one of the declared field types is a counter type. Cassandra UDTs are stored as static schema metadata with no write path for counter increments, so a counter field inside a UDT is illegal; the create is rejected with InvalidRequestException before the schema change is applied.
Solutions
- Remove the counter-typed field from the CREATE TYPE declaration and create the type again without it; if counters are required, keep them in a regular counter table instead of a UDT; nest or reference counter data by primary key rather than embedding it in the UDT.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateTypeStatement.java:112 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/b17585297bcbe62a.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateTypeStatement.java:112
UserType existingType = keyspace.types.getNullable(bytes(typeName));
if (null != existingType)
{
if (ifNotExists)
return schema;
throw ire("A user type with name '%s' already exists", typeName);
}
Set<FieldIdentifier> usedNames = new HashSet<>();
for (FieldIdentifier name : fieldNames)
if (!usedNames.add(name))
throw ire("Duplicate field name '%s' in type '%s'", name, typeName);
for (CQL3Type.Raw type : rawFieldTypes)
{
if (type.isCounter())
throw ire("A user type cannot contain counters");
if (type.isUDT() && !type.isFrozen())
throw ire("A user type cannot contain non-frozen UDTs");
}
List<AbstractType<?>> fieldTypes =
rawFieldTypes.stream()
.map(t -> t.prepare(keyspaceName, keyspace.types).getType())
.collect(toList());
UserType udt = new UserType(keyspaceName, bytes(typeName), fieldNames, fieldTypes, true);
return schema.withAddedOrUpdated(keyspace.withSwapped(keyspace.types.with(udt)));
}
SchemaChange schemaChangeEvent(KeyspacesDiff diff)
{
return new SchemaChange(Change.CREATED, Target.TYPE, keyspaceName, typeName);
}View on GitHub (pinned to 88fd0f6a0e)