-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SNOW-29] Initialize dynamic table:
verificationsubmission_latest
(#83
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
synapse_data_warehouse/synapse/dynamic_tables/V2.21.0__verificationsubmission_latest.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use schema {{database_name}}.synapse; --noqa: JJ01,PRS,TMP,CP01 | ||
|
||
CREATE DYNAMIC TABLE IF NOT EXISTS VERIFICATIONSUBMISSION_LATEST | ||
TARGET_LAG = '1 day' | ||
WAREHOUSE = compute_xsmall | ||
AS | ||
-- We deduplicate simply by selecting the latest record for each | ||
-- verification submission ID... | ||
WITH latest_unique_rows AS ( | ||
SELECT | ||
verificationsubmissionsnapshots.*, | ||
FROM | ||
{{database_name}}.synapse_raw.verificationsubmissionsnapshots --noqa: TMP | ||
WHERE | ||
SNAPSHOT_TIMESTAMP >= CURRENT_TIMESTAMP - INTERVAL '14 DAYS' | ||
QUALIFY ROW_NUMBER() OVER ( | ||
PARTITION BY id | ||
ORDER BY change_timestamp DESC, snapshot_timestamp DESC | ||
) = 1 | ||
) | ||
SELECT | ||
* | ||
FROM | ||
latest_unique_rows | ||
ORDER BY | ||
latest_unique_rows.id ASC; |