-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update api_calls to extract_summary #138
Changes from all commits
296088f
8e1b1ab
a37121f
90c8ec3
e58eca0
4bbc894
7882b7b
c95351e
3d54ef3
89a3650
0bfed66
3367542
65483eb
eb451f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,39 +7,56 @@ with connector as ( | |
), | ||
|
||
-- grab api calls, schema changes, and record modifications | ||
|
||
log_events as ( | ||
|
||
select | ||
connector_id, | ||
cast( {{ dbt.date_trunc('day', 'created_at') }} as date) as date_day, | ||
case | ||
when event_subtype in ('create_table', 'alter_table', 'create_schema', 'change_schema_config') then 'schema_change' | ||
else event_subtype end as event_subtype, | ||
|
||
sum(case when event_subtype = 'records_modified' then cast( {{ fivetran_log.fivetran_log_json_parse(string='message_data', string_path=['count']) }} as {{ dbt.type_bigint()}} ) | ||
else 1 end) as count_events | ||
event_subtype, | ||
message_data | ||
|
||
from {{ ref('stg_fivetran_platform__log') }} | ||
|
||
where event_subtype in ('api_call', | ||
'records_modified', | ||
'create_table', 'alter_table', 'create_schema', 'change_schema_config') -- all schema changes | ||
|
||
where event_subtype in ( | ||
'api_call', 'extract_summary', 'records_modified', 'create_table', 'alter_table', | ||
'create_schema', 'change_schema_config') -- all relevant event subtypes | ||
and connector_id is not null | ||
), | ||
|
||
agg_log_events as ( | ||
|
||
group by connector_id, cast( {{ dbt.date_trunc('day', 'created_at') }} as date), event_subtype | ||
select | ||
connector_id, | ||
date_day, | ||
case | ||
when event_subtype in ('create_table', 'alter_table', 'create_schema', 'change_schema_config') then 'schema_change' | ||
else event_subtype end as event_subtype, | ||
|
||
sum( | ||
case | ||
when event_subtype = 'records_modified' | ||
then cast({{ fivetran_log.fivetran_log_json_parse(string='message_data', string_path=['count']) }} as {{ dbt.type_bigint()}} ) | ||
when event_subtype = 'extract_summary' | ||
then cast({{ fivetran_log.fivetran_log_json_parse(string='message_data', string_path=['total_queries']) }} as {{ dbt.type_bigint()}}) | ||
else 1 | ||
end | ||
) as count_events | ||
|
||
from log_events | ||
group by connector_id, date_day, event_subtype | ||
), | ||
|
||
pivot_out_events as ( | ||
|
||
select | ||
connector_id, | ||
date_day, | ||
max(case when event_subtype = 'api_call' then count_events else 0 end) as count_api_calls, | ||
max(case when event_subtype = 'api_call' or event_subtype = 'extract_summary' then count_events else 0 end) as count_api_calls, | ||
max(case when event_subtype = 'records_modified' then count_events else 0 end) as count_record_modifications, | ||
max(case when event_subtype = 'schema_change' then count_events else 0 end) as count_schema_changes | ||
|
||
from log_events | ||
from agg_log_events | ||
group by connector_id, date_day | ||
), | ||
|
||
|
@@ -63,7 +80,7 @@ connector_event_counts as ( | |
|
||
spine as ( | ||
|
||
{% if execute %} | ||
{% if execute and flags.WHICH in ('run', 'build') %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you note in the "under the hood" section of the CHANGELOG that this release supports There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, updated! |
||
{% set first_date_query %} | ||
select min( signed_up ) as min_date from {{ var('connector') }} | ||
{% endset %} | ||
|
@@ -78,7 +95,7 @@ spine as ( | |
{{ fivetran_utils.fivetran_date_spine( | ||
datepart = "day", | ||
start_date = "cast('" ~ first_date[0:10] ~ "' as date)", | ||
end_date = dbt.dateadd("week", 1, dbt.date_trunc('day', dbt.current_timestamp_backcompat() if target.type != 'sqlserver' else dbt.current_timestamp())) | ||
end_date = dbt.dateadd("week", 1, dbt.date_trunc('day', dbt.current_timestamp())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super duper minor -- would you mind updating the parallel line in the row_count__connector_daily_events test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call. updated! |
||
) | ||
}} | ||
) as date_spine | ||
|
@@ -138,7 +155,7 @@ final as ( | |
select * | ||
from join_event_history | ||
|
||
where date_day <= cast({{ dbt.current_timestamp_backcompat() if target.type != 'sqlserver' else dbt.current_timestamp() }} as date) | ||
where date_day <= cast({{ dbt.current_timestamp() }} as date) | ||
) | ||
|
||
select * | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making this change as well!