prestodb/presto · error · IllegalStateException

Cannot parse distinct type definition(%s), expected '{' afte

Error message

Cannot parse distinct type definition(%s), expected '{' after position %s

What it means

This error is thrown by DistinctTypeParsingData.parse in TypeSignature while parsing a serialized distinct type signature (format: name{baseType, orderable, [ancestors]}). It means the '{' character that must follow the distinct type's qualified name was not found at or after startIndex. The library throws it because a signature string reaching this parser is malformed relative to the expected distinct-type serialization layout.

Source

Thrown at presto-common/src/main/java/com/facebook/presto/common/type/TypeSignature.java:315

        private final int endIndex;
        private final DistinctTypeInfo distinctType;

        private DistinctTypeParsingData(int endIndex, DistinctTypeInfo distinctType)
        {
            this.endIndex = endIndex;
            this.distinctType = distinctType;
        }

        private static Optional<QualifiedObjectName> parseParentName(String s)
        {
            return s.equals("null") ? Optional.empty() : Optional.of(QualifiedObjectName.valueOf(s));
        }

        private static DistinctTypeParsingData parse(String signature, int startIndex)
        {
            int openBracketIndex = signature.indexOf("{", startIndex);
            if (openBracketIndex == -1) {
                throw new IllegalStateException(format("Cannot parse distinct type definition(%s), expected '{' after position %s", signature, startIndex));
            }
            QualifiedObjectName name = QualifiedObjectName.valueOf(signature.substring(startIndex, openBracketIndex));

            int firstCommaIndex = signature.indexOf(", ", openBracketIndex);
            if (firstCommaIndex == -1) {
                throw new IllegalStateException(format("Cannot parse distinct type definition(%s), expected ',' after position %s", signature, openBracketIndex));
            }
            TypeSignature baseType = TypeSignature.parseTypeSignature(signature.substring(openBracketIndex + 1, firstCommaIndex));

            int secondCommaIndex = signature.indexOf(", ", firstCommaIndex + 2);
            if (secondCommaIndex == -1) {
                throw new IllegalStateException(format("Cannot parse distinct type definition(%s), expected ',' after position %s", signature, secondCommaIndex));
            }
            boolean isOrderable = parseBoolean(signature.substring(firstCommaIndex + 2, secondCommaIndex));

            int thirdCommaIndex = signature.indexOf(", [", secondCommaIndex + 2);
            if (thirdCommaIndex == -1) {
                throw new IllegalStateException(format("Cannot parse distinct type definition(%s), expected '[' after position %s", signature, secondCommaIndex));

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Check the signature string and ensure it contains '{' immediately after the distinct type's qualified name, e.g. 'cat.schema.type{baseType, true, []}'.
  2. Verify the signature was produced by TypeSignature.toString()/TypeSignatureBase of the same Presto version — regenerate it rather than hand-editing.
  3. Log and inspect the full signature at the startIndex reported by the message to spot truncation or whitespace/encoding corruption.

Example fix

// before (malformed)
TypeSignature.parseTypeSignature("DISTINCT shop.customer_id bigint, true, []}");
// after
TypeSignature.parseTypeSignature("DISTINCT shop.customer_id{bigint, true, []}");
Defensive patterns

Strategy: validation

Validate before calling

// pre-validate a distinct type signature before parsing
boolean hasOpenBrace = signature != null && signature.contains("{");
if (!hasOpenBrace) {
    throw new IllegalArgumentException("Malformed distinct type signature (missing '{'): " + signature);
}

Type guard

static boolean looksLikeDistinctType(String sig) {
    return sig != null && sig.matches(".*\\{.*,.*\\}\\s*$");
}

Try / catch

try {
    TypeSignature ts = TypeSignature.parseTypeSignature(signature);
} catch (IllegalStateException e) {
    if (e.getMessage().contains("expected '{'")) {
        // log full signature, fall back to raw VARCHAR type
    } else throw e;
}

Prevention

When it happens

Trigger: Calling TypeSignature.parseTypeSignature (or parsing a signature containing 'DISTINCT <name>...') where the text after the type name has no '{' character — e.g. 'DISTINCT myschema.mytype base, true, []}' missing the brace, or a truncated signature.

Common situations: Hand-editing serialized type signatures, corruption of type signatures persisted in catalogs/metadata, version mismatch where a connector emits an older or custom distinct-type format, truncation when copying signature strings.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/d5b4843be2a2fab9. Report an issue: GitHub.