Mirror doesn’t yet support Snowflake as a native sink. Streaming data directly into Snowflake requires an always-on Snowflake warehouse, which is typically far more expensive than batch loading for the same data.Instead, this page outlines how to load data into Snowflake periodically from S3, a cost-effective storage sink that is natively supported by Goldsky and by Snowflake.
What you’ll need
This page outlines the core process with illustrative scripts (using python and SQL); you’ll need to schedule these tasks into an orchestration platform such as Dagster or Airflow to run on your desired schedule. You’ll also need:- AWS Key ID and AWS Secret Key to access your S3 bucket.
- Snowflake account details (account, username, password, database name, warehouse name)
- A Goldsky Mirror pipeline writing the desired data to an S3 bucket.
Write extraction script
1
Install required Python libraries
You will need the
pandas library to handle data and the snowflake-connector-python library to connect to Snowflake. Install them using pip:2
Define AWS credentials
Define your AWS Key ID and AWS Secret Key as variables. These will be used to access your S3 bucket.
3
Write SQL scripts
Write functions that generate SQL scripts to create a table in Snowflake (if it doesn’t exist) and load data from the S3 bucket into the table.
4
Connect to Snowflake and execute SQL scripts
Connect to Snowflake using the
snowflake.connector.connect function. Then, execute the SQL scripts using the cursor.execute method, and then close the connection.5
Load data from staging table to destination table
You now have the raw data from S3 loaded into Snowflake; but because S3 as a sink is not re-org aware, you’ll need an intermediate step to manage duplicate/stale data. This can be done with a The final line in the code above contains the key de-duplication logic based on id.
QUALIFY statement, depending on your specific situation.For example: