apache/cassandra · error · InvalidRequestException
Invalid value for INITCOND of type
Error message
Invalid value for INITCOND of type %s
What it means
Thrown when the literal supplied as INITCOND cannot be validated as a value of the aggregate's STYPE (an AbstractType.MarshalException was raised while validating the serialized bytes). The initcond must be a legal value of the state type.
Solutions
- Align the INITCOND literal with the declared STYPE (e.g. 0 for int, 0.0 for double, quoted string for text).
- Update STYPE and INITCOND together when changing the state type.
- Omit INITCOND if the state function is CALLED ON NULL INPUT and null initialization is acceptable.
Example fix
// before CREATE AGGREGATE ks.sum(int) SFUNC add_one STYPE int INITCOND 'zero'; // after CREATE AGGREGATE ks.sum(int) SFUNC add_one STYPE int INITCOND 0;
Defensive patterns
Strategy: validation
Validate before calling
// validate initcond literal against STYPE before issuing DDL
try {
Object v = stateType.asCQL3Type().fromCQLLiteral(initcondLiteral);
stateType.validate(stateType.getSerializer().serialize(v));
} catch (MarshalException e) {
throw new IllegalArgumentException("INITCOND " + initcondLiteral + " invalid for STYPE " + stateType);
} Try / catch
try { session.execute(ddl); }
catch (InvalidRequestException e) {
if (e.getMessage().startsWith("Invalid value for INITCOND")) { /* fix literal to match STYPE */ }
else throw e;
} Prevention
- Derive INITCOND from the STYPE in generated DDL (0, 0.0, '', etc.).
- Update STYPE and INITCOND together in schema migrations.
- Test DDL against a local cluster before applying to production.
When it happens
Trigger: CREATE AGGREGATE ... INITCOND <value> where <value> does not marshal to the declared STYPE, e.g. a string for an int state type, an out-of-domain value for the type, or a wrongly shaped collection/tuple literal.
Common situations: Copy-pasted initcond from an aggregate with a different STYPE; type changed in STYPE but old INITCOND left in place; locale/precision issues with decimal or floating-point literals.
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
- Cannot assign value to of type
- Cannot assign value to of type
- Cannot cast value to type
- Cannot create aggregate
- Cannot replace aggregate
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/26342bac5a326fe0.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateAggregateStatement.java:187
/*
* Validate initial condition
*/
ByteBuffer initialValue = null;
if (null != rawInitialValue)
{
String term = rawInitialValue.toString();
initialValue = Term.asBytes(keyspaceName, term, stateType);
if (null != initialValue)
{
try
{
stateType.validate(initialValue);
}
catch (MarshalException e)
{
throw ire("Invalid value for INITCOND of type %s", stateType.asCQL3Type());
}
}
// Converts initcond to a CQL literal and parse it back to avoid another CASSANDRA-11064
String initialValueString = stateType.asCQL3Type().toCQLLiteral(initialValue);
if (!Objects.equal(initialValue, stateType.asCQL3Type().fromCQLLiteral(initialValueString)))
throw new AssertionError(String.format("CQL literal '%s' (from type %s) parsed with a different value", initialValueString, stateType.asCQL3Type()));
if (Constants.NULL_LITERAL != rawInitialValue && isNullOrEmpty(stateType, initialValue))
throw ire("INITCOND must not be empty for all types except TEXT, ASCII, BLOB");
}
if (!((UDFunction) stateFunction).isCalledOnNullInput() && null == initialValue)
{
throw ire("Cannot create aggregate '%s' without INITCOND because state function %s does not accept 'null' arguments",
aggregateName,
stateFunctionName);
}View on GitHub (pinned to 88fd0f6a0e)