diff --git a/analyses/call_eudf_address_to_coordinates.sql b/analyses/call_eudf_address_to_coordinates.sql index bbee7e5..90be833 100644 --- a/analyses/call_eudf_address_to_coordinates.sql +++ b/analyses/call_eudf_address_to_coordinates.sql @@ -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 *, diff --git a/macros/address_to_coordinates.sql b/macros/address_to_coordinates.sql index df1a266..5c8866f 100644 --- a/macros/address_to_coordinates.sql +++ b/macros/address_to_coordinates.sql @@ -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 -%}