-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: refactor
int_oss_funding_grants_to_project
(#2313)
* chore: bump source to new schema * fix: gitcoin funding events to handle missing dates * fix: dlt should replace instead of append tables * fix: gitcoin project directory removes duplicates * feat(dbt): union oss funding sources * fix(dbt): address linting issues
- Loading branch information
Showing
8 changed files
with
152 additions
and
75 deletions.
There are no files selected for viewing
72 changes: 57 additions & 15 deletions
72
warehouse/dbt/models/intermediate/funding/int_gitcoin_funding_events.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 |
---|---|---|
@@ -1,23 +1,65 @@ | ||
{# | ||
This model combines the donations and matching grants data to create a single table of funding events. | ||
The `funding_type` column is used to differentiate between donations and matching grants. | ||
The `event_time` data has some issues. It is missing for matching grants, so we use the most recent donation timestamp as a placeholder. To the cGrants data, we use a placeholder date of 2023-07-01. | ||
#} | ||
|
||
|
||
with last_donation_by_round as ( | ||
select | ||
round_id, | ||
round_number, | ||
gitcoin_project_id, | ||
max(donation_timestamp) as assumed_event_time | ||
from {{ ref('stg_gitcoin__donations') }} | ||
group by | ||
round_id, | ||
round_number, | ||
gitcoin_project_id | ||
), | ||
|
||
unioned_events as ( | ||
select | ||
transaction_hash, | ||
donation_timestamp as event_time, | ||
round_id, | ||
round_number, | ||
chain_id, | ||
gitcoin_project_id, | ||
donor_address, | ||
amount_in_usd, | ||
'DONATIONS' as funding_type | ||
from {{ ref('stg_gitcoin__donations') }} | ||
|
||
union all | ||
|
||
select | ||
null as transaction_hash, | ||
last_donation_by_round.assumed_event_time as event_time, | ||
matching.round_id, | ||
matching.round_number, | ||
matching.chain_id, | ||
matching.gitcoin_project_id, | ||
null as donor_address, | ||
matching.amount_in_usd, | ||
'MATCHING' as funding_type | ||
from {{ ref('stg_gitcoin__matching') }} as matching | ||
left join last_donation_by_round | ||
on | ||
matching.round_id = last_donation_by_round.round_id | ||
and matching.round_number = last_donation_by_round.round_number | ||
and matching.gitcoin_project_id = last_donation_by_round.gitcoin_project_id | ||
) | ||
|
||
select | ||
transaction_hash, | ||
donation_timestamp as event_time, | ||
round_id, | ||
round_number, | ||
chain_id, | ||
gitcoin_project_id, | ||
donor_address, | ||
amount_in_usd, | ||
'crowdfunding' as funding_type | ||
from {{ ref('stg_gitcoin__donations') }} | ||
union all | ||
select | ||
null as transaction_hash, | ||
null as event_time, | ||
round_id, | ||
round_number, | ||
chain_id, | ||
gitcoin_project_id, | ||
null as donor_address, | ||
amount_in_usd, | ||
'matching_grant' as funding_type | ||
from {{ ref('stg_gitcoin__matching') }} | ||
funding_type, | ||
coalesce(event_time, timestamp('2023-07-01')) as event_time | ||
from unioned_events | ||
where amount_in_usd > 0 |
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
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
13 changes: 10 additions & 3 deletions
13
warehouse/dbt/models/staging/gitcoin/stg_gitcoin__matching.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 |
---|---|---|
@@ -1,10 +1,17 @@ | ||
with max_dlt as ( | ||
select max(_dlt_load_id) as max_dlt_load_id | ||
from {{ source("gitcoin", "all_matching") }} | ||
) | ||
|
||
select distinct | ||
round_id as round_id, | ||
round_num as round_number, | ||
chain_id, | ||
project_id as gitcoin_project_id, | ||
match_amount_in_usd as amount_in_usd, | ||
TRIM(title) as round_title, | ||
LOWER(recipient_address) as project_recipient_address | ||
trim(title) as round_title, | ||
lower(recipient_address) as project_recipient_address | ||
from {{ source("gitcoin", "all_matching") }} | ||
where match_amount_in_usd > 0 | ||
where | ||
match_amount_in_usd > 0 | ||
and _dlt_load_id = (select max_dlt.max_dlt_load_id from max_dlt) |
18 changes: 12 additions & 6 deletions
18
warehouse/dbt/models/staging/gitcoin/stg_gitcoin__project_groups.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 |
---|---|---|
@@ -1,13 +1,19 @@ | ||
select distinct | ||
with max_dlt as ( | ||
select max(_dlt_load_id) as max_dlt_load_id | ||
from {{ source("gitcoin", "project_groups_summary") }} | ||
) | ||
|
||
select | ||
group_id as gitcoin_group_id, | ||
latest_created_project_id as latest_gitcoin_project_id, | ||
total_amount_donated as total_amount_donated_in_usd, | ||
application_count as group_application_count, | ||
latest_created_application as latest_project_application_timestamp, | ||
latest_source as latest_gitcoin_data_source, | ||
TRIM(title) as project_application_title, | ||
LOWER(latest_payout_address) as latest_project_recipient_address, | ||
TRIM(LOWER(latest_website)) as latest_project_website, | ||
TRIM(LOWER(latest_project_twitter)) as latest_project_twitter, | ||
TRIM(LOWER(latest_project_github)) as latest_project_github | ||
trim(title) as project_application_title, | ||
lower(latest_payout_address) as latest_project_recipient_address, | ||
trim(lower(latest_website)) as latest_project_website, | ||
trim(lower(latest_project_twitter)) as latest_project_twitter, | ||
trim(lower(latest_project_github)) as latest_project_github | ||
from {{ source("gitcoin", "project_groups_summary") }} | ||
where _dlt_load_id = (select max_dlt.max_dlt_load_id from max_dlt) |
6 changes: 6 additions & 0 deletions
6
warehouse/dbt/models/staging/gitcoin/stg_gitcoin__project_lookup.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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
with max_dlt as ( | ||
select max(_dlt_load_id) as max_dlt_load_id | ||
from {{ source("gitcoin", "project_lookup") }} | ||
) | ||
|
||
select distinct | ||
group_id as gitcoin_group_id, | ||
project_id as gitcoin_project_id, | ||
source as latest_gitcoin_data_source | ||
from {{ source("gitcoin", "project_lookup") }} | ||
where _dlt_load_id = (select max_dlt.max_dlt_load_id from max_dlt) |
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
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