mirror of
https://gitlab.com/cief-data/dbt_cloud.git
synced 2026-08-19 04:14:00 +00:00
Added comments on address_to_coordinates macro
This commit is contained in:
@@ -1,4 +1,33 @@
|
||||
-- This block of code returns the latitude, longitude, metadata, every data column
|
||||
/*
|
||||
Geocoding addresses and retrieving metadata
|
||||
|
||||
This block of code geocodes addresses by calling an EUDF in Snowflake.
|
||||
It retrieves the latitude, longitude, and metadata for each address from a given table table, along with all the existing data columns.
|
||||
|
||||
Usage:
|
||||
- Uses the `address_to_coordinates` macro defined and stored in /macros folder
|
||||
- Replace `test_address__mock_data` with the name of your actual table.
|
||||
|
||||
Returns:
|
||||
- LATITUDE: FLOAT - The latitude coordinate of the address.
|
||||
- LONGITUDE: FLOAT - The longitude coordinate of the address.
|
||||
- METADATA: VARIANT - The parsed JSON response from the geocoding EUDF.
|
||||
- All existing data columns from the specified table.
|
||||
|
||||
Example:
|
||||
WITH geocoded AS (
|
||||
SELECT
|
||||
*,
|
||||
{{ address_to_coordinates('ADDRESS_LINE_ONE', 'ADDRESS_LINE_TWO', 'POSTCODE', 'DISTRICT_NAME', 'STATE_NAME') }} AS METADATA
|
||||
FROM {{ ref('test_address__mock_data') }}
|
||||
)
|
||||
SELECT
|
||||
METADATA[0]:geometry:location:lat::float AS LATITUDE,
|
||||
METADATA[0]:geometry:location:lng::float AS LONGITUDE,
|
||||
*
|
||||
FROM geocoded;
|
||||
*/
|
||||
|
||||
WITH geocoded AS (
|
||||
SELECT
|
||||
*,
|
||||
|
||||
@@ -1,5 +1,25 @@
|
||||
-- Macro to call EUDF stored in snowflake
|
||||
-- id, created_datetime, updated_datetime, reference, address_1, address_2, postcode, district, state, country
|
||||
/*
|
||||
A macro to convert an address string into a set of geo coordinates.
|
||||
|
||||
It accepts five input parameters representing address components and returns the parsed JSON response from the E-UDF.
|
||||
|
||||
Usage:
|
||||
{{ address_to_coordinates(column1, column2, column3, column4, column5) }}
|
||||
|
||||
Parameters:
|
||||
- column1: VARCHAR or STRING - ADDRESS_LINE_ONE
|
||||
- column2: VARCHAR or STRING - ADDRESS_LINE_TWO
|
||||
- column3: VARCHAR or STRING - POSTCODE
|
||||
- column4: VARCHAR or STRING - DISTRICT_NAME
|
||||
- column5: VARCHAR or STRING - STATE_NAME
|
||||
|
||||
Returns:
|
||||
- VARIANT - A parsed JSON response from the E-UDF, representing metadata from geocoding the address.
|
||||
|
||||
Example:
|
||||
{{ address_to_coordinates('ADDRESS_LINE_ONE', 'ADDRESS_LINE_TWO', 'POSTCODE', 'DISTRICT_NAME', 'STATE_NAME') }}
|
||||
*/
|
||||
|
||||
{%- macro address_to_coordinates(column1, column2, column3, column4, column5) -%}
|
||||
PARSE_JSON( GLOBAL_FUNCTION.EUDF.ECHO_ADDRESS_TO_COORDINATES({{column1}}, {{column2}}, {{column3}}, {{column4}}, {{column5}}) )
|
||||
{%- endmacro -%}
|
||||
|
||||
Reference in New Issue
Block a user