Push to Snowflake
Write Sanda's numbers into a table in your own Snowflake account. Each run merges only the rows whose values changed, and wakes your warehouse only then.
A push to Snowflake writes Sanda's numbers into a table in your own Snowflake account: revenue over the last twelve months for each customer, the overdue balance beside it, the date of their last order. The numbers come from your semantic model, so they mean what your team agreed they mean, and they land in an ordinary Snowflake table that your own queries, dashboards and models read like any other.
It works as every push does (see Push): each run reads the values, writes them the way Snowflake stores them, compares them with what Snowflake last accepted, and sends only the rows whose values changed.
What it costs you in Snowflake
Snowflake charges for a warehouse while it runs, so a push is built to run yours as little as it can:
- Connecting and setting up a push need no warehouse. The check when you connect, the list of tables and each table's columns all come from Snowflake's own records of what the account holds, which Snowflake answers without one.
- A run where nothing changed makes no call to Snowflake. Your warehouse stays asleep.
- A run that has changes writes them in as few statements as it can: one statement for every 5,000 changed rows, on the warehouse you name. The setup script makes an extra-small one that wakes for a write and goes back to sleep a minute later.
To cap what Sanda's writes can cost, give the warehouse a resource monitor in Snowflake. When it suspends the warehouse, a run waits and says so, and the next run carries on once the warehouse can run again.
What it writes
A push writes to one table in the schema its connection names, and finds each row by a key column: a text or whole-number column that is different on every row, such as your customer code. A run updates the row with that key, and adds a row when the table has none. A push never deletes a row, and never clears a column because a row has left the push: that row keeps the values it has.
You don't need to make the table first. A push can send a whole table from your semantic model, and Sanda makes a Snowflake table for it if the schema hasn't one of that name (see send a whole table). A push can also write into a table you made yourself: the setup script's grants cover every table in the schema, including ones you make later. To write into a PostgreSQL database instead, see push to Postgres.
If the table, or a column a push writes, goes missing later (someone dropped it, say), the next run makes it again and carries on, unless you turn that off (see make the table if it isn't there).
Connect Snowflake
Before you start
- Someone who can run an administrator's script in Snowflake. Connecting makes a user, a role and a warehouse for Sanda, which needs the
ACCOUNTADMINrole, or a role that may create users, roles and warehouses and grant on the schema. - A database and schema for Sanda to write to. Pushes write to tables in this one schema. A schema of its own, such as
ANALYTICS.SANDA, keeps what Sanda writes apart from everything else. - Be an owner or admin in Sanda. Only owners and admins connect an account and make a push, because a push writes into Snowflake on the whole workspace's behalf.
Connect an account
- Open Push. In the console, go to Data · Streams · Push.
- Start connecting. Press the Snowflake card under Choose a destination. Connect a Snowflake account opens under the cards, saying who needs to run the setup script. Once an account is connected, the card opens a new push instead: to connect another, press Connected accounts at the right of Choose a destination, then Connect Snowflake in the window it opens.
- Fill in the account. Type the Account identifier, such as
myorg-myaccount: in Snowflake, open your name at the bottom left, then Account, and copy the account identifier, with a hyphen in place of the dot. Type the Database and Schema pushes write to. Leave User, Role and Warehouse empty forSANDA_PUSH, or type the names of ones you have. - Run the setup script. Under the fields, Then run this in Snowflake, as an administrator shows a script with your names and a new public key in it, filling in as you type. Copy it into a Snowflake worksheet and run it.
- Check and connect. Press Check and connect. Sanda signs in to Snowflake as the user, checks the role can use the warehouse and see the schema, and keeps the connection. You land in a new push with the account chosen.
Connect each account and schema once, however many pushes write to it.
What the setup script does
The script makes three things, and grants nothing else:
| It makes | What it is for |
|---|---|
A role, SANDA_PUSH |
Using the warehouse, reading, adding and updating rows in the schema's tables (including tables made later), and making tables in the schema. It can't delete a row, drop a table or reach any other schema. |
An extra-small warehouse, SANDA_PUSH |
Running the writes. It starts suspended, wakes for a write, and suspends itself a minute after. |
A service user, SANDA_PUSH |
Signing in. It has no password and can't sign in to Snowflake's website: it signs in only with the key pair, by its public key. |
The key pair
Sanda signs in to Snowflake with a key pair, not a password. Your browser makes the pair when Connect a Snowflake account opens. The public key goes in the setup script, which sets it on the user. The private key goes to Sanda once, when you press Check and connect, and is stored encrypted. Sanda only ever uses it to sign its requests to your account, and nobody (Sam included) sees it again. Make a new key pair makes another, and the script shows its public key: run the script again if you already ran it with the old one.
If Connect fails
Nothing is kept until the check passes, and the form says what to fix:
| The form says | What to do |
|---|---|
| Snowflake didn't accept the key pair for the user | Run the setup script, which sets the public key on the user, and press Check and connect again. If you made a new key pair, run the script again. |
| Snowflake has no account at that address, or Sanda couldn't reach it | Check the Account identifier. It looks like myorg-myaccount. |
| Snowflake signed the user in, but not with the role | Run the script's GRANT ROLE line. |
| The role can't use the warehouse | Run the script's grants on the warehouse. |
| The role can't see the schema | Check the Database and Schema names, then run the script's grants. |
| The account and schema are already connected | Each account and schema is connected once. Use the connection you have, or disconnect it first. |
A Snowflake account that only accepts connections from listed addresses (a network policy) refuses Sanda until Sanda's addresses are on its list. Ask Sanda support for them. Sanda reaches Snowflake over the internet, so it can't use a private link address.
Disconnect
On Push, press Connected accounts, then Disconnect beside the account, and confirm. Sanda forgets the private key. To end Sanda's access in Snowflake too, run ALTER USER SANDA_PUSH UNSET RSA_PUBLIC_KEY, or drop the user, as an administrator. The pushes that write to the account stay, and run again once you connect it. Nothing in Snowflake changes: the rows pushes already wrote stay in the table.
When Snowflake stops accepting the key pair, or after you disconnect, the account's row says connect again. Press Connect again beside it, run the script the form shows (it sets the new public key), and press Check and connect: the same connection takes the new key, so every push on it carries on. To point a connection at another schema, connect that schema as a new account.
Create a push to Snowflake
Press New push on Data · Streams · Push, or the Snowflake card once an account is connected. The editor asks the same four things as any push (see create a push), in Snowflake's words.
Under What it sends, a new push starts on A whole table: a table from your semantic model, one Snowflake row for each of its rows, in a table Sanda makes if it isn't there (see send a whole table). Values onto rows you have writes chosen metrics and columns into a table you already have, column by column, as the rest of this section describes.
Where it writes
- Destination, on a new push when more than one destination has an account connected: choose Snowflake.
- Snowflake account: the account and schema the push writes to.
- Table: the table whose rows get the values, from the tables in that schema.
How each record is found
- Snowflake column: the key column, from the table's text and whole-number columns, each marked key column. A new push starts on Choose a key column.
- Sanda value that holds it: a column or a dimension, never a metric, because it says which one row a Sanda row is about.
Snowflake compares text with its capitals, so A1 and a1 are two rows. A whole number is compared as its digits, so 42 and 42.0 are one row. Two Sanda rows with one key are both refused, because Snowflake couldn't tell which to keep: group the push by the key so each has one row.
What it writes
Under What it writes, pick a Snowflake column on the left and the value for it on the right, or A fixed value instead for one that is the same on every row. Press Add a column for each one more. A push writes up to 200 columns.
- The line under each column says its Snowflake type, such as
NUMBER(18,2)orTIMESTAMP_NTZ, and a column's comment in Snowflake shows under it. - Columns Snowflake fills itself (an identity column), columns it works out, and types a push can't write (binary, geography, geometry, vectors) are listed under columns Sanda can't write, and why.
- A column that can't be empty and has no default is needed to add a row. The editor names any the push doesn't write, and saving warns of them again.
Saving checks the mapping against the table as Snowflake has it now, and refuses in a sentence anything Snowflake would not take, such as a column it no longer has.
Send a whole table
A whole table sends every column you choose of a table on your semantic map, such as sales by store and day, one Snowflake row for each of its rows. It is an ordinary push once it is saved: each run merges only the rows whose values changed.
- Choose the table. Under The table, pick the Table from your semantic map, and the column that is Different on every row, such as an order number. Each run finds a Snowflake row by it, and adds a row when the table has none.
- Choose where it lands. Under Into, A new table is chosen. Type the Table name, or keep the one Sanda suggests. Snowflake keeps it upper case with underscores, such as
SALES_BY_STORE, and the hint under it says the name it will have. - Choose the columns. Under Columns, every column is ticked to start. Each says the Snowflake column it becomes and its type, such as
ORDER_TOTAL · NUMBER(12,2). Untick any you don't want sent. - Create the table. Press Create SALES_BY_STORE in Snowflake (it names your table). Sanda makes the table and its columns if the schema hasn't a table of that name, and the editor moves to A table Snowflake already has, with the table chosen and every column lined up. Making a table needs no warehouse.
- Finish and save. Choose when it runs and name it, as for any push, and press Save push.
If the schema already has a table of that name, the editor says so before you press Create, with Send into it instead. In A table Snowflake already has, choose the Snowflake table and the column it is Found by, and each of your columns lines up with the Snowflake column whose name reads the same, ignoring case, spaces and underscores. A column with no match isn't sent until you press Add the missing columns to the table, which adds a column for each. Only the table's owner can add columns, so this works on tables Sanda made, and on tables you made only if Sanda's role owns them.
Each column type becomes the nearest Snowflake type:
| In your semantic model | In Snowflake |
|---|---|
| Whole numbers | NUMBER(38,0) |
Numbers with decimal places, such as numeric(12,2) |
NUMBER with the same places, such as NUMBER(12,2) |
| Other numbers | FLOAT |
| Text | VARCHAR, with its length where it has one |
| True or false | BOOLEAN |
| Dates, times, and dates with times | DATE, TIME, and TIMESTAMP_NTZ (or TIMESTAMP_TZ for a time with a zone) |
| JSON | VARIANT |
| Lists | ARRAY |
| Raw bytes | Not sent |
The key column becomes the table's primary key and can't be empty. A key that is neither text nor a whole number, such as a date, is kept as text.
Make the table if it isn't there
Under How it sends, Make the table if it isn't there is ticked on a new push. When a run finds the table, or a column the push writes, missing, it makes it (CREATE TABLE IF NOT EXISTS, then the missing columns) and carries on, once a run. A table made again starts empty, so Sanda forgets which rows it already sent and the next runs send every row again to fill it, and the run's detail says so. Untick it to have a run stop instead, with a sentence saying what is missing.
How values are written
Every value is written the way its column stores it, before it is compared with what Snowflake last accepted:
- Numbers are rounded to the column's decimal places, so 100.004 and 100.0049 sent to a
NUMBER(18,2)column are the same value. - Booleans take yes or no, true or false, or one or zero.
- Dates take the value's day in your workspace's reporting time zone. Timestamps take the instant, in UTC: a
TIMESTAMP_NTZcolumn holds the UTC clock reading, andTIMESTAMP_TZandTIMESTAMP_LTZcolumns the instant itself. VARIANT,OBJECTandARRAYcolumns take JSON. AVARIANTcolumn also takes plain text.- An empty value is written as NULL, so a metric with nothing to measure doesn't leave last month's number standing.
A value that doesn't fit its column, such as text longer than a VARCHAR(40) holds, is refused before anything is sent, and the run lists it.
How a run sends
A run merges its changed rows into the table in statements of up to 5,000 rows, and at most 50,000 rows a run. A statement may run for up to 5 minutes before Snowflake cancels it. A run also stops sending after 7 minutes, and the next run carries on: what it leaves is counted as left for a later run. Each run's detail says how many Snowflake API requests it made.
A statement Snowflake is still writing when a run runs out of time is merged again by the next run. Merging the same rows twice leaves the table as merging them once, so nothing is written twice.
Send everything again, on the push, merges every row it reads again over the next runs, including the ones Snowflake already has, and releases held rows. Use it when the table was changed by hand. It wakes your warehouse for about one statement every 5,000 rows. See send everything again.
When a run says why
Rows Snowflake refused
Snowflake's own message comes first, because it quotes the value. Snowflake refuses a statement whole without saying which row was at fault, so Sanda splits the statement until it finds the row, and only that row is refused. Sanda adds a hint for the common ones:
| Code | What it means |
|---|---|
SNOWFLAKE_100038 |
The column takes a number, and the value isn't one. |
SNOWFLAKE_100035, SNOWFLAKE_100040 |
The column takes a date and time, or a date, and the value isn't one Snowflake reads. |
SNOWFLAKE_100046 |
The number is larger than the column holds. Widen the column, or round the value in Sanda. |
SNOWFLAKE_100072 |
A column that can't be empty got no value. Map a value to it, or give it a default in Snowflake. |
SNOWFLAKE_100078 |
The text is longer than the column holds. Widen the column in Snowflake. |
SNOWFLAKE_STILL_RUNNING |
Snowflake was still writing the row's statement when the run ran out of time. It is merged again on the next run. |
BECCA_TOO_LARGE |
The row's values together are larger than one Snowflake statement takes. |
BECCA_DUPLICATE |
More than one Sanda row has this key. |
A row Snowflake refuses 3 runs in a row for the same value is held. See held records.
A run that stops
A refusal about the push rather than one row stops the run in one sentence, and nothing is held for it:
| The run says | What to do |
|---|---|
| A column this push writes isn't in its table any more | The column was dropped or renamed, and Make the table if it isn't there is off, or adding it didn't help. Open the push, change or remove it, and save. |
| Snowflake has no table that Sanda's role can reach any more | The table was dropped or renamed and Make the table if it isn't there is off, or the role's grant on it was taken away. Run the setup script's grants again, or open the push and choose another table. |
| Snowflake didn't let Sanda's role make the table | The role can't make tables in the schema. Run the setup script's GRANT CREATE TABLE line, or make the table yourself. |
| Snowflake didn't let Sanda's role add columns | Only a table's owner can add a column. Add it in Snowflake, or send into a table Sanda made. |
| Snowflake no longer lets Sanda's role write to this table | Run the setup script's GRANT lines again. |
| Snowflake couldn't run the warehouse this push writes with | A resource monitor suspended it, or the role lost its grant on it. The run says Snowflake's reason. A suspended warehouse is waited for, and the next run carries on. |
| Snowflake no longer accepts Sanda's connection | The public key was taken off the user, or the user was dropped. Disconnect the account and connect it again. |
Something unclear or out of date? Tell us, and we will fix the page.