Created
November 27, 2022 11:24
-
-
Save mshakhomirov/a8b273a18a88332b0c4afe1346d917ce to your computer and use it in GitHub Desktop.
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
config { | |
type: "operations", | |
hasOutput: true, | |
schema: "production", | |
disabled: false, | |
name: "user_reputation", | |
dependencies: ["reputation_data", "reputation_data_v"], | |
tags: ["user_reputation"], | |
description: "user_reputation based on reputation_data from firehose" | |
} | |
create table if not exists ${self()} ( | |
user_id int64 | |
,updated_at timestamp | |
) | |
PARTITION BY DATE(updated_at) | |
; | |
merge ${self()} t | |
using ( | |
select | |
user_id | |
, latest_updated_at | |
from | |
( | |
select | |
user_id | |
, max(updated_at) as latest_updated_at | |
from | |
${ref("reputation_data_v")} | |
group by | |
user_id | |
) y | |
) s | |
on t.user_id = s.user_id | |
when matched then | |
update set updated_at = s.latest_updated_at, user_id = s.user_id | |
when not matched then | |
insert (updated_at, user_id) values (latest_updated_at, user_id) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment