{"record":{"id":"0a8256200eed4870","repo":"prestodb/presto","slug":"invalid-function-argument-0a8256","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"Invalid input to %s: null at index %s","messagePattern":"Invalid input to (.+?): null at index (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/geospatial/GeoFunctions.java","lineNumber":196,"sourceCode":"    public static Slice stMultiPoint(@SqlType(\"array(\" + GEOMETRY_TYPE_NAME + \")\") Block input)\n    {\n        CoordinateSequence coordinates = readPointCoordinates(input, \"ST_MultiPoint\", false);\n        if (coordinates.size() == 0) {\n            return null;\n        }\n\n        return serialize(createJtsMultiPoint(coordinates));\n    }\n\n    private static CoordinateSequence readPointCoordinates(Block input, String functionName, boolean forbidDuplicates)\n    {\n        PackedCoordinateSequenceFactory coordinateSequenceFactory = new PackedCoordinateSequenceFactory();\n        double[] coordinates = new double[2 * input.getPositionCount()];\n        double lastX = Double.NaN;\n        double lastY = Double.NaN;\n        for (int i = 0; i < input.getPositionCount(); i++) {\n            if (input.isNull(i)) {\n                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format(\"Invalid input to %s: null at index %s\", functionName, i + 1));\n            }\n\n            BasicSliceInput slice = new BasicSliceInput(GEOMETRY.getSlice(input, i));\n            GeometrySerializationType type = GeometrySerializationType.getForCode(slice.readByte());\n            if (type != GeometrySerializationType.POINT) {\n                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));\n            }\n\n            double x = slice.readDouble();\n            double y = slice.readDouble();\n\n            if (Double.isNaN(x) || Double.isNaN(x)) {\n                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format(\"Invalid input to %s: empty point at index %s\", functionName, i + 1));\n            }\n            if (forbidDuplicates && x == lastX && y == lastY) {\n                throw new PrestoException(INVALID_FUNCTION_ARGUMENT,\n                        format(\"Invalid input to %s: consecutive duplicate points at index %s\", functionName, i + 1));\n            }","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/geospatial/GeoFunctions.java#L178-L214","documentation":"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.","triggerScenarios":"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.","commonSituations":"Arrays assembled from sparse sensor/GPS data with missing fixes; filter() not applied to remove nulls before aggregation; schema changes introducing nullable geometry columns.","solutions":["Remove NULL elements before calling: filter(arr, x -> x IS NOT NULL).","Use COALESCE to substitute a default point where appropriate.","Use TRY(...) if nulls are expected and should yield NULL results.","Fix upstream ETL so geometry arrays never contain NULL entries."],"exampleFix":"// before (SQL)\nSELECT st_makeline(points) FROM t;\n// after\nSELECT st_makeline(filter(points, p -> p IS NOT NULL)) FROM t;","handlingStrategy":"validation","validationCode":"-- SQL\nSELECT st_makeline(filter(points, p -> p IS NOT NULL)) FROM t;","typeGuard":null,"tryCatchPattern":"-- SQL\nSELECT TRY(st_makeline(points)) FROM t;","preventionTips":["Filter NULL elements from geometry arrays before point functions","Use COALESCE for replaceable missing points","Enforce NOT NULL on geometry columns at ingestion"],"tags":["presto","geospatial","geometry","null-handling","sql"],"backgroundTag":"null-geometry-input","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"}