prestodb/presto · error · PrestoException

INVALID_FUNCTION_ARGUMENT

INVALID_FUNCTION_ARGUMENT

Error message

Invalid input to %s: null at index %s

What it means

readPointCoordinates iterates a GEOMETRY array argument (used by functions like ST_Points/line builders) and reads each element expecting a serialized POINT geometry. A NULL element at any index cannot be interpreted as a point, so Presto throws INVALID_FUNCTION_ARGUMENT naming the function and the 1-based index. The library requires fully non-null, valid point arrays as input.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/geospatial/GeoFunctions.java:196

    public static Slice stMultiPoint(@SqlType("array(" + GEOMETRY_TYPE_NAME + ")") Block input)
    {
        CoordinateSequence coordinates = readPointCoordinates(input, "ST_MultiPoint", false);
        if (coordinates.size() == 0) {
            return null;
        }

        return serialize(createJtsMultiPoint(coordinates));
    }

    private static CoordinateSequence readPointCoordinates(Block input, String functionName, boolean forbidDuplicates)
    {
        PackedCoordinateSequenceFactory coordinateSequenceFactory = new PackedCoordinateSequenceFactory();
        double[] coordinates = new double[2 * input.getPositionCount()];
        double lastX = Double.NaN;
        double lastY = Double.NaN;
        for (int i = 0; i < input.getPositionCount(); i++) {
            if (input.isNull(i)) {
                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to %s: null at index %s", functionName, i + 1));
            }

            BasicSliceInput slice = new BasicSliceInput(GEOMETRY.getSlice(input, i));
            GeometrySerializationType type = GeometrySerializationType.getForCode(slice.readByte());
            if (type != GeometrySerializationType.POINT) {
                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to %s: geometry is not a point: %s at index %s", functionName, type.toString(), i + 1));
            }

            double x = slice.readDouble();
            double y = slice.readDouble();

            if (Double.isNaN(x) || Double.isNaN(x)) {
                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to %s: empty point at index %s", functionName, i + 1));
            }
            if (forbidDuplicates && x == lastX && y == lastY) {
                throw new PrestoException(INVALID_FUNCTION_ARGUMENT,
                        format("Invalid input to %s: consecutive duplicate points at index %s", functionName, i + 1));
            }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Remove NULL elements before calling: filter(arr, x -> x IS NOT NULL).
  2. Use COALESCE to substitute a default point where appropriate.
  3. Use TRY(...) if nulls are expected and should yield NULL results.
  4. Fix upstream ETL so geometry arrays never contain NULL entries.

Example fix

// before (SQL)
SELECT st_makeline(points) FROM t;
// after
SELECT st_makeline(filter(points, p -> p IS NOT NULL)) FROM t;
Defensive patterns

Strategy: validation

Validate before calling

-- SQL
SELECT st_makeline(filter(points, p -> p IS NOT NULL)) FROM t;

Try / catch

-- SQL
SELECT TRY(st_makeline(points)) FROM t;

Prevention

When it happens

Trigger: Calling a function such as st_makeline or st_point aggregation over an array of geometries where at least one element is NULL; arrays built from outer joins or optional columns containing nulls.

Common situations: Arrays assembled from sparse sensor/GPS data with missing fixes; filter() not applied to remove nulls before aggregation; schema changes introducing nullable geometry columns.

Related errors


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