apache/cassandra · error · InvalidRequestException

INITCOND must not be empty for all types except TEXT…

Error message

INITCOND must not be empty for all types except TEXT, ASCII, BLOB

What it means

Thrown when INITCOND is explicitly provided (not NULL literal) but the value is empty/zero-length for a state type that does not permit empty values. Only TEXT, ASCII, and BLOB state types accept an empty (zero-length) INITCOND.

Solutions

  1. Use a type-appropriate non-empty initcond, e.g. INITCOND 0 for numeric STYPEs.
  2. Use INITCOND only with text/ascii/blob if an empty value is genuinely desired.
  3. Omit the INITCOND clause entirely (state function must accept null input in that case).

Example fix

// before
CREATE AGGREGATE ks.c(int) SFUNC incr STYPE int INITCOND '';
// after
CREATE AGGREGATE ks.c(int) SFUNC incr STYPE int INITCOND 0;
Defensive patterns

Strategy: validation

Validate before calling

boolean emptyAllowed = Set.of("text","ascii","blob").contains(stateType.toLowerCase());
if (!emptyAllowed && (initcond == null || initcond.isEmpty()))
    throw new IllegalArgumentException("INITCOND must be non-empty for STYPE " + stateType);

Try / catch

try { session.execute(ddl); }
catch (InvalidRequestException e) {
    if (e.getMessage().contains("INITCOND must not be empty")) { /* supply a type-appropriate initcond */ }
    else throw e;
}

Prevention

When it happens

Trigger: CREATE AGGREGATE ... INITCOND '' (or another empty value) where STYPE is not text, ascii, or blob — e.g. INITCOND '' with STYPE int.

Common situations: Using '' as a generic 'default' value by habit; templated DDL generating INITCOND '' for all types; migrating aggregates between types without adjusting initcond.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/statements/schema/CreateAggregateStatement.java:197

            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);
        }

        /*
         * Create or replace
         */

        UDAggregate aggregate =
            new UDAggregate(new FunctionName(keyspaceName, aggregateName),
                            argumentTypes,
                            returnType,
                            (ScalarFunction) stateFunction,

View on GitHub (pinned to 88fd0f6a0e)