Snowflake - Best practices to keep tables up to date with s3 external stage

Viewed 132

We want to ingest our source tables from an s3 external stage into Snowflake. For this ingestion we have to consider, new files arriving in the s3 bucket, updates in existing files, and in some cases row deletions.

We are evaluating 3 approaches so far:

  • full drop & copy of tables daily (straightforward but less performant)
  • copy command which will capture new and updated files, and then execute a merge query to deduplicate and even delete rows based on specific use cases (could work out, but we need to maintain more complex merge & delete logic per case)
  • use external tables on top of the external s3 stage, and materialized views on top of the external tables, to boost the query performance.(not sure if this is a suggested ingestion mechanism)

From all the 3 approaches the external tables & materialized view seems to be the one that keeps all tables up to date with the source in a more care-free / less-maintenance way. But at the same time, we haven't seen this suggested as an ingestion mechanism for Snowflake. Also it is not very clear to us how snowflake handles the maintenance of materialized views, to understand cost implications (could it be compared cost-wise to the copy and merge queries of the 2nd approach for example?).

In general, are there any best practices regarding our ingestion use case? Also some feedback regarding the 3rd approach would be very useful.

1 Answers

Try and Evaluate the following :

Step1 : Create External Tables on top of External Stage. Step 2: Create a Snowflake Stream (Standard) on the External Table to Find the (Insert,Update and Deletes) on the File Step3: Create a Stored Procedure [Merge statements on Target table to figure out (Inserts,Updates,Deletes) to Load into Target Table Step4: Schedule the Stored Prod using Snowflake Task.

Note: Consider the Source file management ( Landing into S3 and Post Ingestion into Snowflake , How to Archive the files in S3 etc).

Related