apache/cassandra · error · InvalidRequestException
ex.getMessage()
Error message
ex.getMessage()
What it means
Time duration format functions validate the unit argument via DurationSpec.fromSymbol, which only accepts Cassandra's duration units (e.g. 'years', 'months', 'days', 'hours', 'minutes', 'seconds', etc.). validateUnit() wraps any exception from that parsing and rethrows its message as an InvalidRequestException. This error means the unit string supplied is not a recognized duration unit symbol.
Source
Thrown at src/java/org/apache/cassandra/cql3/functions/FormatFcts.java:225
sourceUnit = validateUnit(arguments.get(1));
targetUnitAsString = arguments.get(2);
}
targetUnit = validateUnit(targetUnitAsString);
double convertedValue = convertValue(value, sourceUnit, targetUnit);
return UTF8Type.instance.fromString(format(convertedValue) + ' ' + targetUnitAsString);
}
private TimeUnit validateUnit(String unitAsString)
{
try
{
return DurationSpec.fromSymbol(unitAsString);
}
catch (Exception ex)
{
throw new InvalidRequestException(ex.getMessage());
}
}
private Pair<Double, String> convertValue(long valueToConvert)
{
for (int i = 0; i < CONVERSION_FACTORS.length; i++)
{
if (valueToConvert >= CONVERSION_FACTORS[i])
{
double convertedValue = (double) valueToConvert / CONVERSION_FACTORS[i];
return Pair.create(convertedValue, UNITS[i]);
}
}
return Pair.create((double) valueToConvert, "ms");
}
private Double convertValue(long valueToConvert, TimeUnit sourceUnit, TimeUnit targetUnit)
{View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Use an exact supported unit symbol, e.g. 'years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds', 'milliseconds', 'microseconds', 'nanoseconds' (check DurationSpec symbols for your version).
- Check the function's documentation/description in system_schema or DESCRIPTOR for accepted units.
- Correct casing/plurality to match the enum symbol exactly.
Example fix
// before SELECT formatDuration(90, 'min') FROM t; // after SELECT formatDuration(90, 'minutes') FROM t;
Defensive patterns
Strategy: validation
Validate before calling
Set<String> allowed = Set.of("years","months","weeks","days","hours","minutes","seconds","milliseconds","microseconds","nanoseconds");
if (!allowed.contains(unit)) throw new IllegalArgumentException("bad duration unit: " + unit); Try / catch
try { session.execute("SELECT formatDuration(90, '" + unit + "') FROM t"); } catch (InvalidRequestException e) { /* unit symbol rejected — correct and retry with canonical symbol */ } Prevention
- Use exact DurationSpec symbols, fully spelled out and plural where required
- Keep unit names in a constants file shared across queries
- Check DESC FUNCTION output for accepted units
When it happens
Trigger: Executing a duration format function (e.g. formatDuration(...)) where the unit parameter is misspelled, plural/singular mismatched, or an unsupported string like 'yrs' or 'seconds*' — any Exception from DurationSpec.fromSymbol is rethrown.
Common situations: Typos in cqlsh queries; assuming abbreviated units ('h', 'sec') are supported; version differences where certain unit symbols are not accepted.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Durations are not allowed inside sets:
- Durations are not allowed as map keys:
- Unknown duration symbol '%s'
- Unable to convert '%s' to a duration
- Unknown bucket_mode '" + value + "'
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/2aea696695b0f5bd.
Report an issue: GitHub.