From bca0c234ef0e16a7395287c3e9cb9d1cfc04fe3a Mon Sep 17 00:00:00 2001 From: cdolfi Date: Fri, 25 Aug 2023 14:34:11 -0400 Subject: [PATCH] added materialized view contents into docs --- docs/explorer_contributor_actions.sql | 139 ++++++++++++++++++++++++++ queries/company_query.py | 5 + queries/contributors_query.py | 5 + 3 files changed, 149 insertions(+) create mode 100644 docs/explorer_contributor_actions.sql diff --git a/docs/explorer_contributor_actions.sql b/docs/explorer_contributor_actions.sql new file mode 100644 index 00000000..bbad944b --- /dev/null +++ b/docs/explorer_contributor_actions.sql @@ -0,0 +1,139 @@ +/* This is the SQL query that populates the explorer_contributor_actions materialized view*/ + +SELECT + A.ID AS cntrb_id, + A.created_at, + A.repo_id, + A.ACTION, + repo.repo_name, + A.LOGIN, + DENSE_RANK() OVER(PARTITION BY A.ID, A.repo_id ORDER BY A.created_at) AS RANK +FROM ( + select + commits.cmt_ght_author_id AS ID, + commits.cmt_author_timestamp AS created_at, + commits.repo_id, + 'commit' :: TEXT AS ACTION, + contributors.cntrb_login AS LOGIN + FROM + ( augur_data.commits LEFT JOIN augur_data.contributors ON ( ( ( contributors.cntrb_id ) :: TEXT = ( commits.cmt_ght_author_id ) :: TEXT ) ) ) + GROUP BY + commits.cmt_commit_hash, + commits.cmt_ght_author_id, + commits.repo_id, + commits.cmt_author_timestamp, + 'commit' :: TEXT, + contributors.cntrb_login + UNION all + SELECT + issues.reporter_id AS ID, + issues.created_at, + issues.repo_id, + 'issue_opened' :: TEXT AS ACTION, + contributors.cntrb_login AS LOGIN + FROM + ( augur_data.issues LEFT JOIN augur_data.contributors ON ( ( contributors.cntrb_id = issues.reporter_id ) ) ) + WHERE + ( issues.pull_request IS NULL ) + UNION ALL + SELECT + pull_request_events.cntrb_id AS ID, + pull_request_events.created_at, + pull_requests.repo_id, + 'pull_request_closed' :: TEXT AS ACTION, + contributors.cntrb_login AS LOGIN + FROM + augur_data.pull_requests, + ( augur_data.pull_request_events LEFT JOIN augur_data.contributors ON ( ( contributors.cntrb_id = pull_request_events.cntrb_id ) ) ) + WHERE + pull_requests.pull_request_id = pull_request_events.pull_request_id + AND pull_requests.pr_merged_at IS NULL + AND ( ( pull_request_events.ACTION ) :: TEXT = 'closed' :: TEXT ) + UNION ALL + SELECT + pull_request_events.cntrb_id AS ID, + pull_request_events.created_at, + pull_requests.repo_id, + 'pull_request_merged' :: TEXT AS ACTION, + contributors.cntrb_login AS LOGIN + FROM + augur_data.pull_requests, + ( augur_data.pull_request_events LEFT JOIN augur_data.contributors ON ( ( contributors.cntrb_id = pull_request_events.cntrb_id ) ) ) + WHERE + pull_requests.pull_request_id = pull_request_events.pull_request_id + AND ( ( pull_request_events.ACTION ) :: TEXT = 'merged' :: TEXT ) + UNION ALL + SELECT + issue_events.cntrb_id AS ID, + issue_events.created_at, + issues.repo_id, + 'issue_closed' :: TEXT AS ACTION, + contributors.cntrb_login AS LOGIN + FROM + augur_data.issues, + augur_data.issue_events + LEFT JOIN augur_data.contributors ON contributors.cntrb_id = issue_events.cntrb_id + WHERE + issues.issue_id = issue_events.issue_id + AND issues.pull_request IS NULL + AND ( ( issue_events.ACTION ) :: TEXT = 'closed' :: TEXT ) + UNION ALL + SELECT + pull_request_reviews.cntrb_id AS ID, + pull_request_reviews.pr_review_submitted_at AS created_at, + pull_requests.repo_id, + ( 'pull_request_review_' :: TEXT || ( pull_request_reviews.pr_review_state ) :: TEXT ) AS ACTION, + contributors.cntrb_login AS LOGIN + FROM + augur_data.pull_requests, + augur_data.pull_request_reviews + LEFT JOIN augur_data.contributors ON contributors.cntrb_id = pull_request_reviews.cntrb_id + WHERE + pull_requests.pull_request_id = pull_request_reviews.pull_request_id + UNION ALL + SELECT + pull_requests.pr_augur_contributor_id AS ID, + pull_requests.pr_created_at AS created_at, + pull_requests.repo_id, + 'pull_request_open' :: TEXT AS ACTION, + contributors.cntrb_login AS LOGIN + FROM + augur_data.pull_requests + LEFT JOIN augur_data.contributors ON pull_requests.pr_augur_contributor_id = contributors.cntrb_id + UNION ALL + SELECT + message.cntrb_id AS ID, + message.msg_timestamp AS created_at, + pull_requests.repo_id, + 'pull_request_comment' :: TEXT AS ACTION, + contributors.cntrb_login AS LOGIN + FROM + augur_data.pull_requests, + augur_data.pull_request_message_ref, + augur_data.message + LEFT JOIN augur_data.contributors ON contributors.cntrb_id = message.cntrb_id + WHERE + pull_request_message_ref.pull_request_id = pull_requests.pull_request_id + AND pull_request_message_ref.msg_id = message.msg_id + UNION ALL + SELECT + issues.reporter_id AS ID, + message.msg_timestamp AS created_at, + issues.repo_id, + 'issue_comment' :: TEXT AS ACTION, + contributors.cntrb_login AS LOGIN + FROM + augur_data.issues, + augur_data.issue_message_ref, + augur_data.message + LEFT JOIN augur_data.contributors ON contributors.cntrb_id = message.cntrb_id + WHERE + issue_message_ref.msg_id = message.msg_id + AND issues.issue_id = issue_message_ref.issue_id + AND issues.closed_at != message.msg_timestamp + ) A, + augur_data.repo + WHERE + A.repo_id = repo.repo_id + ORDER BY + A.created_at DESC diff --git a/queries/company_query.py b/queries/company_query.py index ce50889b..6217d59e 100644 --- a/queries/company_query.py +++ b/queries/company_query.py @@ -22,6 +22,10 @@ def company_query(self, repos): (Worker Query) Executes SQL query against Augur database for company affiliation data. + Explorer_contributor_actions is a materialized view on the database for quicker run time and + may not be in your augur database. The SQL query content can be found + in docs/explorer_contributor_actions.sql + Args: ----- repo_ids ([str]): repos that SQL query is executed on. @@ -29,6 +33,7 @@ def company_query(self, repos): Returns: -------- dict: Results from SQL query, interpreted from pd.to_dict('records') + """ logging.warning(f"{QUERY_NAME}_DATA_QUERY - START") diff --git a/queries/contributors_query.py b/queries/contributors_query.py index edf3a323..0806f423 100644 --- a/queries/contributors_query.py +++ b/queries/contributors_query.py @@ -22,6 +22,10 @@ def contributors_query(self, repos): (Worker Query) Executes SQL query against Augur database for contributor data. + Explorer_contributor_actions is a materialized view on the database for quicker run time and + may not be in your augur database. The SQL query content can be found + in docs/explorer_contributor_actions.sql + Args: ----- repo_ids ([str]): repos that SQL query is executed on. @@ -29,6 +33,7 @@ def contributors_query(self, repos): Returns: -------- dict: Results from SQL query, interpreted from pd.to_dict('records') + """ logging.warning(f"{QUERY_NAME}_DATA_QUERY - START")