prestodb/presto · error · PrestoException

GENERIC_INTERNAL_ERROR

GENERIC_INTERNAL_ERROR

Error message

Mixing spherical and euclidean geometric types

What it means

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.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/planner/LocalExecutionPlanner.java:2185

            RowExpression updatedJoinFilter = replaceExpression(filter, ImmutableMap.of(expression, TRUE_CONSTANT));
            return updatedJoinFilter == TRUE_CONSTANT ? Optional.empty() : Optional.of(updatedJoinFilter);
        }

        private SpatialPredicate spatialTest(CallExpression functionCall, boolean probeFirst, Optional<OperatorType> comparisonOperator)
        {
            FunctionMetadata functionMetadata = metadata.getFunctionAndTypeManager().getFunctionMetadata(functionCall.getFunctionHandle());
            QualifiedObjectName functionName = functionMetadata.getName();
            List<TypeSignature> argumentTypes = functionMetadata.getArgumentTypes();
            Predicate<TypeSignature> isSpherical = (typeSignature)
                    -> typeSignature.equals(SPHERICAL_GEOGRAPHY_TYPE_SIGNATURE);
            if (argumentTypes.stream().allMatch(isSpherical)) {
                return sphericalSpatialTest(functionName, comparisonOperator);
            }
            else if (argumentTypes.stream().noneMatch(isSpherical)) {
                return euclideanSpatialTest(functionName, comparisonOperator, probeFirst);
            }
            else {
                throw new PrestoException(GENERIC_INTERNAL_ERROR, "Mixing spherical and euclidean geometric types");
            }
        }

        private SpatialPredicate euclideanSpatialTest(QualifiedObjectName functionName, Optional<OperatorType> comparisonOperator, boolean probeFirst)
        {
            if (functionName.equals(ST_CONTAINS)) {
                if (probeFirst) {
                    return (buildGeometry, probeGeometry, radius) -> probeGeometry.contains(buildGeometry);
                }
                else {
                    return (buildGeometry, probeGeometry, radius) -> buildGeometry.contains(probeGeometry);
                }
            }
            if (functionName.equals(ST_WITHIN)) {
                if (probeFirst) {
                    return (buildGeometry, probeGeometry, radius) -> probeGeometry.within(buildGeometry);
                }
                else {

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Use to_spherical_geog(to_geometry(...)) to convert euclidean geometries to spherical
  2. Apply consistent geometry types on both sides of the ST_ predicate
  3. Avoid mixing ST_Distance-style euclidean calls with great-circle distance functions in one join
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/planner/LocalExecutionPlanner.java:2185 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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