@SuppressWarnings("MethodMayBeStatic")
  @Udf(description = "The 2 input points should be specified as (lat, lon) pairs, measured"
      + " in decimal degrees. An optional fifth parameter allows to specify either \"MI\" (miles)"
      + " or \"KM\" (kilometers) as the desired unit for the output measurement. Default is KM.")
  public Double geoDistance(
      @UdfParameter(description = "The latitude of the first point in decimal degrees.")
        final double lat1,
      @UdfParameter(description = "The longitude of the first point in decimal degrees.")
        final double lon1,
      @UdfParameter(description = "The latitude of the second point in decimal degrees.")
        final double lat2,
      @UdfParameter(description = "The longitude of the second point in decimal degrees.")
        final double lon2,
      @UdfParameter(description = "The units for the return value. Either MILES or KM.")
        final String units
  ) {
    validateLatLonValues(lat1, lon1, lat2, lon2);
    final double chosenRadius = selectEarthRadiusToUse(units);

    final double deltaLat = Math.toRadians(lat2 - lat1);
    final double deltaLon = Math.toRadians(lon2 - lon1);

    final double lat1Radians = Math.toRadians(lat1);
    final double lat2Radians = Math.toRadians(lat2);

    final double a =
        haversin(deltaLat) + haversin(deltaLon) * Math.cos(lat1Radians) * Math.cos(lat2Radians);
    final double distanceInRadians = 2 * Math.asin(Math.sqrt(a));
    return distanceInRadians * chosenRadius;
  }
@Test
  public void shouldFailOutOfBoundsCoordinates() {
    // When:
    final Exception e = assertThrows(
        KsqlFunctionException.class,
        () -> distanceUdf.geoDistance(90.1, -122.1663, -91.5257, -0.1122)
    );

    // Then:
    assertThat(e.getMessage(), containsString(
        "valid latitude values for GeoDistance function are"));
  }