apache/cassandra · error · InvalidRequestException

unsupported target unit

Error message

unsupported target unit <targetUnit>

What it means

Data-storage format functions convert a byte/size value into a target unit via a switch over DataStorageUnit enum constants. If the target unit is not one of the handled enum cases, convertValue() throws this InvalidRequestException. It indicates the requested conversion unit fell through the switch default — effectively an internal unsupported-unit condition.

Solutions

  1. Use a supported target unit symbol (bytes, kilobytes/kibibytes, megabytes/mebibytes, gigabytes/gibibytes, etc. per DataStorageUnit).
  2. Upgrade/patch so the format function's convertValue switch covers the enum constant (report as a bug if hit on stock Cassandra).
  3. Verify the unit string parses to a DataStorageUnit via DataStorageUnit.fromSymbol before calling.

Example fix

// before
SELECT formatSize(size, 'zebibytes') FROM t; -- unhandled target unit
// after
SELECT formatSize(size, 'gibibytes') FROM t;
Defensive patterns

Strategy: validation

Validate before calling

if (!Set.of("bytes","kilobytes","kibibytes","megabytes","mebibytes","gigabytes","gibibytes").contains(unit)) throw new IllegalArgumentException("unsupported target unit: " + unit);

Try / catch

try { session.execute(query); } catch (InvalidRequestException e) { if (e.getMessage().startsWith("unsupported target unit")) { /* switch to a supported unit */ } else throw e; }

Prevention

When it happens

Trigger: Invoking a storage-size format function with a convertedValue path whose target unit is not bytes/kibibytes/mebibytes/gibibytes-and-siblings handled by the switch — normally only reachable if a new DataStorageUnit enum constant exists but the conversion switch was not updated.

Common situations: Running a newer Cassandra version where DataStorageUnit gained a constant but the format function's switch lags; custom patches to the enum.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/functions/FormatFcts.java:413

            String convertedValueAsString = format(convertedValue);

            return UTF8Type.instance.fromString(convertedValueAsString + ' ' + targetUnit.getSymbol());
        }

        private double convertValue(long valueToConvert, DataStorageUnit sourceUnit, DataStorageUnit targetUnit)
        {
            switch (targetUnit)
            {
                case BYTES:
                    return sourceUnit.toBytesDouble(valueToConvert);
                case KIBIBYTES:
                    return sourceUnit.toKibibytesDouble(valueToConvert);
                case MEBIBYTES:
                    return sourceUnit.toMebibytesDouble(valueToConvert);
                case GIBIBYTES:
                    return sourceUnit.toGibibytesDouble(valueToConvert);
                default:
                    throw new InvalidRequestException("unsupported target unit " + targetUnit);
            }
        }

        private DataStorageUnit validateUnit(String unitAsString)
        {
            try
            {
                return DataStorageUnit.fromSymbol(unitAsString);
            }
            catch (Exception ex)
            {
                throw new InvalidRequestException(ex.getMessage());
            }
        }

        public static FunctionFactory factory()
        {
            return new FunctionFactory(FUNCTION_NAME,

View on GitHub (pinned to 88fd0f6a0e)