prestodb/presto · error · PrestoException

INVALID_FUNCTION_ARGUMENT

INVALID_FUNCTION_ARGUMENT

Error message

e.getMessage()

What it means

While creating the logical plan, an InvalidFunctionArgumentException was raised and converted into an INVALID_FUNCTION_ARGUMENT PrestoException carrying the original message. This surfaces function-argument errors detected during plan/analysis to the client.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/execution/SqlQueryExecution.java:638

            // fragment the plan
            // the variableAllocator is finally passed to SqlQueryScheduler for runtime cost-based optimizations
            variableAllocator.set(new VariableAllocator(plan.getTypes().allVariables()));
            SubPlan fragmentedPlan = getSession().getRuntimeStats().recordWallAndCpuTime(
                    FRAGMENT_PLAN_TIME_NANOS,
                    () -> planFragmenter.createSubPlans(stateMachine.getSession(), plan, false, idAllocator, variableAllocator.get(), stateMachine.getWarningCollector()));

            // record analysis time
            stateMachine.endAnalysis();

            boolean explainAnalyze = queryAnalysis.isExplainAnalyzeQuery();
            return new PlanRoot(fragmentedPlan, !explainAnalyze, queryAnalysis.extractConnectors());
        }
        catch (StackOverflowError e) {
            throw new PrestoException(NOT_SUPPORTED, "statement is too large (stack overflow during analysis)", e);
        }
        catch (InvalidFunctionArgumentException e) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);
        }
    }

    private PlanRoot runCreateLogicalPlanAsync()
    {
        try {
            // Check if creating plan async has been cancelled
            if (planFutureLocked.compareAndSet(false, true)) {
                return createLogicalPlanAndOptimize();
            }
            return null;
        }
        catch (Throwable e) {
            fail(e);
            throw e;
        }
    }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Read the message for the exact function and argument that is invalid.
  2. Fix the argument values in the query (check ranges, non-negative sizes, valid indices).
  3. Guard arguments in SQL with CASE/COALESCE to keep them in the valid domain.
  4. Validate inputs upstream before building the query.

Example fix

-- before
SELECT substr(name, -5, -2) FROM t;
-- after
SELECT substr(name, 1, 5) FROM t;
Defensive patterns

Strategy: try-catch

Validate before calling

-- validate function arguments in SQL
case when len >= 1 then substr(s, 1, len) else null end

Try / catch

// catch PrestoException with errorCode INVALID_FUNCTION_ARGUMENT; log e.getMessage() identifying the bad function call, fix the arguments, retry

Prevention

When it happens

Trigger: doCreateLogicalPlanAndOptimize() catches InvalidFunctionArgumentException during planning — typically calling a function with arguments outside its domain (e.g. negative length in substr, wrong numeric argument) that is only validated at plan time.

Common situations: Malformed function calls in generated SQL, passing NULL/negative/oversized arguments to functions like split_part, substr, or geometric functions.

Related errors


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