prestodb/presto · error · PrestoException
INVALID_FUNCTION_ARGUMENT
INVALID_FUNCTION_ARGUMENT
Error message
e.getMessage()
What it means
JtsGeometrySerde.deserialize catches JTS TopologyException while reading a geometry from the serialized slice and rethrows it as INVALID_FUNCTION_ARGUMENT with the original message. A TopologyException indicates the geometry's coordinates form an invalid topological structure during decoding/processing.
Source
Thrown at presto-geospatial-toolkit/src/main/java/com/facebook/presto/geospatial/serde/JtsGeometrySerde.java:64
public class JtsGeometrySerde
{
// TODO: Are we sure this is thread safe?
private static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory();
private JtsGeometrySerde() {}
public static Geometry deserialize(Slice shape)
{
requireNonNull(shape, "shape is null");
BasicSliceInput input = shape.getInput();
verify(input.available() > 0);
GeometrySerializationType type = GeometrySerializationType.getForCode(input.readByte());
try {
return readGeometry(input, type);
}
catch (TopologyException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);
}
}
private static Geometry readGeometry(BasicSliceInput input, GeometrySerializationType type)
{
switch (type) {
case POINT:
return readPoint(input);
case MULTI_POINT:
return readMultiPoint(input);
case LINE_STRING:
return readPolyline(input, false);
case MULTI_LINE_STRING:
return readPolyline(input, true);
case POLYGON:
return readPolygon(input, false);
case MULTI_POLYGON:
return readPolygon(input, true);View on GitHub (pinned to 55bb57d202)
Solutions
- Repair the geometry before loading: use ST_Buffer(geom, 0) trick or upstream makeValid tooling to fix topology.
- Inspect the offending WKT with ST_GeometryType/ST_AsText and fix invalid rings manually.
- Re-export the data with snapping/precision fixes (e.g. reduce coordinate jitter).
- Quarantine failing rows and process them individually.
Example fix
// before SELECT * FROM t WHERE ST_Contains(boundary, pt); -- boundary has invalid topology // after SELECT * FROM t WHERE ST_Contains(ST_Buffer(boundary, 0), pt); -- repaired geometry
Defensive patterns
Strategy: validation
Validate before calling
-- detect invalid topology before querying SELECT * FROM t WHERE TRY(ST_Buffer(geom, 0)) IS NULL; -- flags topologically invalid geometries
Type guard
boolean isTopologicallyValid(Object geom) { try { jtsGeom(geom).isValid(); return true; } catch (Exception e) { return false; } } Try / catch
try { result = ST_Contains(geom, pt); } catch (PrestoException e) { if ("INVALID_FUNCTION_ARGUMENT".equals(e.getErrorCode().getName())) { return ST_Contains(ST_Buffer(geom, 0), pt); } throw e; } Prevention
- Run makeValid/ST_Buffer(geom,0) repair on imported GIS data.
- Snap/reduce coordinate precision for fragile geometries.
- Validate topology in the producing GIS tool before export.
- Quarantine invalid rows during ETL.
When it happens
Trigger: Deserializing a geometry whose coordinates trigger a JTS topological inconsistency (e.g. self-intersecting structures encountered during validation, degenerate rings) from a geometry column or function argument.
Common situations: Geometries imported from tools that tolerate invalid topology (overlapping rings, spikes), datasets with precision-reduced coordinates, self-intersecting polygons from upstream GIS software.
Related errors
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/0216c84254fdb62c.
Report an issue: GitHub.