Skip to content

Instantly share code, notes, and snippets.

@aymanfarhat
Last active August 10, 2022 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aymanfarhat/93e72177b67ffeada662d262bfe5c7a0 to your computer and use it in GitHub Desktop.
Save aymanfarhat/93e72177b67ffeada662d262bfe5c7a0 to your computer and use it in GitHub Desktop.
#Copyright 2022 Google LLC.
#SPDX-License-Identifier: Apache-2.0
WITH
initial_log AS (
SELECT
commit_hash,
author_name,
author_email,
TIMESTAMP_SECONDS(author_date) AS author_date,
REGEXP_EXTRACT(file, "(tools|examples)/[^/]+/.*") AS type,
REGEXP_EXTRACT(file, "[tools|examples]/([^/]+)/.*") AS sub_repo,
file,
FROM
`myproject.gitlogs.pso`
WHERE
REGEXP_EXTRACT(file, "(tools|examples)/[^/]+/.*") IS NOT NULL
AND REGEXP_EXTRACT(file, "[tools|examples]/([^/]+)/.*") IS NOT NULL)
SELECT
type,
sub_repo,
MAX(author_date) AS last_author_date,
ARRAY_AGG(DISTINCT author_email) AS authors,
FROM
initial_log
GROUP BY
type,
sub_repo
ORDER BY
last_author_date DESC
#Copyright 2022 Google LLC.
#SPDX-License-Identifier: Apache-2.0
WITH
initial_log AS (
SELECT
commit_hash,
author_name,
author_email,
TIMESTAMP_SECONDS(author_date) AS author_date,
REGEXP_EXTRACT(file, "(tools|examples)/[^/]+/.*") AS type,
REGEXP_EXTRACT(file, "[tools|examples]/([^/]+)/.*") AS sub_repo,
file,
FROM
`myproject.gitlogs.pso`
WHERE
REGEXP_EXTRACT(file, "(tools|examples)/[^/]+/.*") IS NOT NULL
AND REGEXP_EXTRACT(file, "[tools|examples]/([^/]+)/.*") IS NOT NULL)
SELECT
author_email,
sub_repo,
COUNT(DISTINCT commit_hash) AS commits_in_folder
FROM
initial_log
GROUP BY
author_email,
sub_repo
#Copyright 2022 Google LLC.
#SPDX-License-Identifier: Apache-2.0
SELECT
commit_hash,
author_name,
author_email,
TIMESTAMP_SECONDS(author_date) AS author_date,
REGEXP_EXTRACT(file, "(tools|examples)/[^/]+/.*") AS type,
REGEXP_EXTRACT(file, "[tools|examples]/([^/]+)/.*") AS sub_repo,
file,
FROM
`myproject.gitlogs.pso`
WHERE
REGEXP_EXTRACT(file, "(tools|examples)/[^/]+/.*") IS NOT NULL
AND REGEXP_EXTRACT(file, "[tools|examples]/([^/]+)/.*") IS NOT NULL
#Copyright 2022 Google LLC.
#SPDX-License-Identifier: Apache-2.0
WITH
initial_log AS (
SELECT
commit_hash,
author_name,
author_email,
TIMESTAMP_SECONDS(author_date) AS author_date,
REGEXP_EXTRACT(file, "(tools|examples)/[^/]+/.*") AS type,
REGEXP_EXTRACT(file, "[tools|examples]/([^/]+)/.*") AS sub_repo,
file,
FROM
`myproject.gitlogs.pso`
WHERE
REGEXP_EXTRACT(file, "(tools|examples)/[^/]+/.*") IS NOT NULL
AND REGEXP_EXTRACT(file, "[tools|examples]/([^/]+)/.*") IS NOT NULL)
SELECT
type,
sub_repo,
MAX(author_date) AS last_author_date
FROM
initial_log
GROUP BY
type,
sub_repo
ORDER BY
last_author_date DESC
#Copyright 2022 Google LLC.
#SPDX-License-Identifier: Apache-2.0
WITH
initial_log AS (
SELECT
commit_hash,
author_name,
author_email,
TIMESTAMP_SECONDS(author_date) AS author_date,
REGEXP_EXTRACT(file, "(tools|examples)/[^/]+/.*") AS type,
REGEXP_EXTRACT(file, "[tools|examples]/([^/]+)/.*") AS sub_repo,
file,
FROM
`myproject.gitlogs.pso`
WHERE
REGEXP_EXTRACT(file, "(tools|examples)/[^/]+/.*") IS NOT NULL
AND REGEXP_EXTRACT(file, "[tools|examples]/([^/]+)/.*") IS NOT NULL),
commits_repo_author AS (
SELECT
sub_repo,
author_email,
type,
COUNT(DISTINCT commit_hash) AS commits_in_folder
FROM
initial_log
GROUP BY
author_email,
sub_repo,
type)
SELECT
type,
sub_repo,
ARRAY_AGG(STRUCT(author_email,
commits_in_folder)
ORDER BY
commits_in_folder DESC) AS authors
FROM
commits_repo_author
GROUP BY
type,
sub_repo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment