Skip to main content

Copy a Snowflake table or view once a day

This page is for an administrator who wants Prism to copy a table or view from Snowflake on a schedule, rather than read it live. Prism runs one statement a day against your warehouse, keeps the rows as a dated copy in its own memory, and answers every question from that copy. Your warehouse sees one query per copy and nothing while people are asking questions.

Choose this over the live Snowflake recipes (a table, a directory) when:

  • your warehouse team does not want query load while the product is in use; or
  • the table is a directory of your people that you want to be the organizational context stream. Prism resolves GitHub logins, Jira accounts and employee ids to one person from the organizational stream's rows. A live Snowflake directory never puts rows in Prism, so it cannot do that. A copy can.

You author a source manifest from the snowflake_snapshot recipe. Its worked example is a directory of people, because that is the case that needs a copy. For any other table, replace the columns with your own the same way.

Read Take a source live first if you have not connected any source yet.

What this has been tested against, and what it has not​

The copy this recipe takes is tested two ways: against a model of Snowflake's SQL API v2, built from Snowflake's own documentation, and against a real Snowflake account of ours, whenever the Snowflake snapshot driver, its tests or this recipe change, and every night. The real account is where these are tested:

  • Authentication. Key-pair sign-in is accepted, and a key the account does not hold is refused before anything runs, as a fault of the source rather than of one stream. Only key-pair sign-in is implemented; password, OAuth and workload identity are not supported at all.
  • The statement timeout firing. Prism sends statement_timeout to Snowflake with every statement, and Snowflake ends the statement at that point itself (observed: a 5-second timeout ended its statement in under 7 seconds). Prism also holds its own limit, and cancels a statement it stops waiting for; the cancel was observed taking effect on the account.
  • A statement that outlives Snowflake's 45-second answer window is polled to its result.
  • Result chunking. Snowflake returns a large result in partitions whose size it chooses. Observed: a 20,000-row result came as a small first partition (about 100 KB) and one much larger one (about 4 MB), and Prism read every partition. (Prism also refuses a copy whose rows do not add up to what Snowflake said; that refusal is tested against the model, since a real account cannot be made to send a short partition.)
  • Resubmitting a statement. When a submission gets no answer, Prism sends it again under the same request id with retry=true. On the real account, a statement still running is answered with the same statement handle, not a new one.
  • A people directory, copied through this recipe, designated organizational, and compiled into the identity crosswalk, with a person resolving by each identifier they carry.
  • A copy of only the changed rows (section 9), over the same directory: the first copy, a second run that reads nothing, and a reconcile that rewrites nothing. The row hash, with each type a view usually holds. The check that refuses a key under a collation.

The following were not observed against a real Snowflake. Confirm each one on your account before relying on it:

  • Warehouse resume time on your account. With auto-resume on (Snowflake's default), a warehouse that has suspended resumes when the copy runs, and the resume counts against statement_timeout. How long yours takes was not measured. Set the timeout with it in mind.
  • Identifier case of a warehouse, database or schema. Snowflake matches these names and the role name exactly, including case. At Register, Prism stores a name that SQL accepts without quotes in upper case. It stores a name in double quotes as written inside the quotes. It stores any other name as typed. For a name that SHOW lists in lower or mixed case, use double quotes. In a form field, type "Mixed_Role". In the manifest, YAML removes plain double quotes, so write read_only_role: '"Mixed_Role"'. Only the role was tested against a real account, which refused a role name in the wrong case. For the warehouse, database and schema, this rule follows Snowflake's documentation and was not tested.
  • Date and time formats. Window bounds are sent as ISO text and rely on the account's input formats being AUTO (the default). An account that sets DATE_INPUT_FORMAT or TIMESTAMP_INPUT_FORMAT otherwise was not tested.

The first copy against your account is the real test. Check it with the verification questions in step 6 before you designate anything.

1. What to ask your account administrator for​

The same things the directory page lists:

  • the table or view (a view is your access control: leave out the columns you would rather not hand over);
  • a TYPE = SERVICE login with a key pair registered against it;
  • a read-only role with USAGE on the warehouse, the database and the schema, and SELECT on the one object;
  • the warehouse the daily copy should run on. The spend lands there.

2. The five connection values​

You enter these in Admin → Context streams, not in the chart, on the form you register the source with (section 5):

ValueWhat it is
accountThe host of your Snowflake URL without .snowflakecomputing.com. For example myorg-myaccount, or xy12345.east-us-2.azure.privatelink over Private Link (Private Link). You can paste a URL instead, if its host ends in .snowflakecomputing.com. Prism keeps only the account part and shows you what it stored. Prism cannot read the account from a Snowsight URL (app.snowflake.com)
warehouseThe virtual warehouse the copy runs on
databaseThe database holding the table or view
schemaThe schema holding it. Optional: leave it empty when the service login's default schema is the right one
userThe service login Prism signs in as

The credential is the private key, as PEM (a line starting -----BEGIN). A .p8 file is often DER-encoded; convert it with openssl pkcs8 -topk8 -nocrypt -inform DER -in key.p8 -out key.pem.

Until a key is stored, all of it can change. A probe that fails stores no key. So while the source has no key, Edit parameters… on the source's page offers all five values, and the Manifest tab's Save takes any change under connection:. Correct the value the probe named, then enter the key again.

Once a key is stored, the address is fixed. The account, the login, the warehouse, the database, the schema and statement_timeout cannot change. Changing one of them is deleting the source and registering it again, which also means entering the private key again. The role can still change: edit read_only_role on the Manifest tab and Save. Prism keeps the key, clears the probe result and switches the source off. Probe it, approve it and enable it again.

Egress: the ingest pod calls <account>.snowflakecomputing.com on 443 (egress.md).

Some Snowflake accounts accept connections only over a private network link. Snowflake calls this Private Link. Four things change for such an account.

  1. The account ends in .privatelink. Your Snowflake team usually sends the address as a URL, such as https://xy12345.east-us-2.azure.privatelink.snowflakecomputing.com/. Paste that URL into account, or type xy12345.east-us-2.azure.privatelink. Without .privatelink, Prism dials the account's public host, and a Private Link account may not answer there.
  2. The Prism pods must resolve the private host name. Your laptop resolving it proves nothing. The name resolves through a private DNS zone, and that zone has to be linked to the network the cluster runs in. On Azure that is the privatelink.snowflakecomputing.com zone, linked to the cluster's virtual network. Test from inside the cluster with the curl in egress.md.
  3. Every pod that calls Snowflake needs the same reach. The app pod sends the probe. The ingest pod runs the daily copy. If the probe passes and the copy fails with a transport error, the ingest pod cannot reach the host.
  4. A disaster-recovery or replica account is a separate account. It has its own identifier, and Prism reads only the account you name. Before you register, open a worksheet on the account you mean Prism to read and run SELECT CURRENT_ORGANIZATION_NAME(), CURRENT_ACCOUNT_NAME(), CURRENT_ACCOUNT(). The first two make orgname-account_name. The third is the account locator.

3. The statement, and its ceiling​

  • One statement per copy, or one per manifest partition, each read whole. paginate is {type: none} and nothing else. Snowflake splits the result into partitions itself, and a paged read would be several statements, each seeing the table at a different moment. fetch_size is refused for the same reason: Snowflake decides how much each partition carries.
  • Each statement is its own moment. A source with two streams copies each as of its own statement, and so does each manifest partition of a stream. Snowflake's API holds no transaction across statements, so unlike a Postgres or Oracle source, two streams of one source, or two partitions of one stream, are not one instant.
  • statement_timeout (PT10M in the recipe) is the ceiling on each statement of the copy. Snowflake receives it with the statement and cancels there, and Prism holds it too. Without one, Prism's own bound (ingest.engine.databaseFetchTimeoutSeconds, an hour by default) is sent in its place. A statement that runs out of time is reported as the ceiling and never retried.
  • PT10M is the recipe's guard against warehouse spend. You can raise it. The manifest's statement_timeout bounds one statement. One source's run in an ingest tick is also bounded, by ingest.engine.sourceDeadlineSeconds (two hours by default). When that bound ends, the copy stops. A view that takes longer to read needs both values raised. To size the timeout, run the stream's SELECT in a worksheet on the warehouse the copy will use, and time it. Set the timeout well above that time, and allow for a suspended warehouse to resume. A copy of only the changed rows still reads the whole view on each reconcile (section 9), so size it for the whole view there too. The largest result Prism has read from a real account is the 20,000 rows above.
  • Choose it before you register. Once the source holds its key, changing statement_timeout means deleting the source and registering it again (section 2).
  • The warehouse can end a statement first. Snowflake's documentation says that when the warehouse sets STATEMENT_TIMEOUT_IN_SECONDS, the lower of that and the statement's own timeout applies. Ask your account administrator for the warehouse's value. This was not tested against a real account.
  • Every other round trip is bounded at 60 seconds: sending the statement, asking whether it has finished, and cancelling. Snowflake's API answers within about 45 seconds whatever the statement costs, so a minute with no answer means the network went quiet, not that the view is slow. A submission with no answer is sent again, and the log names what stalled.
  • While a statement runs, Prism keeps asking. Snowflake answers "still running" with 202 or 429; neither costs an attempt. A status request that gets no answer, or a gateway error, says nothing about the statement, so Prism keeps asking about the same one. After six of those in a row it gives the statement up, cancels it, and tries again, unless this stream has already been read in part (next point but one), when the stream is abandoned instead.
  • A statement Prism stops waiting for is cancelled, so it does not run on and bill. That needs the handle Snowflake returns. If the submission itself got no answer there is no handle to cancel with, and the timeout sent with the statement is what ends it.
  • A copy is never landed short. If anything fails after the first rows have been read, or after an earlier statement of the stream (one manifest partition) returned no rows, the copy is abandoned and the next scheduled run takes it whole. The previous copy stands.

4. The worked example, and which parts are yours​

The recipe's markers say which lines are which. STRUCTURAL lines are ones the engine needs; YOURS lines are your view, your columns and your choices.

  • sql: names your view and its columns as your view spells them. Snowflake folds an unquoted name UP and Prism folds the result back DOWN, so SELECT EMPLOYEE_ID arrives as employee_id. Every from: must be a column of that result. Prism checks before landing a row and refuses a name that is not there, rather than writing a column of NULLs.

  • employee_id is the key and the anchor, the identifier a person is. email is how a Jira account resolves. github_login is optional: delete it and its identity link if your directory has no forge usernames.

  • manager_employee_id and its reports_to link are what "everyone under X" walks.

  • Each column's type: must be one its Snowflake type can land as without the value changing. Prism checks this against the result set before it reads a row, and refuses the copy by column name when a type cannot land. What is checked is type:; a sql_type: override on a column, such as NUMERIC(5,2), is not checked against the value:

    Declared type:Snowflake types it takes
    stringany type: TIME lands as 23:01:59.123456, VARIANT as its JSON, BINARY as hex
    numberNUMBER, FLOAT, DECFLOAT, and VARCHAR when every value reads back unchanged from a floating-point double (for example, any whole number up to 9,007,199,254,740,992, and any number with a fractional part of up to 15 significant digits no smaller than about 1e-307); a whole number above 9,007,199,254,740,992 lands only when a double holds it exactly. It is stored as that double
    timestampthe three TIMESTAMP types, DATE, and VARCHAR when every value is an ISO 8601 timestamp or Snowflake's default zoned text (2020-01-01 00:00:00.000 +0000)
    dateDATE, the three TIMESTAMP types, and VARCHAR when every value is an ISO 8601 date
    booleanBOOLEAN, and NUMBER when every value is 0 or 1 (an empty value lands as false, as it does for BOOLEAN)

    NUMBER and DECFLOAT keep every digit. A FLOAT, and a VARCHAR read as a number, are stored as a floating-point double, as text and floating-point numbers from other sources are: 0.1 is stored as the double nearest to 0.1. A VARCHAR value that a double cannot hold, such as a 20-digit id or 1e-400, is refused rather than stored as a different number. Declare such a column string. A DECFLOAT beyond what Prism's store holds (written with more than 16,383 decimal places, trailing zeros included) is refused naming the column. TIME and the TIMESTAMP types keep microseconds; a finer fraction is dropped. The usual "no end date" and "no start date" values are stored as infinity and -infinity: a date of 9999-12-31, a timestamp of 9999-12-31 23:59:59.999999 in UTC (which is what Snowflake's …23:59:59.999999999 becomes), and 0001-01-01 (as a date, or as a timestamp at 00:00:00 in UTC). Such a value sorts after (or before) every other one. But it is not equal to DATE '9999-12-31', a time bucket over it is labelled infinity, and date arithmetic on it fails or gives a meaningless result. Cast it in the SELECT (to VARCHAR, or to NULL) if a question will do arithmetic on it. A TIMESTAMP_TZ keeps its own offset, so a date taken from it is the date in that offset. A date taken from a TIMESTAMP_LTZ is the UTC date, and one taken from a TIMESTAMP_NTZ is the date its wall clock shows. Cast in the SELECT if you want another zone's. A VARCHAR value that does not read as the declared type stops the copy rather than landing as an empty value. To land a column another way, cast it in the SELECT: for example CAST(shift_start AS VARCHAR), or active_flag = 'Y' AS active for a text flag declared boolean.

If this copy will replace a directory you already have, read Replacing an uploaded directory before you write your columns. The field names matter there.

5. Register, probe, approve, enable​

On Admin → Context streams, pick the recipe, open Review the manifest, replace the document with yours, enter the connection values and the key, and press Register, which tests the connection with the key before storing it. Then approve the source, and enable it.

Test on the source's page also runs each stream's own SELECT, returning no rows. Entering the key checks only the connection. A view that does not exist, a column it has not got, or a grant the role lacks is named with the stream, on the source's Overview under Stream queries.

If you wrote the manifest yourself, register it with Paste a manifest… instead of a recipe. Once the form has read the manifest, it shows a field for each connection parameter the manifest declares, and a required one left blank is refused by name. That form has no field for the key: enter it after registering, on the source's Credential tab, with Save and test.

A passing probe means: the account answered, the key was accepted, and the session was the one you asked for (the role, warehouse, database and schema are read back). Snowflake accepts a warehouse name that does not exist and runs without one, so the probe reads the warehouse back and fails on a mismatch.

The probe that Register runs does not mean the view exists or that the role can read it. Press Test to find out before the first copy does.

The first copy runs at the next ingest tick after the source is enabled. After that it follows schedule (03:00 UTC in the recipe).

6. Verify it​

The recipe ships two questions. The first, how many distinct people does the latest copy list, is also how you confirm a copy has landed. Compare it with SELECT COUNT(DISTINCT employee_id) over the view in your own worksheet. Mark each question correct, wrong or skipped on the verification screen.

7. Make it the organizational context stream​

If nothing holds the organizational stream yet: on the source's page, press Designate as the organizational context stream. The next ingest run compiles the crosswalk from its rows. Check the identity crosswalk line in the self test, which counts what it linked, by kind.

Replacing an uploaded directory​

The usual case: an uploaded roster (csv_people) already holds the stream, and answers and definitions are built on it. In order:

  1. Register and enable the Snowflake copy (steps 1–5). Leave the roster alone. Enabling the copy is never refused because the roster holds the stream.
  2. Let it land, and check that it did. Its first copy runs at the next ingest tick. The first verification question (step 6) should count the people you expect.
  3. Move the stream. On the organizational stream's pane, press Move to the Snowflake copy. One act: the roster gives up the role and the copy takes it, so the installation is never without a directory in between.
  4. Check the crosswalk after the next ingest run: the self test's identity crosswalk line should name the Snowflake source.

The crosswalk is then rebuilt from Snowflake alone. The roster's rows are not merged in. The roster keeps its uploaded file, so you can move the stream back.

What makes the switch invisible to your readers (tested): a person present in both directories resolves to the same person afterwards, and the same questions give the same answers — by leader, by a reporting-line definition, and by a classification. That holds when two things carry over from the roster to your Snowflake manifest:

  • The same anchor. If the roster keyed people by employee id, key the copy by employee id. A reporting-line definition stores the key of each person it names and what kind of key it is. Under a different anchor, a question using it is refused rather than answered wrongly:

    this definition's people were bound as employee_id and 'snowflake_snapshot' now identifies people by email, so the keys it stored cannot match anybody here.

  • The same field names for every field a definition names. A classification over job_family and job_title needs fields of those names in the copy's model, whatever your view calls the columns (from: does the mapping). A missing one is refused by name:

    'developers' (revision 1) cannot be evaluated against 'snowflake_snapshot' as it is now: …

Moving away from a directory that holds the stream before the copy has landed is refused, and nothing changes. So is a move onto a live Snowflake directory, which never lands anything. The copy is checked the way the crosswalk reads it: every table its identity links read must exist, and at least one must hold a row.

'snowflake_snapshot' has no landed copy yet (snowflake_snapshot_people does not exist), and the crosswalk is compiled from its rows: moving the organizational context stream to it now would leave nobody resolvable until its first walk completes. Land it first — its first walk runs at the next ingest tick after it is enabled — then move. Nothing was written.

The same condition is also checked when the crosswalk is compiled, in case the table disappears later. In that case the crosswalk is emptied: nobody resolves until the directory has rows again or the stream is moved back. This is deliberate. A directory Prism cannot read must not go on answering. The self test's crosswalk line FAILs and carries the reason:

… and its landed copy is gone or empty (… does not exist) although a walk of it has completed, so there is nobody to compile. The source's status shows what its last walk landed: walk it again, or move the designation back to a source that has rows

8. A second Snowflake account​

To copy from a second account beside this one, with its own key, tables and label, see Connect a second Snowflake account.

9. Copy only the rows that changed​

The recipe copies the whole view on every run. For a large view, that is a full read of the warehouse every day. To copy only the rows that changed, declare kind: mirror and incremental.mode: keyset. The table then holds one current row per key. Each run reads only the rows whose version moved above the last run's position. On the reconcile schedule, a run reads the whole view and compares a hash of each row. That catches what the version cannot show: an edit in a joined table, and a row that left the view.

The manifest, the three questions to ask the view's owner, and what Prism refuses are the same as for Postgres. See One current copy instead of a dated one. Five things are different on Snowflake:

  1. paginate is {type: none}, with no fetch_size, as for every Snowflake stream (section 3).
  2. A run is several statements, each at its own moment. On the first copy and on each reconcile, a run sends three: the collation check (point 4), the read of the largest version, and the read of every row. Any other run first reads the largest version above the last position. When nothing is newer, that is the only statement. Otherwise a second statement reads the rows above the last position. The largest version becomes the new position. A row that changes after that read is read by the row read. The next run reads it again and rewrites it only if it changed again. No row is skipped. Each statement has the whole statement_timeout.
  3. Snowflake computes each row's hash. The row read carries SHA2 and HASH over every column the stream declares. Your warehouse does that work for each row the run reads: the changed rows on most runs, and every row on the first copy and on each reconcile.
  4. A cursor column under a collation is refused. A column declared with a collation such as en-ci, or put under one by the SELECT, holds a and A as equal. A run would then skip rows. On the first copy and on each reconcile, Prism reads each cursor column's collation with COLLATION(). It refuses any collation but none or utf8, and nothing is copied. Apply COLLATE 'utf8' to that column in the SELECT.
  5. A cursor column of type VARIANT, OBJECT, ARRAY, BINARY or a spatial type is refused. Snowflake sends such a value as text that Prism cannot send back as the same value. Nothing is copied. Cast the column in the SELECT, for example col::VARCHAR AS col. For a BINARY column, use HEX_ENCODE(col) AS col.

A GEOGRAPHY or GEOMETRY column cannot be hashed. Snowflake refuses the statement on every run, and nothing is copied. Select such a column as text, for example ST_ASWKT(col) AS col.

Not tested against a real account: a run over rows that change between runs, and the time and warehouse credits a large view costs.

If something is wrong​

A refusal names Snowflake's code and what to do. The ones with a sentence of their own:

CodeWhat to do
390100, 390144, 390318, 394204The account refused the sign-in: a wrong user or key, or the ingest pod's clock more than a minute ahead or five minutes behind. Check the user, that its RSA_PUBLIC_KEY matches the stored private key (DESC USER shows the fingerprint), and the pod's clock; LOGIN_HISTORY_BY_USER (the last row) says which. Stops the whole source, never retried.
390189The account refused the role this source names. Snowflake matches the role name exactly, including case. Check the name against SHOW ROLES, and check that the role is granted to the service user. A real account answered this code for a role name in the wrong case.
390186The role read_only_role names is not granted to the service user. Grant it, or name one the user has. The account records no message for this one. Stops the whole source, never retried.
NO-ACCOUNTThe account host answered 404. Check the account identifier. An identifier that names no host at all fails as a connection error instead; the run retries it and then gives up, naming the last error.
KEY-UNLOADABLEThe stored key would not load: it is not PEM, or its passphrase is wrong. A DER .p8 converts as step 2 shows.
002003The object, its schema or its database does not exist, or the role cannot see it. Snowflake reports all of these the same way.
000904A column the statement names is not one the object has. The refusal names it as Snowflake echoed it. A quoted name must match a column exactly, and text takes single quotes; an unquoted name is folded up, so alias it in the SELECT. Compare with DESCRIBE VIEW.
003001The role can see the object and may not read it: grant SELECT on it.
000606No usable warehouse: the statement had none, or the role cannot use the one named.
090073The warehouse cannot resume because its resource monitor has used its quota. Raise the monitor's quota. Stops the whole source, never retried.
391920The warehouse name does not exist for this role, and the API ran the statement without one.
001003Snowflake could not parse the SELECT.
cannot land as the declared typeA column's type: is not one its Snowflake type can land as (the table in step 4). Cast it in the SELECT, or declare it string. Checked before any row is read, so an empty view is refused too.
does not read asTwo causes, and the message says which. A value does not read as the column's declared type:, for example a VARCHAR value that is not a number, a NUMBER flag that is not 0 or 1, or a far-future end date declared timestamp whose instant is past the year 9999 in UTC: cast it in the SELECT, or declare the column string (or date, for an end date). A value does not read as its own Snowflake type, or is outside the years 1 to 9999, for example a TIMESTAMP_LTZ end date past the year 9999 in UTC: cast it in the SELECT (for example to VARCHAR). Declaring the column string does not help this second case, because the value is read before any column is mapped. Neither message names the value. The second message does not name the column either. The run's log on the stream's Runs tab names it.
391908Snowflake answered that its response does not include the whole result set. Nothing was landed; narrow the SELECT.
PARTITION-SHORTA partition arrived with fewer rows than Snowflake said. Treated as a network fault: the copy is abandoned, never landed short.
000604The statement was cancelled on the account by something other than this copy, such as an administrator or a resource monitor. Wait for the next scheduled copy. Prism's own cancels are retried; this row is for one it did not make. One exception: if a cancel of Prism's never reached the account and one of yours then did, the statement is run again rather than named here.
another six-digit codeRead Snowflake's own message for it, filtered on the source's user: a statement's in QUERY_HISTORY_BY_USER, a refused sign-in's in LOGIN_HISTORY_BY_USER (ERROR_MESSAGE in both). Both are table functions in any database's INFORMATION_SCHEMA, show an event within seconds, and need no access to the SNOWFLAKE database. Their ERROR_CODE drops leading zeros (002003 reads 2003). Prism never records the message, because it can quote the statement.
the key … has a collation that is not binaryThe run's log on the stream's Runs tab names the collation. A cursor column of a copy of only the changed rows (section 9) compares under a collation that is not binary. Nothing was copied. Apply COLLATE 'utf8' to that column in the SELECT.

The ceiling (000630, or Prism's own limit) says which limit fired, the manifest's or the engine's, and is never retried.