{"record":{"id":"1b468dd28d55d41b","repo":"prestodb/presto","slug":"invalid-function-argument-1b468d","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"ROW index out of bounds: ","messagePattern":"ROW index out of bounds: ","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/planner/ExpressionInterpreter.java","lineNumber":1256,"sourceCode":"            }\n            Object index = process(node.getIndex(), context);\n            if (index == null) {\n                return null;\n            }\n            if ((index instanceof Long) && isArray(type(node.getBase()))) {\n                ArraySubscriptOperator.checkArrayIndex((Long) index);\n            }\n\n            if (hasUnresolvedValue(base, index)) {\n                return new SubscriptExpression(toExpression(base, type(node.getBase())), toExpression(index, type(node.getIndex())));\n            }\n\n            // Subscript on Row hasn't got a dedicated operator. It is interpreted by hand.\n            if (base instanceof SingleRowBlock) {\n                SingleRowBlock row = (SingleRowBlock) base;\n                int position = toIntExact((long) index - 1);\n                if (position < 0 || position >= row.getPositionCount()) {\n                    throw new PrestoException(StandardErrorCode.INVALID_FUNCTION_ARGUMENT, \"ROW index out of bounds: \" + (position + 1));\n                }\n                Type returnType = type(node.getBase()).getTypeParameters().get(position);\n                return TypeUtils.readNativeValue(returnType, row, position);\n            }\n\n            // Subscript on Array or Map is interpreted using operator.\n            return invokeOperator(OperatorType.SUBSCRIPT, types(node.getBase(), node.getIndex()), ImmutableList.of(base, index));\n        }\n\n        @Override\n        protected Object visitQuantifiedComparisonExpression(QuantifiedComparisonExpression node, Object context)\n        {\n            if (!optimize) {\n                throw new UnsupportedOperationException(\"QuantifiedComparison not yet implemented\");\n            }\n            return node;\n        }\n","sourceCodeStart":1238,"sourceCodeEnd":1274,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/planner/ExpressionInterpreter.java#L1238-L1274","documentation":"Subscript ([]) on a ROW value is evaluated manually; it throws INVALID_FUNCTION_ARGUMENT when the 1-based index is outside the row's field count. Row subscripts must be between 1 and the number of fields.","triggerScenarios":"Evaluating row_col[i] where i < 1 or i > number of row fields during constant folding or non-vectorized expression evaluation.","commonSituations":"Dynamic indexes computed from data that can exceed the row arity, off-by-one mistakes (index 0), or empty-row edge cases in UDF-generated values.","solutions":["Validate the subscript is within 1..cardinality(row) before applying it.","Use a CASE/TRY expression to guard out-of-range indexes.","Fix off-by-one index computation (Presto ROW subscripts are 1-based)."],"exampleFix":"// before\nSELECT r[2] FROM t;\n// after\nSELECT IF(cardinality(r) >= 2, r[2], NULL) FROM t;","handlingStrategy":"validation","validationCode":"if (index < 1 || index > cardinality(rowValue)) { return null; } // 1-based ROW subscript check","typeGuard":"boolean inRowRange(int index, int positionCount) { return index >= 1 && index <= positionCount; }","tryCatchPattern":"try { return exprInterpreter.evaluate(rowSubscriptExpr, context); } catch (PrestoException e) { if (e.getErrorCode() == StandardErrorCode.INVALID_FUNCTION_ARGUMENT.toErrorCode()) { return null; } throw e; }","preventionTips":["Remember ROW subscripts are 1-based","Guard dynamic subscripts with cardinality() checks","Wrap risky expressions in TRY() in SQL"],"tags":["row","subscript","index-out-of-bounds"],"backgroundTag":"index-out-of-bounds","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"}