Snowflake

Snowflake is a managed cloud Data Warehousing platform. It separates compute and storage resources, providing a managed data infrastructure that automatically scales based on needs.

Snowflake is cross-cloud compatible. Meaning you can choose to host on any of the cloud providers such as AWS, GCP, and Microsoft Azure.

Snowflake processes both structured and semi-structured data, supporting formats such as JSON, Avro, Parquet, and XML. Additionally, it adheres to standards like SQL and ACID transactions.

The platform is compatible with leading business intelligence tools, including Tableau, Looker, and PowerBI. Additionally, Snowflake accommodates various programming and scripting languages.

Snowflake emphasizes data security. It incorporates enterprise-grade encryption for data at rest and in transit. Other features include multi-factor authentication and granular access controls.


Setup Guide

New to Snowflake? No worries, in order to use Weld with Snowflake, you just need to know the basics. Here is a good place to start: https://docs.snowflake.com/en/user-guide-getting-started.html

Weld needs its own Snowflake user, with its own role set as the user's default role. Weld only looks at the privileges of that default role (and the roles granted to it), so grants to any other role do not count. Creating a dedicated user and role also makes sure Weld can only access what it needs.

Weld writes to two databases:

  • WELD_LANDING, where syncs land their tables
  • WELD_MODELS, where Weld creates your models

Setting up takes three steps:

  1. Generate a key pair on your own machine.
  2. Create the role, the user (with your public key), the databases and the grants, either with the setup script or manually.
  3. Connect Snowflake in Weld with the user name and the private key.

Key-Pair Authentication

Generate a key pair

1. Generate a private key. An encrypted key is recommended:

Encrypted (recommended)

openssl genrsa 2048 | openssl pkcs8 -topk8 -v2 aes256 -inform PEM -out rsa_key.p8

OpenSSL asks for a passphrase. Keep it, you enter it in Weld together with the key.

Unencrypted (not recommended for production use)

openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -out rsa_key.p8 -nocrypt

2. Generate the public key from the private key:

openssl rsa -in rsa_key.p8 -pubout -out rsa_key.pub

3. Print the public key on one line, without the -----BEGIN PUBLIC KEY----- and -----END PUBLIC KEY----- lines. This is the value you paste into Snowflake in the next step:

grep -v "PUBLIC KEY" rsa_key.pub | tr -d '\n'

Store both files securely. The public key goes into Snowflake, the private key rsa_key.p8 goes into Weld, and it should never be shared anywhere else.


Setting Up - The Fast and Easy Way

Want to run all commands yourself? Skip ahead to Setting Up - The Manual Way.

The script below creates the databases, the role and the user, assigns your public key to the user, and grants the role what Weld needs. It is safe to run again: everything is created with if not exists, and repeating a grant changes nothing.

It switches between two system roles, so run it as a user that has been granted both SYSADMIN and SECURITYADMIN (an ACCOUNTADMIN user has both):

  • SYSADMIN creates the two databases.
  • SECURITYADMIN creates the role and the user, and grants the privileges.

1. In Snowsight, create a new SQL worksheet.

2. Paste in the script:

Snowflake set-up script

-- Weld setup for Snowflake as a data warehouse, with key-pair authentication.
-- Object names must be upper case.

-- Paste your public key: the base64 text between the BEGIN and END PUBLIC KEY lines of rsa_key.pub
set public_key = '<PUBLIC_KEY>';

set user_weld = 'WELD_USER';
set role_weld = 'WELD_ROLE';
set warehouse_name = 'COMPUTE_WH';

-- Weld writes to these two databases, keep the names
set database_landing = 'WELD_LANDING';
set database_models = 'WELD_MODELS';

-- SYSADMIN: create the databases
use role sysadmin;

create database if not exists identifier($database_landing);
create database if not exists identifier($database_models);

-- SECURITYADMIN: create the role and the user, and grant privileges
use role securityadmin;

create role if not exists identifier($role_weld);

create user if not exists identifier($user_weld)
  rsa_public_key = $public_key
  default_role = $role_weld
  type = 'SERVICE';

grant role identifier($role_weld) to user identifier($user_weld);

grant usage on warehouse identifier($warehouse_name) to role identifier($role_weld);

grant create schema, usage
  on database identifier($database_landing)
  to role identifier($role_weld);

grant create schema, usage
  on database identifier($database_models)
  to role identifier($role_weld);

grant create table, create view, usage
  on future schemas in database identifier($database_landing)
  to role identifier($role_weld);

grant create table, create view, usage
  on future schemas in database identifier($database_models)
  to role identifier($role_weld);

3. Replace <PUBLIC_KEY> on the first set line with the one-line public key from step 3 of the key pair. If your warehouse is not called COMPUTE_WH, change warehouse_name too.

4. Select the entire script and click Run.

Done? Skip ahead to Where's my credentials? and connect Snowflake in Weld.


Setting Up - The Manual Way

Run these statements yourself if you want to see each step, or change them to fit your account. Replace WELD_ROLE, WELD_USER and COMPUTE_WH if you use other names, and <PUBLIC_KEY> with the one-line public key from step 3 of the key pair.

1. Create the two databases as SYSADMIN. Skip this if they already exist.

use role sysadmin;

create database if not exists WELD_LANDING;
create database if not exists WELD_MODELS;

2. Create the role, and the user with your public key and the role as its default role, as SECURITYADMIN. Then grant the role to the user.

use role securityadmin;

create role if not exists WELD_ROLE;

create user if not exists WELD_USER
  rsa_public_key = '<PUBLIC_KEY>'
  default_role = WELD_ROLE
  type = 'SERVICE';

grant role WELD_ROLE to user WELD_USER;

If the user already exists, assign the key and the default role with alter user WELD_USER set rsa_public_key = '<PUBLIC_KEY>' default_role = WELD_ROLE;.

3. Still as SECURITYADMIN, let the role use the warehouse:

grant usage on warehouse COMPUTE_WH to role WELD_ROLE;

4. Still as SECURITYADMIN, grant the role access to both databases, and to the schemas Weld will create in them:

grant create schema, usage on database WELD_LANDING to role WELD_ROLE;
grant create schema, usage on database WELD_MODELS to role WELD_ROLE;

grant create table, create view, usage on future schemas in database WELD_LANDING to role WELD_ROLE;
grant create table, create view, usage on future schemas in database WELD_MODELS to role WELD_ROLE;

Granting on future schemas needs the MANAGE GRANTS privilege, which SECURITYADMIN has.

You are now all set up. Continue to Where's my credentials? and connect Snowflake in Weld.


Troubleshooting

When you save the connection, Weld signs in as the user and checks the grants of its default role. These are the errors it can show, and how to fix them.

Your default role must have "CREATE DATABASE" privilege

Missing privileges for WELD_USER. Your default role must have "CREATE DATABASE" privilege. Consult our setup guide for more information.

Weld cannot see WELD_LANDING or WELD_MODELS with the user's default role, and that role is not allowed to create them. Either the databases do not exist yet, or the role has no grants on them.

Create the databases and grant the role access to them, as in the setup script or steps 1 and 4 of the manual way.

Also check that the role you granted to is really the user's default role: describe user WELD_USER; should show WELD_ROLE as DEFAULT_ROLE.

Privilege Error … is lacking the following privileges

Privilege Error for WELD_USER in <account>. WELD_ROLE is lacking the following privileges: ["CREATE SCHEMA on WELD_MODELS","CREATE TABLE on WELD_MODELS.<SCHEMA>","CREATE VIEW on WELD_MODELS.<SCHEMA>"]

The databases exist, but they are owned by another role and the default role is missing grants on them. <SCHEMA> stands for future schemas: Weld creates its own schemas, so it needs the privileges on schemas that do not exist yet. Either:

  • Run the grants from step 4 of the manual way for each database in the error. Only the on future schemas grants satisfy the check, grants on existing schemas do not. Or

  • Make the role the owner of the databases, which covers all of the above:

    use role securityadmin;
    grant ownership on database WELD_LANDING to role WELD_ROLE copy current grants;
    grant ownership on database WELD_MODELS to role WELD_ROLE copy current grants;
    

Missing Warehouse

Missing Warehouse "COMPUTE_WH"

The default role cannot see the warehouse. Grant it with grant usage on warehouse COMPUTE_WH to role WELD_ROLE;, and enter the warehouse name in Weld in upper case, exactly as Snowflake lists it.


Identifier casing

Snowflake resolves an unquoted identifier to its upper-case form, and Weld quotes every name it writes. A table created as "orders" is therefore genuinely lower case, and every query against it has to stay quoted:

select "id" from "hubspot"."orders"   -- works
select id from hubspot.orders          -- fails, this looks for HUBSPOT.ORDERS

Turn on Create tables and columns in upper case and Weld creates the schema, table and column names in upper case instead, so you can query them without quoting:

select id from hubspot.orders

You can set it in two places:

  • On the data warehouse, under Advanced when you connect Snowflake, or later on the Data Warehouse settings page. This becomes the default for new syncs.
  • On an individual sync, next to the destination schema name when you create it. This overrides the warehouse default for that sync.

A sync is refused at creation if the casing would collapse two source fields onto the same column, for example a source exposing both id and ID. Rename the fields in the source, or leave the casing off for that sync.


Full syncs into Snowflake are atomic

For a full sync, Weld stages the extracted data into an internal Snowflake stage with the PUT command, then loads it into the destination table with a single COPY INTO statement.

COPY INTO defaults to ON_ERROR = ABORT_STATEMENT, so the statement aborts entirely if anything goes wrong. The destination table is only touched once staging has succeeded, so a failed full sync leaves it exactly as it was.


Where's my credentials?

Account

Can be found in the Account URL in the following format:
https://{account_identifier}.snowflakecomputing.com/

So in case of this URL:
https://ab12345.eu-central-1.snowflakecomputing.com/

You need to provide the following account identifier:
ab12345.eu-central-1

The easiest way to find your Account URL is by going to the Snowflake sign-in page. The URL of the page will be something like this:
https://{account_identifier}.snowflakecomputing.com/...

If you are already logged in to Snowflake (Snowsight UI), hover over your account in the list of the logged in accounts in bottom left corner, then click on the small link icon with the Copy account URL tooltip text.

If you are already logged in to the Classic Console, you should find the account url in the browser URL bar.

Warehouse
The warehouse you granted the role USAGE on, in upper case. The default is COMPUTE_WH.

User name
The user you created. The default is WELD_USER.

Key-pair authentication
Select the private key file rsa_key.p8 you generated, and enter its passphrase if you encrypted it. There is no password: the user is a SERVICE user that signs in with the key.

Something we overlooked?

We are the happiest when you reach out with any comments or questions. It helps us stay in the loop and make the documentation and the product better. Don't hesitate to reach out!

Was this page helpful?