forked from dora-team/fourkeys
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from mozilla-services/use-canonical-service-name
Use canonical service name in BigQuery views
- Loading branch information
Showing
3 changed files
with
96 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,39 @@ | ||
-- Changes View: The `change_id` field is a Git commit's ID | ||
WITH | ||
pushes AS ( | ||
SELECT | ||
source, | ||
event_type, | ||
CASE | ||
WHEN source LIKE "github%" THEN JSON_EXTRACT_SCALAR(metadata, '$.repository.full_name') | ||
END | ||
AS metadata_service, | ||
JSON_EXTRACT_SCALAR(commit, '$.id') AS change_id, | ||
TIMESTAMP_TRUNC(TIMESTAMP(JSON_EXTRACT_SCALAR(commit, '$.timestamp')),second) AS time_created | ||
FROM | ||
`four_keys.events_raw` e, | ||
-- Create a row for each element in the array of `commits` from the `metadata` field. | ||
-- The other fields in the row are repeated for each `commit`. | ||
UNNEST(JSON_EXTRACT_ARRAY(e.metadata, '$.commits')) AS commit | ||
WHERE | ||
event_type = "push" | ||
GROUP BY | ||
1, | ||
2, | ||
3, | ||
4, | ||
5 | ||
) | ||
SELECT | ||
source, | ||
event_type, | ||
pushes.*, | ||
service_catalog.service, | ||
FROM | ||
pushes | ||
LEFT JOIN | ||
`four_keys.services` AS service_catalog | ||
ON | ||
CASE | ||
WHEN source LIKE "github%" THEN JSON_EXTRACT_SCALAR(metadata, '$.repository.full_name') | ||
WHEN pushes.source = "pagerduty" THEN pushes.metadata_service = service_catalog.pagerduty_service | ||
WHEN pushes.source = "github" THEN pushes.metadata_service = service_catalog.github_repository | ||
ELSE FALSE | ||
END | ||
AS service, | ||
JSON_EXTRACT_SCALAR(commit, '$.id') AS change_id, | ||
TIMESTAMP_TRUNC(TIMESTAMP(JSON_EXTRACT_SCALAR(commit, '$.timestamp')),second) AS time_created | ||
FROM | ||
four_keys.events_raw e, | ||
-- Create a row for each element in the array of `commits` from the `metadata` field. | ||
-- The other fields in the row are repeated for each `commit`. | ||
UNNEST(JSON_EXTRACT_ARRAY(e.metadata, '$.commits')) AS commit | ||
WHERE | ||
event_type = "push" | ||
GROUP BY | ||
1, | ||
2, | ||
3, | ||
4, | ||
5 |
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