Geocoder function working

This commit is contained in:
Yam ZhengLim
2023-05-21 01:31:57 +00:00
parent 382b8d5866
commit 1df446e6d2
+8 -16
View File
@@ -1,21 +1,13 @@
-- This block of code returns the entire json
-- select
-- ADDRESS_LINE_ONE,
-- ADDRESS_LINE_TWO,
-- {{ address_to_coordinates( 'ADDRESS_LINE_ONE', 'ADDRESS_LINE_TWO', 'POSTCODE', 'DISTRICT_NAME', 'STATE_NAME' ) }} as output_1
-- from {{ ref('test_address__mock_data') }};
-- This block of code returns the latitude, longitude, metadata, every data column
-- Fix why this block return 289 rows instead of 17 rows?
WITH json_data AS (
SELECT PARSE_JSON( {{ address_to_coordinates( 'ADDRESS_LINE_ONE', 'ADDRESS_LINE_TWO', 'POSTCODE', 'DISTRICT_NAME', 'STATE_NAME' ) }} ) AS response
WITH geocoded AS (
SELECT
*,
PARSE_JSON( {{ address_to_coordinates( 'ADDRESS_LINE_ONE', 'ADDRESS_LINE_TWO', 'POSTCODE', 'DISTRICT_NAME', 'STATE_NAME' ) }} ) AS METADATA
from {{ ref('test_address__mock_data') }}
)
SELECT
response[0]:geometry:location:lat::float AS LATITUDE,
response[0]:geometry:location:lng::float AS LONGITUDE,
response AS METADATA,
t.*
FROM json_data
CROSS JOIN {{ ref('test_address__mock_data') }} AS t;
METADATA[0]:geometry:location:lat::float AS LATITUDE,
METADATA[0]:geometry:location:lng::float AS LONGITUDE,
*
FROM geocoded;