Created
April 26, 2022 19:43
-
-
Save vvgsrk/a78029c9f1dc05b44be937aaef99d57e to your computer and use it in GitHub Desktop.
Incremental DBT temp table
This file contains hidden or 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
create or replace temporary table dev_edw_dbt_incremental_model_test.dbt_src_product_management.src_product_management_product_latest_incremental__dbt_tmp as | |
( | |
WITH ranked_data AS ( | |
SELECT | |
ROW_NUMBER() over ( | |
PARTITION BY product_id | |
ORDER BY | |
__event_ts DESC | |
) AS row_rank, | |
* | |
FROM dev_edw_dbt_incremental_model_test.dbt_src_product_management.src_product_management_product_history | |
WHERE __load_ts > ( SELECT MAX(__load_ts) | |
FROM dev_edw_dbt_incremental_model_test.dbt_src_product_management.src_product_management_product_latest_incremental ) | |
) | |
SELECT | |
"PRODUCT_ID", | |
"PRODUCT_NAME", | |
"PRICE_PER_UNIT", | |
"BASIC_UNIT", | |
"IS_STOCK_LIMITED", | |
"IS_ACTIVE_FOR_SALE", | |
"__EVENT_TS", | |
"__LOAD_TS", | |
HASH( | |
product_id | |
) AS __uuid | |
FROM | |
ranked_data | |
WHERE | |
row_rank = 1 | |
ORDER BY __load_ts desc | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment