By integrating with Snowflake Streams, Tamr RealTime enables you to capture change and make improvements to the data proactively at the point of entry.
This topic provides an example of integrating Snowflake with the Tamr RealTime API to return a specific record by the record ID.
Step 1: Create a Snowflake Secret
Create a Snowflake Secret to securely store the Tamr Cloud API key. Use a generic string to store an API key.
CREATE OR REPLACE SECRET secret_tamr_cloud__api_key
TYPE = GENERIC_STRING
SECRET_STRING = 'apk_<id>'
COMMENT = 'Tamr Cloud API Key For <my-tenant>.tamr.cloud';
Step 2: Create a Snowflake Network Rule
Create a Snowflake Network Rule allowing outgoing traffic to the hostname of your Tamr Cloud tenant.
CREATE OR REPLACE NETWORK RULE network_rule_tamr_cloud_<my-tenant>_api
TYPE = HOST_PORT
VALUE_LIST = ('<my-tenant>.tamr.cloud:443')
MODE = EGRESS
COMMENT = 'Tamr Cloud <my-tenant>.tamr.cloud Tenant';
Step 3: Create a Snowflake External Access Integration
Create a Snowflake External Access Integration using the above secret and network rule. This step requires an ADMIN privilege.
CREATE OR REPLACE EXTERNAL ACCESS INTEGRATION external_access_integration_tamr_cloud_<my-tenant>_api
ALLOWED_NETWORK_RULES = ('network_rule_tamr_cloud_<my-tenant>_api')
ALLOWED_AUTHENTICATION_SECRETS = ('secret_tamr_cloud_<my-tenant>_api_key')
ENABLED = TRUE
COMMENT = 'External Access Integration Tamr Cloud Api on <my-tenant>.tamr.com';
Step 4: Create a User Defined Function
Create a user defined function to execute the python snippet that calls the Tamr RealTime API.
CREATE OR REPLACE FUNCTION tamr_demo_get_record_by_id_python(table_id STRING, record_id STRING)
RETURNS STRING
LANGUAGE PYTHON
RUNTIME_VERSION = 3.8
HANDLER = 'get_record_by_id'
EXTERNAL_ACCESS_INTEGRATIONS = (external_access_integration_tamr_cloud_<my-tenant>_api)
PACKAGES = ('snowflake-snowpark-python','requests')
SECRETS = ('tamrapikey' = secret_tamr_cloud_<my-tenant>_api_key )
AS
$$
import _snowflake
import requests
import json
session = requests.Session()
def get_record_by_id(table_id: str, record_id: str):
hostname = '<my-tenant>.tamr.cloud'
api_key = _snowflake.get_generic_secret_string('tamrapikey')
url = 'https://{}/api/v1alpha1/tables/{}/records/{}'.format(hostname, table_id, record_id)
response = session.get(url, headers={'Accept': 'application/json', 'X-API-KEY': api_key})
if response.status_code == 404:
return f"Received 404 response code for record id '{record_id}'. Record not found"
if response.status_code != 200:
return "Received non-200 response code '{}'".format(response.status_code)
return response.json()
$$;
Step 5: Get a Record from Tamr RealTime API
Run a Snowflake SQL Select statement to execute the function to get a record from the Tamr RealTime API.
SELECT tamr_get_record_by_id_python('<tbl_id>', '<rec_id>');