Skip to content

Commit

Permalink
make implementation with pow() default
Browse files Browse the repository at this point in the history
  • Loading branch information
bastienboutonnet committed Mar 14, 2021
1 parent a292695 commit 05b2eb7
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions macros/geo/haversine_distance.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ The arguments should be float type.
{{ return(adapter.dispatch('haversine_distance', packages = dbt_utils._get_utils_namespaces())(lat1,lon1,lat2,lon2,unit)) }}
{% endmacro %}

{% macro default__haversine_distance(lat1,lon1,lat2,lon2,unit) -%}
{# vanilla macro is in miles #}
{% set conversion_rate = '' %}
{% if unit == 'km' %}
{# we multiply miles result to get it in kms #}
{% set conversion_rate = '* 1.60934' %}
{% endif %}
{# {% macro default__haversine_distance(lat1,lon1,lat2,lon2,unit) -%} #}
vanilla macro is in miles
{# {% set conversion_rate = '' %} #}
{# {% if unit == 'km' %} #}
we multiply miles result to get it in kms
{# {% set conversion_rate = '* 1.60934' %} #}
{# {% endif %} #}

2 * 3961 * asin(sqrt((sin(radians(({{lat2}} - {{lat1}}) / 2))) ^ 2 +
cos(radians({{lat1}})) * cos(radians({{lat2}})) *
(sin(radians(({{lon2}} - {{lon1}}) / 2))) ^ 2)) {{conversion_rate}}
{# 2 * 3961 * asin(sqrt((sin(radians(({{lat2}} - {{lat1}}) / 2))) ^ 2 + #}
{# cos(radians({{lat1}})) * cos(radians({{lat2}})) * #}
{# (sin(radians(({{lon2}} - {{lon1}}) / 2))) ^ 2)) {{conversion_rate}} #}

{%- endmacro %}
{# {%- endmacro %} #}

{% macro snowflake__haversine_distance(lat1,lon1,lat2,lon2,unit) -%}
{% macro default__haversine_distance(lat1,lon1,lat2,lon2,unit) -%}
{# vanilla macro is in miles #}
{% set conversion_rate = '' %}
{% if unit == 'km' %}
Expand Down

0 comments on commit 05b2eb7

Please sign in to comment.