prestodb/presto · error · IllegalArgumentException

Function call spec %s is not in a valid format.

Error message

Function call spec %s is not in a valid format.

What it means

FunctionCallRewriter parses each original function call spec with SqlParser.createExpression. If the spec is not syntactically valid SQL expression syntax, the ParsingException is wrapped into this IllegalArgumentException. The spec must parse to an expression before support checks run.

Source

Thrown at presto-verifier/src/main/java/com/facebook/presto/verifier/rewrite/FunctionCallRewriter.java:454

                if (signature.getNameSuffix().equals(functionCall.getName().getSuffix())) {
                    if (signature.getKind().equals(FunctionKind.AGGREGATE) || signature.getKind().equals(FunctionKind.WINDOW)) {
                        return true;
                    }
                }
            }
            return false;
        }
    }

    private static Expression parseOriginalFunctionCall(String functionCallSpec)
    {
        SqlParser sqlParser = new SqlParser();
        Expression expression;
        try {
            expression = sqlParser.createExpression(functionCallSpec, PARSING_OPTIONS);
        }
        catch (ParsingException e) {
            throw new IllegalArgumentException(String.format("Function call spec %s is not in a valid format.", functionCallSpec), e);
        }

        if (SUPPORTED_ORIGINAL_FUNCTIONS.stream().noneMatch(clazz -> clazz.equals(expression.getClass()))) {
            throw new IllegalArgumentException(String.format("Substituting %s in %s is not supported.", expression.getClass().getSimpleName(), functionCallSpec));
        }

        if (expression instanceof FunctionCall) {
            FunctionCall functionCall = (FunctionCall) expression;

            Stream<Expression> arguments = functionCall.getArguments().stream();
            arguments = Stream.concat(arguments, functionCall.getOrderBy().map(OrderBy::getSortItems).orElse(ImmutableList.of()).stream().map(SortItem::getSortKey));
            arguments = Stream.concat(arguments, functionCall.getWindow().map(Window::getPartitionBy).orElse(ImmutableList.of()).stream());
            arguments = Stream.concat(arguments, functionCall.getWindow().flatMap(Window::getOrderBy).map(OrderBy::getSortItems).orElse(ImmutableList.of()).stream().map(SortItem::getSortKey));

            arguments.forEach(argument -> {
                if (argument instanceof Identifier || argument instanceof Literal) {
                    return;
                }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Correct the spec so it is a syntactically valid SQL expression, e.g. 'myfunc(1, 2)'
  2. Test the spec by parsing it with `new SqlParser().createExpression(spec, PARSING_OPTIONS)` locally before deploying the config
  3. Check the properties file for characters (quotes, backslashes, trailing commas) mangled by properties-file parsing

Example fix

// before
originalSpec = "sum(x,"
// after
originalSpec = "sum(x)"
Defensive patterns

Strategy: validation

Validate before calling

// Pre-validate spec parses as an expression
try {
    new SqlParser().createExpression(spec, PARSING_OPTIONS);
} catch (ParsingException e) {
    throw new IllegalArgumentException("Spec does not parse: " + spec, e);
}

Try / catch

try {
    rewriter = FunctionCallRewriter.getInstance(functionCallSubstitutes, typeManager);
} catch (IllegalArgumentException e) {
    if (e.getCause() instanceof ParsingException) {
        LOG.error("Invalid SQL expression spec: %s", e.getMessage());
    }
}

Prevention

When it happens

Trigger: Calling FunctionCallRewriter.getInstance (or parseOriginalFunctionCall via validateAndConstructFunctionCallSubstituteMap) with an original-function spec that fails SqlParser parsing under PARSING_OPTIONS, e.g. mismatched parentheses, invalid tokens, or reserved-word misuse like 'myfunc(1,' or 'function x'.

Common situations: Typos in the verifier configuration; quoting errors in properties files stripping parentheses; writing a full statement or type name instead of an expression; trailing commas in argument lists.

Related errors


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