apache/cassandra · error · InvalidTypeException

time values must be enclosed by single quotes

Error message

time values must be enclosed by single quotes

What it means

Thrown by TypeCodec.TimeCodec.parse(String) because CQL time literals must be enclosed in single quotes even when given as a plain long (nanoseconds since midnight). The codec enforces quoting unconditionally to disambiguate time literals from other numeric tokens; an unquoted value is rejected immediately with this message before any parsing.

Source

Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:1900

        {
            super(DataType.time());
        }

        @Override
        public int serializedSize()
        {
            // matching behavior of TimeType, which is not declared as fixed length
            return VARIABLE_LENGTH;
        }

        @Override
        public Long parse(String value)
        {
            if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null;

            // enclosing single quotes required, even for long literals
            if (!ParseUtils.isQuoted(value))
                throw new InvalidTypeException("time values must be enclosed by single quotes");
            value = value.substring(1, value.length() - 1);

            if (ParseUtils.isLongLiteral(value))
            {
                try
                {
                    return Long.parseLong(value);
                }
                catch (NumberFormatException e)
                {
                    throw new InvalidTypeException(
                    String.format("Cannot parse time value from \"%s\"", value), e);
                }
            }

            try
            {
                return ParseUtils.parseTime(value);

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Wrap the value in single quotes: parse("'34200000000000'") or parse("'08:30:00.000'").
  2. Use ParseUtils.quote(value) when constructing literals programmatically.
  3. Pass a java.lang.Long nanoseconds value via bound statements/codecs (format/serialize) instead of string parsing.
  4. Catch InvalidTypeException and auto-quote with a helper before retrying parse.

Example fix

// before
Long t = TypeCodec.time().parse("08:30:00");
// after
Long t = TypeCodec.time().parse("'08:30:00'");
Defensive patterns

Strategy: validation

Validate before calling

static String quoteCqlTime(String v) {
    return "'" + v + "'";
}
static boolean isQuotedCqlTime(String v) {
    return v != null && v.length() >= 2 && v.charAt(0) == '\'' && v.charAt(v.length() - 1) == '\'';
}

Try / catch

try {
    Long t = TypeCodec.time().parse(literal);
} catch (InvalidTypeException e) {
    // auto-quote and retry once
    t = TypeCodec.time().parse("'" + literal + "'");
}

Prevention

When it happens

Trigger: Calling TimeCodec.parse() with unquoted input such as 34200000000000 as the raw string "34200000000000" or "08:30:00" — anything where ParseUtils.isQuoted(value) is false. Also triggered by literals built without quotes in string concatenation.

Common situations: Building query literals by hand and forgetting to quote time values (unlike int/bigint, quotes are mandatory); passing results of Long.toString(nanos) straight to parse; copying cqlsh output that displays unquoted values.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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