Skip to content

Commit

Permalink
Auxiliary events table for issues (#2512)
Browse files Browse the repository at this point in the history
* Auxiliary events table for issues

* Create mart for auxiliary table
  • Loading branch information
ravenac95 authored Nov 22, 2024
1 parent bf53eb7 commit 52147fe
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 0 deletions.
123 changes: 123 additions & 0 deletions warehouse/dbt/models/intermediate/events/int_events_aux_issues.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{{
config(
materialized='table',
partition_by={
"field": "time",
"data_type": "timestamp",
"granularity": "day",
},
meta={
'sync_to_db': False
}
)
}}

with github_comments as (
select -- noqa: ST06
created_at as `time`,
type as event_type,
CAST(id as STRING) as event_source_id,
"GITHUB" as event_source,
SPLIT(REPLACE(repository_name, "@", ""), "/")[SAFE_OFFSET(1)]
as to_name,
SPLIT(REPLACE(repository_name, "@", ""), "/")[SAFE_OFFSET(0)]
as to_namespace,
"REPOSITORY" as to_type,
CAST(repository_id as STRING) as to_artifact_source_id,
actor_login as from_name,
actor_login as from_namespace,
"GIT_USER" as from_type,
CAST(actor_id as STRING) as from_artifact_source_id,
`number` as issue_number
from {{ ref('stg_github__comments') }}
),

github_issues as (
select -- noqa: ST06
created_at as `time`,
type as event_type,
CAST(id as STRING) as event_source_id,
"GITHUB" as event_source,
SPLIT(REPLACE(repository_name, "@", ""), "/")[SAFE_OFFSET(1)]
as to_name,
SPLIT(REPLACE(repository_name, "@", ""), "/")[SAFE_OFFSET(0)]
as to_namespace,
"REPOSITORY" as to_type,
CAST(repository_id as STRING) as to_artifact_source_id,
actor_login as from_name,
actor_login as from_namespace,
"GIT_USER" as from_type,
CAST(actor_id as STRING) as from_artifact_source_id,
`number` as issue_number
from {{ ref('stg_github__issues') }}
),

github_pull_requests as (
select -- noqa: ST06
created_at as `time`,
type as event_type,
CAST(id as STRING) as event_source_id,
"GITHUB" as event_source,
SPLIT(REPLACE(repository_name, "@", ""), "/")[SAFE_OFFSET(1)]
as to_name,
SPLIT(REPLACE(repository_name, "@", ""), "/")[SAFE_OFFSET(0)]
as to_namespace,
"REPOSITORY" as to_type,
CAST(repository_id as STRING) as to_artifact_source_id,
actor_login as from_name,
actor_login as from_namespace,
"GIT_USER" as from_type,
CAST(actor_id as STRING) as from_artifact_source_id,
`number` as issue_number
from {{ ref('stg_github__pull_requests') }}
),

github_pull_request_merge_events as (
select -- noqa: ST06
created_at as `time`,
type as event_type,
CAST(id as STRING) as event_source_id,
"GITHUB" as event_source,
SPLIT(REPLACE(repository_name, "@", ""), "/")[SAFE_OFFSET(1)]
as to_name,
SPLIT(REPLACE(repository_name, "@", ""), "/")[SAFE_OFFSET(0)]
as to_namespace,
"REPOSITORY" as to_type,
CAST(repository_id as STRING) as to_artifact_source_id,
actor_login as from_name,
actor_login as from_namespace,
"GIT_USER" as from_type,
CAST(actor_id as STRING) as from_artifact_source_id,
`number` as issue_number
from {{ ref('stg_github__pull_request_merge_events') }}
),

issue_events as (
select
time,
event_type,
event_source_id,
event_source,
{{ oso_id("event_source", "to_artifact_source_id") }} as to_artifact_id,
{{ oso_id("event_source", "from_artifact_source_id") }} as from_artifact_id,
issue_number
from (
select * from github_issues
union all
select * from github_pull_requests
union all
select * from github_pull_request_merge_events
union all
select * from github_comments
)
)

select
time,
to_artifact_id,
from_artifact_id,
issue_number,
UPPER(event_type) as event_type,
CAST(event_source_id as STRING) as event_source_id,
UPPER(event_source) as event_source
from issue_events
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{
config(meta = {
'sync_to_db': True,
'order_by': [ 'event_source', 'event_type', 'to_artifact_id', 'time' ]
})
}}

select
time,
to_artifact_id,
from_artifact_id,
event_type,
event_source_id,
event_source,
issue_number
from {{ ref('int_events_aux_issues') }}

0 comments on commit 52147fe

Please sign in to comment.