apache/cassandra · error · InvalidTypeException

Cannot parse tuple value from

Error message

Cannot parse tuple value from "%s", invalid CQL value at character %d

What it means

Inside the tuple codec's parse loop, each field value is scanned with ParseUtils.skipCQLValue. When the characters at the current position do not form a valid CQL value for the next field, skipCQLValue throws IllegalArgumentException, which the codec rethrows as this InvalidTypeException indicating the offending character index.

Solutions

  1. Fix the literal so every field is a valid CQL value for its declared type (quote strings: ('abc', 2)).
  2. Validate field values against the TupleType component types before parsing.
  3. Construct the TupleValue programmatically with TupleType.newValue(...) to bypass string parsing entirely.
  4. Inspect the reported character index in the message to locate the malformed field.

Example fix

// before
TupleValue v = tupleType.parse("(abc, 2)"); // 'abc' not valid for int field
// after
TupleValue v = tupleType.parse("(1, 'abc')"); // reorder or quote correctly per field types
Defensive patterns

Strategy: validation

Validate before calling

for (int i = 0; i < values.length; i++) if (!tupleType.getComponentTypes().get(i).accepts(values[i])) throw new IllegalArgumentException("field " + i + " invalid");

Try / catch

try { return tupleType.parse(literal); } catch (InvalidTypeException e) { throw new IllegalArgumentException("bad CQL value: " + e.getMessage(), e); }

Prevention

When it happens

Trigger: Parsing "(abc, 2)" for a tuple whose first field is int (non-numeric literal), unquoted strings without quotes like (hello, 1), stray characters such as (1; 2), or a literal terminated early like (1, ).

Common situations: Typo in a literal during manual cqlsh inserts; user-supplied form data bound directly as CQL literal; values copied from another serialization format.

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/3ee1cae1fe04c9e7. Report an issue: GitHub.

Appendix: source

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

                String.format(
                "Cannot parse tuple value from \"%s\", at character %d expecting '(' but got '%c'",
                value, idx, value.charAt(idx)));

            idx = ParseUtils.skipSpaces(value, idx);

            if (value.charAt(idx) == ')') return v;

            int i = 0;
            while (idx < value.length())
            {
                int n;
                try
                {
                    n = ParseUtils.skipCQLValue(value, idx);
                }
                catch (IllegalArgumentException e)
                {
                    throw new InvalidTypeException(
                    String.format(
                    "Cannot parse tuple value from \"%s\", invalid CQL value at character %d",
                    value, idx),
                    e);
                }

                String input = value.substring(idx, n);
                v = parseAndSetField(input, v, i);
                idx = n;
                i += 1;

                idx = ParseUtils.skipSpaces(value, idx);
                if (value.charAt(idx) == ')') return v;
                if (value.charAt(idx) != ',')
                    throw new InvalidTypeException(
                    String.format(
                    "Cannot parse tuple value from \"%s\", at character %d expecting ',' but got '%c'",
                    value, idx, value.charAt(idx)));

View on GitHub (pinned to 88fd0f6a0e)