-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit argument to haversine distnace macro, and apply conversion f…
…or kms (#340)
- Loading branch information
1 parent
049974c
commit f4ef848
Showing
9 changed files
with
124 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lat_1,lon_1,lat_2,lon_2,output | ||
48.864716,2.349014,52.379189,4.899431,430 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lat_1,lon_1,lat_2,lon_2,output | ||
48.864716,2.349014,52.379189,4.899431,267 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: test_haversine_distance_km | ||
tests: | ||
- assert_equal: | ||
actual: actual | ||
expected: expected | ||
- name: test_haversine_distance_mi | ||
tests: | ||
- assert_equal: | ||
actual: actual | ||
expected: expected |
23 changes: 23 additions & 0 deletions
23
integration_tests/models/geo/test_haversine_distance_km.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
with data as ( | ||
select * from {{ ref('data_haversine_km') }} | ||
), | ||
final as ( | ||
select | ||
output as expected, | ||
cast( | ||
{{ | ||
dbt_utils.haversine_distance( | ||
lat1='lat_1', | ||
lon1='lon_1', | ||
lat2='lat_2', | ||
lon2='lon_2', | ||
unit='km' | ||
) | ||
}} as numeric | ||
) as actual | ||
from data | ||
) | ||
select | ||
expected, | ||
round(actual,0) as actual | ||
from final |
39 changes: 39 additions & 0 deletions
39
integration_tests/models/geo/test_haversine_distance_mi.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
with data as ( | ||
select * from {{ ref('data_haversine_mi') }} | ||
), | ||
final as ( | ||
select | ||
output as expected, | ||
cast( | ||
{{ | ||
dbt_utils.haversine_distance( | ||
lat1='lat_1', | ||
lon1='lon_1', | ||
lat2='lat_2', | ||
lon2='lon_2', | ||
unit='mi' | ||
) | ||
}} as numeric | ||
) as actual | ||
from data | ||
|
||
union all | ||
|
||
select | ||
output as expected, | ||
cast( | ||
{{ | ||
dbt_utils.haversine_distance( | ||
lat1='lat_1', | ||
lon1='lon_1', | ||
lat2='lat_2', | ||
lon2='lon_2', | ||
) | ||
}} as numeric | ||
) as actual | ||
from data | ||
) | ||
select | ||
expected, | ||
round(actual,0) as actual | ||
from final |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters