prestodb/presto · error · IllegalArgumentException

Expression spec %s is not in a valid format.

Error message

Expression spec %s is not in a valid format.

What it means

parseSubstituteExpression parses the replacement spec with SqlParser.createExpression; a ParsingException is wrapped into this IllegalArgumentException. The substitute side of a function-call-substitutes entry must be a syntactically valid SQL expression.

Source

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

                    if (((ArrayConstructor) argument).getValues().stream().allMatch(Literal.class::isInstance)) {
                        return;
                    }
                }
                throw new IllegalArgumentException(String.format("Argument of type %s from %s is not supported.", argument.getClass().getSimpleName(), functionCallSpec));
            });
        }
        return expression;
    }

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

        if (SUPPORTED_SUBSTITUTE_EXPRESSIONS.stream().noneMatch(clazz -> clazz.isAssignableFrom(expression.getClass()))) {
            throw new IllegalArgumentException(String.format("Substitution of with from %s is not supported.", expression.getClass().getSimpleName()));
        }

        return expression;
    }

    private static Identifier toIdentifier(Expression expression)
    {
        if (expression instanceof Identifier) {
            return (Identifier) expression;
        }
        return new Identifier(String.valueOf(expression.toString().hashCode()));
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Fix the substitute spec so it parses as a single SQL expression, e.g. 'abs(x)' or 'CASE WHEN x > 0 THEN 1 ELSE 0 END'
  2. Validate by running `new SqlParser().createExpression(spec, PARSING_OPTIONS)` against the spec before putting it in config
  3. Check properties-file quoting/escaping for special characters in the expression

Example fix

// before
substituteSpec = "abs("
// after
substituteSpec = "abs(x)"
Defensive patterns

Strategy: validation

Validate before calling

try {
    new SqlParser().createExpression(substituteSpec, PARSING_OPTIONS);
} catch (ParsingException e) {
    throw new IllegalArgumentException("Substitute spec does not parse: " + substituteSpec, e);
}

Try / catch

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

Prevention

When it happens

Trigger: Passing a substitute expression spec that fails parsing, e.g. 'abs(' or 'if(x' in the second half of a function-call-substitutes entry.

Common situations: Truncated or typoed replacement expressions; properties-file escaping issues (e.g. backslashes or quotes in CASE/IF expressions); writing invalid SQL like a bare comma-separated list.

Related errors


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