{"record":{"id":"0216c84254fdb62c","repo":"prestodb/presto","slug":"invalid-function-argument-0216c8","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"e.getMessage()","messagePattern":"e\\.getMessage\\(\\)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-geospatial-toolkit/src/main/java/com/facebook/presto/geospatial/serde/JtsGeometrySerde.java","lineNumber":64,"sourceCode":"\npublic class JtsGeometrySerde\n{\n    // TODO: Are we sure this is thread safe?\n    private static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory();\n\n    private JtsGeometrySerde() {}\n\n    public static Geometry deserialize(Slice shape)\n    {\n        requireNonNull(shape, \"shape is null\");\n        BasicSliceInput input = shape.getInput();\n        verify(input.available() > 0);\n        GeometrySerializationType type = GeometrySerializationType.getForCode(input.readByte());\n        try {\n            return readGeometry(input, type);\n        }\n        catch (TopologyException e) {\n            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);\n        }\n    }\n\n    private static Geometry readGeometry(BasicSliceInput input, GeometrySerializationType type)\n    {\n        switch (type) {\n            case POINT:\n                return readPoint(input);\n            case MULTI_POINT:\n                return readMultiPoint(input);\n            case LINE_STRING:\n                return readPolyline(input, false);\n            case MULTI_LINE_STRING:\n                return readPolyline(input, true);\n            case POLYGON:\n                return readPolygon(input, false);\n            case MULTI_POLYGON:\n                return readPolygon(input, true);","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-geospatial-toolkit/src/main/java/com/facebook/presto/geospatial/serde/JtsGeometrySerde.java#L46-L82","documentation":"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.","triggerScenarios":"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.","commonSituations":"Geometries imported from tools that tolerate invalid topology (overlapping rings, spikes), datasets with precision-reduced coordinates, self-intersecting polygons from upstream GIS software.","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."],"exampleFix":"// before\nSELECT * FROM t WHERE ST_Contains(boundary, pt); -- boundary has invalid topology\n// after\nSELECT * FROM t WHERE ST_Contains(ST_Buffer(boundary, 0), pt); -- repaired geometry","handlingStrategy":"validation","validationCode":"-- detect invalid topology before querying\nSELECT * FROM t WHERE TRY(ST_Buffer(geom, 0)) IS NULL; -- flags topologically invalid geometries","typeGuard":"boolean isTopologicallyValid(Object geom) { try { jtsGeom(geom).isValid(); return true; } catch (Exception e) { return false; } }","tryCatchPattern":"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; }","preventionTips":["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."],"tags":["geospatial","topology","serialization"],"backgroundTag":"geometry-deserialization-failed","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"}