prestodb/presto · error · PrestoException

INVALID_FUNCTION_ARGUMENT

INVALID_FUNCTION_ARGUMENT

Error message

0 is an invalid instance position for array_position.

What it means

Input validation in the three-argument array_position function: the instance parameter tells Presto which matching occurrence to return and is 1-based, so passing 0 is rejected before scanning the array. It fires on array_position(array, element, 0) regardless of the array contents.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/scalar/ArrayPositionWithIndexFunction.java:53

@ScalarFunction("array_position")
public class ArrayPositionWithIndexFunction
{
    protected ArrayPositionWithIndexFunction() {}

    @TypeParameter("T")
    @SqlType(StandardTypes.BIGINT)
    public static long arrayPositionWithIndex(
            @TypeParameter("T") Type type,
            @OperatorDependency(operator = EQUAL, argumentTypes = {"T", "T"}) MethodHandle equalMethodHandle,
            @SqlType("array(T)") Block array,
            @SqlType("T") boolean element,
            @SqlType(StandardTypes.BIGINT) long instance)
    {
        int size = array.getPositionCount();
        int instancesFound = 0;

        if (instance == 0) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "0 is an invalid instance position for array_position.");
        }

        int startIndex = instance > 0 ? 0 : size - 1;
        int stopIndex = instance > 0 ? size : -1;
        int stepSize = instance > 0 ? 1 : -1;
        instance = Math.abs(instance);

        for (int i = startIndex; i != stopIndex; i += stepSize) {
            if (!array.isNull(i)) {
                try {
                    boolean arrayValue = type.getBoolean(array, i);
                    Boolean result = (Boolean) equalMethodHandle.invoke(arrayValue, element);
                    checkNotIndeterminate(result);
                    if (result) {
                        instancesFound++;
                        if (instancesFound == instance) {
                            return i + 1; // result is 1-based (instead of 0)
                        }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Pass an instance value of 1 or greater (or negative to count from the end where supported)
  2. Drop the instance argument entirely to find the first occurrence
  3. Fix generated SQL that binds 0 as the instance parameter
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/scalar/ArrayPositionWithIndexFunction.java:53 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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