{"record":{"id":"eb60208ee250b1d8","repo":"prestodb/presto","slug":"generic-internal-error-eb6020","errorCode":"GENERIC_INTERNAL_ERROR","errorMessage":"Mixing spherical and euclidean geometric types","messagePattern":"Mixing spherical and euclidean geometric types","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/planner/LocalExecutionPlanner.java","lineNumber":2185,"sourceCode":"            RowExpression updatedJoinFilter = replaceExpression(filter, ImmutableMap.of(expression, TRUE_CONSTANT));\n            return updatedJoinFilter == TRUE_CONSTANT ? Optional.empty() : Optional.of(updatedJoinFilter);\n        }\n\n        private SpatialPredicate spatialTest(CallExpression functionCall, boolean probeFirst, Optional<OperatorType> comparisonOperator)\n        {\n            FunctionMetadata functionMetadata = metadata.getFunctionAndTypeManager().getFunctionMetadata(functionCall.getFunctionHandle());\n            QualifiedObjectName functionName = functionMetadata.getName();\n            List<TypeSignature> argumentTypes = functionMetadata.getArgumentTypes();\n            Predicate<TypeSignature> isSpherical = (typeSignature)\n                    -> typeSignature.equals(SPHERICAL_GEOGRAPHY_TYPE_SIGNATURE);\n            if (argumentTypes.stream().allMatch(isSpherical)) {\n                return sphericalSpatialTest(functionName, comparisonOperator);\n            }\n            else if (argumentTypes.stream().noneMatch(isSpherical)) {\n                return euclideanSpatialTest(functionName, comparisonOperator, probeFirst);\n            }\n            else {\n                throw new PrestoException(GENERIC_INTERNAL_ERROR, \"Mixing spherical and euclidean geometric types\");\n            }\n        }\n\n        private SpatialPredicate euclideanSpatialTest(QualifiedObjectName functionName, Optional<OperatorType> comparisonOperator, boolean probeFirst)\n        {\n            if (functionName.equals(ST_CONTAINS)) {\n                if (probeFirst) {\n                    return (buildGeometry, probeGeometry, radius) -> probeGeometry.contains(buildGeometry);\n                }\n                else {\n                    return (buildGeometry, probeGeometry, radius) -> buildGeometry.contains(probeGeometry);\n                }\n            }\n            if (functionName.equals(ST_WITHIN)) {\n                if (probeFirst) {\n                    return (buildGeometry, probeGeometry, radius) -> probeGeometry.within(buildGeometry);\n                }\n                else {","sourceCodeStart":2167,"sourceCodeEnd":2203,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/planner/LocalExecutionPlanner.java#L2167-L2203","documentation":"Planning error from spatial join planning (spatialTest in LocalExecutionPlanner): the join mixed spherical geometry types (e.g. spherical geospatial functions/types) with euclidean (flat-plane) geometry types in the same predicate. The two families use incompatible coordinate semantics and cannot be compared or joined together.","triggerScenarios":"Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/planner/LocalExecutionPlanner.java:2185 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use to_spherical_geog(to_geometry(...)) to convert euclidean geometries to spherical","Apply consistent geometry types on both sides of the ST_ predicate","Avoid mixing ST_Distance-style euclidean calls with great-circle distance functions in one join"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}