-
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.
Merge branch 'main' into ravenac95/fix-kubecluster-slots
- Loading branch information
Showing
4 changed files
with
145 additions
and
14 deletions.
There are no files selected for viewing
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
59 changes: 59 additions & 0 deletions
59
warehouse/dbt/models/intermediate/directory/int_open_collective_projects.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,59 @@ | ||
with url_registry as ( | ||
select | ||
LOWER(JSON_EXTRACT_SCALAR(to_account, '$.slug')) as project_slug, | ||
LOWER(JSON_EXTRACT_SCALAR(link, '$.url')) as github_url, | ||
REGEXP_EXTRACT(LOWER(JSON_EXTRACT_SCALAR(link, '$.url')), r'github\.com/([a-z0-9-]+)') | ||
as artifact_namespace, | ||
REGEXP_EXTRACT( | ||
LOWER(JSON_EXTRACT_SCALAR(link, '$.url')), r'github\.com/[a-z0-9-]+/([a-z0-9-._]+)' | ||
) as artifact_name | ||
from | ||
{{ ref('stg_open_collective__deposits') }}, | ||
UNNEST(JSON_EXTRACT_ARRAY(to_account, '$.socialLinks')) as link | ||
where | ||
JSON_EXTRACT_SCALAR(link, '$.url') like '%github.com%' | ||
), | ||
|
||
oso_projects as ( | ||
select | ||
project_id, | ||
artifact_namespace, | ||
artifact_name | ||
from {{ ref('repositories_v0') }} | ||
where artifact_source = 'GITHUB' | ||
), | ||
|
||
namespace_counts as ( | ||
select | ||
artifact_namespace, | ||
COUNT(distinct project_id) as project_count, | ||
MIN(project_id) as project_id | ||
from oso_projects | ||
group by artifact_namespace | ||
), | ||
|
||
matched_projects as ( | ||
select | ||
ur.*, | ||
case | ||
when op.project_id is not null then op.project_id | ||
when nc.project_count = 1 then nc.project_id | ||
end as project_id | ||
from url_registry as ur | ||
left join oso_projects as op | ||
on | ||
ur.artifact_namespace = op.artifact_namespace | ||
and ur.artifact_name = op.artifact_name | ||
left join namespace_counts as nc | ||
on ur.artifact_namespace = nc.artifact_namespace | ||
) | ||
|
||
select distinct | ||
project_id as project_id, | ||
{{ oso_id("'OPEN_COLLECTIVE'", 'project_slug') }} as artifact_id, | ||
project_slug as artifact_source_id, | ||
'OPEN_COLLECTIVE' as artifact_source, | ||
'' as artifact_namespace, | ||
project_slug as artifact_name, | ||
'https://opencollective.com/' || project_slug as artifact_url | ||
from matched_projects |
24 changes: 24 additions & 0 deletions
24
warehouse/dbt/models/intermediate/funding/int_open_collective_deposits.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,24 @@ | ||
with open_collective_deposits as ( | ||
select | ||
id as event_source_id, | ||
created_at as `time`, | ||
JSON_EXTRACT_SCALAR(to_account, '$.name') as project_name, | ||
LOWER(JSON_EXTRACT_SCALAR(to_account, '$.slug')) as project_slug, | ||
UPPER(JSON_EXTRACT_SCALAR(to_account, '$.type')) as project_type, | ||
UPPER(JSON_EXTRACT_SCALAR(amount, '$.currency')) as currency, | ||
CAST(JSON_EXTRACT_SCALAR(amount, '$.value') as NUMERIC) as amount | ||
from {{ ref('stg_open_collective__deposits') }} | ||
) | ||
|
||
select | ||
open_collective_deposits.event_source_id, | ||
open_collective_deposits.`time`, | ||
projects.project_id, | ||
open_collective_deposits.project_name, | ||
open_collective_deposits.project_slug, | ||
open_collective_deposits.project_type, | ||
open_collective_deposits.currency, | ||
open_collective_deposits.amount | ||
from open_collective_deposits | ||
left join {{ ref('int_open_collective_projects') }} as projects | ||
on open_collective_deposits.project_slug = projects.artifact_source_id |
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