Skip to content

Commit

Permalink
dbt: refactor projects mart to use int model (#1262)
Browse files Browse the repository at this point in the history
* refactor: create int_projects

* update projects mart

* change comments
  • Loading branch information
ccerv1 authored Apr 20, 2024
1 parent cf7e7b2 commit 6c407ce
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ WITH ranked_repos AS (
ROW_NUMBER() OVER (
PARTITION BY project_id ORDER BY star_count DESC
) AS row_number,
COUNT(DISTINCT owner) OVER (PARTITION BY project_id) AS num_github_owners
COUNT(DISTINCT owner) OVER (PARTITION BY project_id) AS count_github_owners
FROM {{ ref('stg_ossd__repositories_by_project') }}
)

SELECT
project_id,
num_github_owners,
count_github_owners,
LOWER(owner) AS primary_github_owner
--TODO: is_git_organization
FROM ranked_repos
WHERE row_number = 1
36 changes: 36 additions & 0 deletions warehouse/dbt/models/intermediate/directory/int_projects.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
WITH ranked_repos AS (
SELECT
project_id,
owner,
star_count,
ROW_NUMBER() OVER (
PARTITION BY project_id ORDER BY star_count DESC
) AS row_number,
COUNT(DISTINCT owner) OVER (PARTITION BY project_id) AS count_github_owners
FROM {{ ref('stg_ossd__repositories_by_project') }}
),

project_owners AS (
SELECT
project_id,
count_github_owners,
LOWER(owner) AS primary_github_owner
{# TODO: is_git_organization #}
FROM ranked_repos
WHERE row_number = 1
)

SELECT
p.id AS project_id,
p.slug AS project_slug,
{# TODO: description AS project_description #}
p.name AS project_name,
p.namespace AS namespace,
po.primary_github_owner,
po.count_github_owners,
ARRAY_LENGTH(JSON_EXTRACT_ARRAY(p.github)) AS count_github_artifacts,
ARRAY_LENGTH(JSON_EXTRACT_ARRAY(p.blockchain)) AS count_blockchain_artifacts,
ARRAY_LENGTH(JSON_EXTRACT_ARRAY(p.npm)) AS count_npm_artifacts
FROM {{ ref('stg_ossd__current_projects') }} AS p
LEFT JOIN project_owners AS po
ON p.id = po.project_id
17 changes: 8 additions & 9 deletions warehouse/dbt/models/marts/directory/projects.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
}}

SELECT
id AS project_id,
slug AS project_slug,
-- description AS project_description,
name AS project_name,
namespace AS user_namespace,
ARRAY_LENGTH(JSON_EXTRACT_ARRAY(github)) AS count_github_artifacts,
ARRAY_LENGTH(JSON_EXTRACT_ARRAY(blockchain)) AS count_blockchain_artifacts,
ARRAY_LENGTH(JSON_EXTRACT_ARRAY(npm)) AS count_npm_artifacts
FROM {{ ref('stg_ossd__current_projects') }}
project_id,
project_slug,
project_name,
count_github_owners,
count_github_artifacts,
count_blockchain_artifacts,
count_npm_artifacts
FROM {{ ref('int_projects') }}

0 comments on commit 6c407ce

Please sign in to comment.