prestodb/presto · error · PrestoException
INVALID_FUNCTION_ARGUMENT
INVALID_FUNCTION_ARGUMENT
Error message
Latitude must be between -90 and 90
What it means
SphericalGeographyUtils.checkLatitude validates that a latitude value is a finite number within [-90, 90] before any spherical computation. NaN, infinity, or out-of-range latitudes are meaningless on a sphere, so the library rejects them with INVALID_FUNCTION_ARGUMENT.
Source
Thrown at presto-geospatial-toolkit/src/main/java/com/facebook/presto/geospatial/SphericalGeographyUtils.java:50
import static java.lang.String.format;
public class SphericalGeographyUtils
{
public static final double EARTH_RADIUS_KM = 6371.01;
public static final double EARTH_RADIUS_M = EARTH_RADIUS_KM * 1000.0;
private static final float MIN_LATITUDE = -90;
private static final float MAX_LATITUDE = 90;
private static final float MIN_LONGITUDE = -180;
private static final float MAX_LONGITUDE = 180;
private static final Joiner OR_JOINER = Joiner.on(" or ");
private static final Set<GeometryType> ALLOWED_SPHERICAL_DISTANCE_TYPES = EnumSet.of(POINT);
private SphericalGeographyUtils() {}
public static void checkLatitude(double latitude)
{
if (Double.isNaN(latitude) || Double.isInfinite(latitude) || latitude < MIN_LATITUDE || latitude > MAX_LATITUDE) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Latitude must be between -90 and 90");
}
}
public static void checkLongitude(double longitude)
{
if (Double.isNaN(longitude) || Double.isInfinite(longitude) || longitude < MIN_LONGITUDE || longitude > MAX_LONGITUDE) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Longitude must be between -180 and 180");
}
}
public static Double sphericalDistance(OGCGeometry leftGeometry, OGCGeometry rightGeometry)
{
if (leftGeometry.isEmpty() || rightGeometry.isEmpty()) {
return null;
}
validateSphericalType("ST_Distance", leftGeometry, ALLOWED_SPHERICAL_DISTANCE_TYPES);
validateSphericalType("ST_Distance", rightGeometry, ALLOWED_SPHERICAL_DISTANCE_TYPES);View on GitHub (pinned to 55bb57d202)
Solutions
- Check argument order; ensure latitude is the first/lat column and not swapped with longitude.
- Filter rows: WHERE latitude BETWEEN -90 AND 90 AND NOT is_nan(latitude).
- Clamp or reject out-of-range values at ingestion time.
- Cast properly — text 'NaN' parsed to double yields NaN.
Example fix
// before SELECT ST_Distance(ST_Point(lon, lat), ST_Point(lon2, lat2)) FROM t; // after SELECT ST_Distance(ST_Point(lon, lat), ST_Point(lon2, lat2)) FROM t WHERE lat BETWEEN -90 AND 90 AND lat2 BETWEEN -90 AND 90 AND NOT is_nan(lat) AND NOT is_nan(lat2);
Defensive patterns
Strategy: validation
Validate before calling
SELECT * FROM t WHERE lat IS NOT NULL AND NOT is_nan(lat) AND lat BETWEEN -90 AND 90;
Type guard
boolean isValidLatitude(double lat) { return !Double.isNaN(lat) && !Double.isInfinite(lat) && lat >= -90.0 && lat <= 90.0; } Try / catch
try { distance = ST_Distance(g1, g2); } catch (PrestoException e) { if ("INVALID_FUNCTION_ARGUMENT".equals(e.getErrorCode().getName())) { log.error("bad latitude"); return null; } throw e; } Prevention
- Validate lat/lon ranges in ETL before loading.
- Never swap latitude and longitude column order.
- Use NULL, not NaN/999, for missing coordinates.
- Add CHECK-style filters in queries touching geospatial functions.
When it happens
Trigger: Calling spherical functions (e.g. ST_Distance on SphericalGeography, greatCircleDistance) with latitude < -90, > 90, NaN, or ±Infinity — usually from bad input columns or wrong argument order (lat/lon swapped).
Common situations: Swapped latitude/longitude columns (longitude up to 180 fails the ±90 check), data with missing values encoded as 999 or 0-degree artifacts, CSV imports producing NaN.
Related errors
- Invalid value [%s]. Valid values: %s
- CLICKHOUSE_QUERY_GENERATOR_FAILURE
- Invalid token URI:
- Invalid offset minutes %s
- DRUID_QUERY_GENERATOR_FAILURE
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/6cdd12cd8a00e489.
Report an issue: GitHub.