prestodb/presto · error · IllegalArgumentException

Bad type signature: '%s'

Error message

Bad type signature: '%s'

What it means

TypeSignature.parseTypeSignature parses a type signature string (e.g. "array(bigint)", "row(a int)"). When the parser exhausts the input without reaching a complete, well-formed type — due to unbalanced parentheses, stray characters, or trailing garbage — it throws IllegalArgumentException with the offending signature.

Source

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

                EnumMapParsingData enumMapParsingData = parseEnumMap(lowerCaseSignature, i);
                parameterEnd = enumMapParsingData.mapEndIndex;
                parsedEnumMaps.put(i, enumMapParsingData);
            }
            else if (distinctTypeStartIndices.contains(i)) {
                DistinctTypeParsingData distinctTypeParsingData = DistinctTypeParsingData.parse(lowerCaseSignature, i);
                parameterEnd = distinctTypeParsingData.endIndex;
                parsedDistinctTypes.put(i, distinctTypeParsingData);
            }
            else if (c == ',') {
                if (bracketCount == 1) {
                    checkArgument(parameterStart >= 0, "Bad type signature: '%s'", signature);
                    parameters.add(parseTypeSignatureParameter(signature, parameterStart, i, literalCalculationParameters, parsedEnumMaps, parsedDistinctTypes));
                    parameterStart = i + 1;
                }
            }
        }

        throw new IllegalArgumentException(format("Bad type signature: '%s'", signature));
    }

    private static class DistinctTypeParsingData
    {
        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));
        }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Inspect the signature string in the exception message and fix the syntax (balance parentheses/angle brackets, remove trailing tokens).
  2. Verify the source of the string: catalog metadata, config file, or query output may be truncated or stale.
  3. Check engine/plugin version compatibility for newer type-signature syntax (row fields, distinct types, enum literals).
  4. Catch IllegalArgumentException around parseTypeSignature and surface a user-facing INVALID_TYPE_SIGNATURE error.

Example fix

// before
TypeSignature sig = parseTypeSignature("array(bigint"); // throws
// after
TypeSignature sig;
try {
    sig = parseTypeSignature(signature.trim());
} catch (IllegalArgumentException e) {
    throw new PrestoException(INVALID_TYPE_SIGNATURE, "Invalid type: " + signature, e);
}
Defensive patterns

Strategy: try-catch

Validate before calling

boolean balanced = true;
int depth = 0;
for (char c : signature.toCharArray()) {
    if (c == '<' || c == '(') depth++;
    if (c == '>' || c == ')') depth--;
    if (depth < 0) { balanced = false; break; }
}
if (signature.trim().isEmpty() || !balanced || depth != 0) {
    throw new IllegalArgumentException("Malformed type signature: " + signature);
}

Type guard

boolean looksLikeTypeSignature(String s) {
    return s != null && s.trim().matches("[a-zA-Z][a-zA-Z0-9_]*(\\(.*\\)|<.*>)?");
}

Try / catch

try {
    sig = TypeSignature.parseTypeSignature(raw);
} catch (IllegalArgumentException e) {
    throw new PrestoException(INVALID_TYPE_SIGNATURE,
        "Cannot parse type signature '" + raw + "'", e);
}

Prevention

When it happens

Trigger: parseTypeSignature("...") where the string is empty, has unbalanced '<'/'>', '(' or ')', contains an invalid parameter list, or has trailing characters after a complete type.

Common situations: Catalog/connector metadata returning hand-built or corrupted type strings; user-supplied type names passed through SQL-like config; version skew where a newer type syntax (e.g. distinct types, enum parameters) is parsed by an older engine.

Related errors


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