Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SNOW-29] Initialize dynamic table: verificationsubmission_latest #83

Merged
merged 8 commits into from
Nov 14, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
jaymedina marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use schema {{database_name}}.synapse; --noqa: JJ01,PRS,TMP,CP01

CREATE OR REPLACE DYNAMIC TABLE VERIFICATIONSUBMISSION_LATEST
jaymedina marked this conversation as resolved.
Show resolved Hide resolved
TARGET_LAG = '1 day'
WAREHOUSE = compute_xsmall
AS
WITH latest_rows AS (
SELECT
id AS latest_id,
MAX(snapshot_timestamp) AS latest_timestamp
jaymedina marked this conversation as resolved.
Show resolved Hide resolved
FROM
verificationsubmissionsnapshots
GROUP BY
latest_id
),
latest_unique_rows AS (
jaymedina marked this conversation as resolved.
Show resolved Hide resolved
SELECT
verificationsubmissionsnapshots.*,
ROW_NUMBER() OVER (
PARTITION BY snapshot_timestamp
ORDER BY snapshot_timestamp DESC
) AS row_num
FROM
verificationsubmissionsnapshots
JOIN
latest_rows
ON
verificationsubmissionsnapshots.id = latest_rows.latest_id
AND verificationsubmissionsnapshots.snapshot_timestamp = latest_rows.latest_timestamp
)
SELECT
* EXCLUDE (row_num)
jaymedina marked this conversation as resolved.
Show resolved Hide resolved
FROM
latest_unique_rows
WHERE
row_num = 1
ORDER BY
latest_unique_rows.id;