SAVE SNAPSHOT
Overview
Creates or replaces a named snapshot from the current in-memory pipeline dataset. Snapshots let you reuse a dataset later in the same pipeline (or in a later step) without re-reading the source.
Snapshot names can include wildcards when listing, loading, or deleting later. When saving, you can
use date tokens (for example
[YYYY][MM][DD]), runtime tokens such as @executionid, and
DataZen functions in the name.
AUTO_DELETE— removes the snapshot automatically when the pipeline finishes (useful for temporary working sets).ENCRYPT_CERT— encrypts the snapshot with the X.509 certificate thumbprint provided. Use the same thumbprint on LOAD SNAPSHOT to decrypt.
On cloud agents, a known limitation forces all snapshots to be temporary:
AUTO_DELETE is always treated as enabled, even when it is omitted from the command.
See the Snapshots section of the Development
Guide for how snapshots fit with @snapshot() and @pipelinedata().
Syntax
Creates or replaces a snapshot using the current data pipeline and optionally deletes it at pipeline completion.
SAVE SNAPSHOT '...'
{ AUTO_DELETE }
{ ENCRYPT_CERT '...' }
;AUTO_DELETE |
Deletes the snapshot created by this operation when the pipeline completes its execution |
ENCRYPT_CERT |
The thumbprint of an X.509 certificate used to encrypt the snapshot |
Example 1
-- Retrieve all customers from a database SELECT * FROM DB [snowflake] (SELECT * FROM CUSTOMERS); -- Save the data as a permanent snapshot with a naming convention -- that uses date tokens SAVE SNAPSHOT 'customers-[YYYY][MM][DD]-[HH][NN][SS]' ; -- Save the data as a permanent snapshot with a naming convention -- that uses the runtime of the pipeline as an epoch value SAVE SNAPSHOT 'customers-@executionid' ;
Example 2
-- Retrieve all customers from a database as the current data pipeline
SELECT * FROM DB [snowflake] (SELECT * FROM CUSTOMERS);
-- Save the data as a temporary snapshot and delete at pipeline completion
SAVE SNAPSHOT 'customers' AUTO_DELETE;
-- Retreive customers from all available 'cust' parquet files
-- The data pipeline now has this data set in memory
SELECT * FROM DRIVE [adls] 'cust*.txt'
WITH
FORMAT Parquet
CONTAINER 'history';
-- Return customers not found in the Parquet files
EXEC ON DB [sql] (
SELECT cust_id, cust_name FROM @snaphot(customers)
WHERE cust_id NOT IN
(
SELECT DISTINCT id FROM @pipelinedata()
);
) WITH REPLACE;