For using Response Translator to transform the GeoTAX response, it is required to define the translator function before creating the user defined function.
Precisely GeoTAX Response Translator helps response transformation and makes response according to the user's need.
This is an example that demonstrates the customization you can perform with the GeoTAX-response. In the example below, the function will replace city by city name, in case city is null in the Response.
create or replace function precisely_geotax_response_translator(event object)
returns object
language javascript as
'
var result = [];
for(i=0;i< EVENT.body.data.length;i++) {
let val = EVENT.body.data[i][1];
if(val.result != null && val.result.machedAddress != null && val.result.machedAddress.city == null) {
val.result.machedAddress.city = val.result.machedAddress.cityName;
}
let row = [i, val];
result.push(row);
}
return { "body": { "data" : result } };
';
This example tries to give more flexibility when performing GeoTAX. If you want to provide specific information for Precisely API's GeoTAX, you can use this information.
headers-api-key: It expects DIS API's production environment key.
headers-api-secret: It expects DIS API's production environment secret.
RESPONSE_TRANSLATOR: It expects Response Translator name here which is created earlier.
create or replace external function geotax_address(address object)
returns variant
IMMUTABLE
api_integration = API_INTEGRATION
HEADERS = ('headers-api-key'= '<<DIS API KEY>>', 'headers-api-secret'='<<DIS API SECRET>>')
MAX_BATCH_ROWS = 10
RESPONSE_TRANSLATOR = precisely_geotax_response_translator
as 'https://9a3cydoxrc.execute-api.us-east-1.amazonaws.com/v1/geo-tax-address';Response Translator
With response translators, you can change the format of data received from remote services used by external functions.
When Snowflake receives data from a remote service, Snowflake expects the data to be formatted according to the same rules. However, many remote services expect to handle data in a different format. Response translator converts data from the remote service's native output format to Snowflake's format.
create or replace table geotax_result as
select ID,longitude,latitude,
object_construct(
'addressId', iff(ID is not null, ID,''),
'longitude', longitude ,
'latitude', latitude
) as geotaxObject
, geotax_location(geotaxObject)
as geotaxResponse from GEOTAX_LOCATIONS order by longitude, latitude;