{"record":{"id":"15594ac81342c9c5","repo":"prestodb/presto","slug":"invalid-function-argument-15594a","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"e.getMessage()","messagePattern":"e\\.getMessage\\(\\)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/execution/SqlQueryExecution.java","lineNumber":638,"sourceCode":"\n            // fragment the plan\n            // the variableAllocator is finally passed to SqlQueryScheduler for runtime cost-based optimizations\n            variableAllocator.set(new VariableAllocator(plan.getTypes().allVariables()));\n            SubPlan fragmentedPlan = getSession().getRuntimeStats().recordWallAndCpuTime(\n                    FRAGMENT_PLAN_TIME_NANOS,\n                    () -> planFragmenter.createSubPlans(stateMachine.getSession(), plan, false, idAllocator, variableAllocator.get(), stateMachine.getWarningCollector()));\n\n            // record analysis time\n            stateMachine.endAnalysis();\n\n            boolean explainAnalyze = queryAnalysis.isExplainAnalyzeQuery();\n            return new PlanRoot(fragmentedPlan, !explainAnalyze, queryAnalysis.extractConnectors());\n        }\n        catch (StackOverflowError e) {\n            throw new PrestoException(NOT_SUPPORTED, \"statement is too large (stack overflow during analysis)\", e);\n        }\n        catch (InvalidFunctionArgumentException e) {\n            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);\n        }\n    }\n\n    private PlanRoot runCreateLogicalPlanAsync()\n    {\n        try {\n            // Check if creating plan async has been cancelled\n            if (planFutureLocked.compareAndSet(false, true)) {\n                return createLogicalPlanAndOptimize();\n            }\n            return null;\n        }\n        catch (Throwable e) {\n            fail(e);\n            throw e;\n        }\n    }\n","sourceCodeStart":620,"sourceCodeEnd":656,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/execution/SqlQueryExecution.java#L620-L656","documentation":"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.","triggerScenarios":"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.","commonSituations":"Malformed function calls in generated SQL, passing NULL/negative/oversized arguments to functions like split_part, substr, or geometric functions.","solutions":["Read the message for the exact function and argument that is invalid.","Fix the argument values in the query (check ranges, non-negative sizes, valid indices).","Guard arguments in SQL with CASE/COALESCE to keep them in the valid domain.","Validate inputs upstream before building the query."],"exampleFix":"-- before\nSELECT substr(name, -5, -2) FROM t;\n-- after\nSELECT substr(name, 1, 5) FROM t;","handlingStrategy":"try-catch","validationCode":"-- validate function arguments in SQL\ncase when len >= 1 then substr(s, 1, len) else null end","typeGuard":null,"tryCatchPattern":"// catch PrestoException with errorCode INVALID_FUNCTION_ARGUMENT; log e.getMessage() identifying the bad function call, fix the arguments, retry","preventionTips":["Validate numeric argument ranges before building SQL","Guard risky function calls with CASE/COALESCE","Test generated SQL against representative inputs"],"tags":["sql","functions","arguments"],"backgroundTag":"invalid-function-arguments","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}