prestodb/presto · warning · PrestoException

INVALID_FUNCTION_ARGUMENT

INVALID_FUNCTION_ARGUMENT

Error message

Invalid GeoJSON: 

What it means

GeometryUtils.jtsGeometryFromJson parses a JSON string with GeoJsonReader and converts any ParseException or IllegalArgumentException into INVALID_FUNCTION_ARGUMENT with 'Invalid GeoJSON: <message>'. It signals that the supplied string is not parseable as GeoJSON.

Source

Thrown at presto-geospatial-toolkit/src/main/java/com/facebook/presto/geospatial/GeometryUtils.java:248

        corners.add(new Point(envelope.getXMax(), envelope.getYMax()));

        for (int i = 0; i < 4; i++) {
            Point point = polygon.getPoint(i);
            if (!corners.contains(point)) {
                return false;
            }
        }

        return true;
    }

    public static org.locationtech.jts.geom.Geometry jtsGeometryFromJson(String json)
    {
        try {
            return new GeoJsonReader().read(json);
        }
        catch (ParseException | IllegalArgumentException e) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid GeoJSON: " + e.getMessage(), e);
        }
    }

    public static Optional<String> jsonFromJtsGeometry(org.locationtech.jts.geom.Geometry geometry)
    {
        if (ATOMIC_GEOMETRY_TYPES.contains(geometry.getGeometryType()) && geometry.isEmpty()) {
            return Optional.empty();
        }
        else {
            return Optional.of(new GeoJsonWriter().write(geometry));
        }
    }

    public static org.locationtech.jts.geom.Geometry jtsGeometryFromWkt(String wkt)
    {
        try {
            return new WKTReader(GEOMETRY_FACTORY).read(wkt);
        }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Validate the JSON (e.g. jq or a JSON parser) and confirm it is a GeoJSON geometry object with proper 'type' and 'coordinates'.
  2. Unwrap Feature/FeatureCollection to the underlying geometry before conversion.
  3. Fix coordinate array nesting to match the geometry dimension (Point -> [x,y]; Polygon -> [[ [x,y], ... ]]).

Example fix

// before
SELECT ST_GeomFromGeoJSON('{"type": "Point", "coordinates": 1.0}');
// after
SELECT ST_GeomFromGeoJSON('{"type": "Point", "coordinates": [1.0, 2.0]}');
Defensive patterns

Strategy: validation

Validate before calling

boolean isProbablyGeoJson(String s) {
    try {
        JsonNode n = MAPPER.readTree(s);
        return n.has("type") && n.has("coordinates")
            && List.of("Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon","GeometryCollection")
                   .contains(n.get("type").asText());
    } catch (Exception e) { return false; }
}

Type guard

boolean isGeoJsonObject(String s) {
    return s != null && s.trim().startsWith("{") && s.contains("\"type\"") && s.contains("\"coordinates\"");
}

Try / catch

try {
    Geometry g = GeometryUtils.jtsGeometryFromJson(json);
} catch (PrestoException e) {
    if (e.getErrorCode().equals(INVALID_FUNCTION_ARGUMENT.toErrorCode())) {
        // log e.getMessage() which includes the parser's reason, then fix input
    }
}

Prevention

When it happens

Trigger: Passing malformed JSON, JSON that is valid but not GeoJSON (missing 'type'/'coordinates'), or unsupported geometry types to ST_GeomFromGeoJSON-style functions.

Common situations: Truncated JSON from a stream/ETL; using GeoJSON Feature/FeatureCollection where a bare geometry is required; coordinates with wrong nesting depth; single quotes or unquoted keys in hand-written JSON.

Related errors


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