Skip to content

Commit

Permalink
power and pow are synonyms (except in for some dialects) (dbt-labs#354)
Browse files Browse the repository at this point in the history
* power and pow are synonyms (except in TSQL)

* contrib

* power is more crossdb friendly than pow

Co-authored-by: Jeremy Cohen <[email protected]>
  • Loading branch information
dataders and jtcohen6 authored Jun 6, 2021
1 parent a729044 commit 4f08f43
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# dbt-utils Next


# dbt-utils v0.7.0 (unreleased)
## Breaking changes

Expand Down Expand Up @@ -46,6 +49,7 @@ If you were relying on the position to match up your optional arguments, this ma

## Under the hood
* Update the default implementation of concat macro to use `||` operator ([#373](https://github.com/fishtown-analytics/dbt-utils/pull/314) [@ChristopheDuong](https://github.com/ChristopheDuong)). Note this may be a breaking change for spark users.
- Use `power()` instead of `pow()` in `generate_series()` and `haversine_distance()` as they are synonyms in most SQL dialects, but some dialects only have `power()` ([#354](https://github.com/fishtown-analytics/dbt-utils/pull/354) from [@swanderz](https://github.com/swanderz))

# dbt-utils v0.6.6

Expand Down
2 changes: 1 addition & 1 deletion macros/sql/generate_series.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
select

{% for i in range(n) %}
p{{i}}.generated_number * pow(2, {{i}})
p{{i}}.generated_number * power(2, {{i}})
{% if not loop.last %} + {% endif %}
{% endfor %}
+ 1
Expand Down
8 changes: 4 additions & 4 deletions macros/sql/haversine_distance.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ The arguments should be float type.
{{ exceptions.raise_compiler_error("unit input must be one of 'mi' or 'km'. Got " ~ unit) }}
{% endif %}

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

{%- endmacro %}

Expand All @@ -43,9 +43,9 @@ The arguments should be float type.
{% else %}
{{ exceptions.raise_compiler_error("unit input must be one of 'mi' or 'km'. Got " ~ unit) }}
{% endif %}
2 * 3961 * asin(sqrt(pow(sin(({{ radians_lat2 }} - {{ radians_lat1 }}) / 2), 2) +
2 * 3961 * asin(sqrt(power(sin(({{ radians_lat2 }} - {{ radians_lat1 }}) / 2), 2) +
cos({{ radians_lat1 }}) * cos({{ radians_lat2 }}) *
pow(sin(({{ radians_lon2 }} - {{ radians_lon1 }}) / 2), 2))) * {{ conversion_rate }}
power(sin(({{ radians_lon2 }} - {{ radians_lon1 }}) / 2), 2))) * {{ conversion_rate }}

{%- endmacro %}

0 comments on commit 4f08f43

Please sign in to comment.