Skip to content

Commit

Permalink
Sort out sqlfluff more
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenwindflower committed Feb 18, 2024
1 parent 359fa99 commit 067d241
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 21 deletions.
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ repos:
hooks:
- id: black
- repo: https://github.com/sqlfluff/sqlfluff
rev: 3.0.0a5
rev: 2.3.5
hooks:
- id: sqlfluff-fix
args: ["./models/"]
additional_dependencies:
["dbt-metricflow[duckdb]~=0.3.0", "sqlfluff-templater-dbt"]
["dbt-duckdb~=1.7.1", "sqlfluff-templater-dbt~=2.3.5"]
3 changes: 3 additions & 0 deletions .sqlfluffignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
target/
dbt_packages/
macros/
.venv
reports/
generate_fixtures.sql
7 changes: 5 additions & 2 deletions models/marts/issue_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ issue_events as (

select *, from {{ ref('stg_events') }}

where event_type = 'IssuesEvent'
where
event_type = 'IssuesEvent'

{% if is_incremental() %}
and stg_events.event_created_at >= coalesce((select max(event_created_at) from {{ this }}), '1900-01-01')
and stg_events.event_created_at >= coalesce(
(select max(event_created_at), from {{ this }}), '1900-01-01'
)
{% endif %}
),

Expand Down
7 changes: 5 additions & 2 deletions models/marts/pull_request_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ pull_request_events as (

select *, from {{ ref('stg_events') }}

where event_type = 'PullRequestEvent'
where
event_type = 'PullRequestEvent'

{% if is_incremental() %}
and stg_events.event_created_at >= coalesce((select max(event_created_at) from {{ this }}), '1900-01-01')
and stg_events.event_created_at >= coalesce(
(select max(event_created_at), from {{ this }}), '1900-01-01'
)
{% endif %}
),

Expand Down
7 changes: 5 additions & 2 deletions models/marts/push_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ push_events as (

select *, from {{ ref('stg_events') }}

where event_type in ('PushEvent')
where
event_type in ('PushEvent')

{% if is_incremental() %}
and stg_events.event_created_at >= coalesce((select max(event_created_at) from {{ this }}), '1900-01-01')
and stg_events.event_created_at >= coalesce(
(select max(event_created_at), from {{ this }}), '1900-01-01'
)
{% endif %}
),

Expand Down
23 changes: 14 additions & 9 deletions models/marts/repos.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,27 @@ with
distill_repos_from_events as (

select
{{ dbt_utils.generate_surrogate_key([
'repo_id',
'repo_name',
'repo_url'
]) }} as repo_state_uuid,
{{
dbt_utils.generate_surrogate_key([
'repo_id',
'repo_name',
'repo_url'
])
}} as repo_state_uuid,
repo_id,
repo_name,
repo_url,
max(event_created_at) as repo_state_last_seen_at,

from {{ ref('stg_events') }}

where true
where
true

{% if is_incremental() %}
and stg_events.event_created_at >= coalesce((select max(updated_at) from {{ this }}), '1900-01-01')
and stg_events.event_created_at >= coalesce(
(select max(updated_at), from {{ this }}), '1900-01-01'
)
{% endif %}

group by all
Expand All @@ -38,11 +43,11 @@ rank_most_recent_repo_state as (
repo_id,
repo_name,
repo_url,
repo_state_last_seen_at as updated_at,
row_number() over (
partition by repo_id
order by repo_state_last_seen_at desc
) as repo_recency_rank,
repo_state_last_seen_at as updated_at,

from distill_repos_from_events

Expand All @@ -54,7 +59,7 @@ pull_most_recent_repo_state as (
repo_id,
repo_name,
repo_url,
updated_at
updated_at,

from rank_most_recent_repo_state

Expand Down
11 changes: 7 additions & 4 deletions models/marts/users.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ distill_user_states_from_events as (

from {{ ref('stg_events') }}

where true

where
true

{% if is_incremental() %}
and stg_events.event_created_at >= coalesce((select max(updated_at) from {{ this }}), '1900-01-01')
and stg_events.event_created_at >= coalesce(
(select max(updated_at), from {{ this }}), '1900-01-01'
)
{% endif %}

group by all
Expand All @@ -49,11 +52,11 @@ rank_user_state_recency as (
actor_display_login,
actor_url,
actor_avatar_url,
user_state_last_seen_at as updated_at,
row_number() over (
partition by actor_id
order by user_state_last_seen_at desc
) as user_state_recency_rank,
user_state_last_seen_at as updated_at,

from distill_user_states_from_events

Expand Down

0 comments on commit 067d241

Please sign in to comment.