-
Notifications
You must be signed in to change notification settings - Fork 0
feat(elt-pipelines): Port equipment downtime tables to elt-pipelines #484
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,130 @@ | ||||||
| {{ | ||||||
| config( | ||||||
| properties={ | ||||||
| "partitioning": "ARRAY['cycle_name']", | ||||||
| }, | ||||||
| on_table_exists = 'drop' | ||||||
| ) | ||||||
| }} | ||||||
|
|
||||||
| with | ||||||
|
|
||||||
| records_sharepoint as ( select * from {{ ref('stg_accelerator_sharepoint__equipment_downtime_data_11_08_24') }} ), | ||||||
|
|
||||||
| records_opralogweb as ( select * from {{ ref('stg_opralogweb__mcr_equipment_downtime') }} ), | ||||||
|
|
||||||
| equipment_name_mappings as ( select * from {{ ref('stg_accelerator_sharepoint__edr_equipment_mapping') }} ), | ||||||
|
|
||||||
| records_sharepoint_with_cycle_phase_col as ( | ||||||
|
|
||||||
| select | ||||||
|
|
||||||
| equipment, | ||||||
| fault_date, | ||||||
| cycle_name, | ||||||
| cast(NULL as varchar) as cycle_phase, | ||||||
| downtime_mins, | ||||||
| fault_occurred_at, | ||||||
| {{ adapter.quote('group') }}, | ||||||
| fault_description, | ||||||
| managers_comments | ||||||
|
|
||||||
| from | ||||||
|
|
||||||
| records_sharepoint | ||||||
|
|
||||||
| ), | ||||||
|
|
||||||
| records_opralogweb_after_sharepoint_joined_with_cycles as ( | ||||||
|
|
||||||
| select | ||||||
|
|
||||||
| r.equipment, | ||||||
| r.fault_date, | ||||||
| c.name as cycle_name, | ||||||
| c.phase as cycle_phase, | ||||||
| r.downtime_mins, | ||||||
| r.fault_occurred_at, | ||||||
| r.{{ adapter.quote('group') }}, | ||||||
| r.fault_description, | ||||||
| r.managers_comments | ||||||
|
|
||||||
| from records_opralogweb r | ||||||
| left join {{ ref("cycles") }} c on r.fault_occurred_at between c.started_at and c.ended_at | ||||||
| where fault_occurred_at > (select max(fault_occurred_at) from records_sharepoint_with_cycle_phase_col) | ||||||
| ), | ||||||
|
|
||||||
| all_records as ( | ||||||
|
|
||||||
| select * from records_sharepoint_with_cycle_phase_col | ||||||
| union | ||||||
|
Contributor
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. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: sed -n '1,135p' elt-pipelines/facility_ops/transform/models/marts/accelerator/mcr_equipment_downtime_records.sql
rg -n "mcr_equipment_downtime_records|equipment_downtime_data_11_08_24" warehouses elt-pipelines 2>/dev/nullRepository: ISISNeutronMuon/analytics-data-platform Length of output: 5461 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- model copies and related definitions ---'
for f in \
elt-pipelines/facility_ops/transform/models/marts/accelerator/mcr_equipment_downtime_records.sql \
warehouses/facility_ops/transform/models/marts/accelerator/mcr_equipment_downtime_records.sql \
elt-pipelines/facility_ops/transform/models/marts/accelerator/mcr_equipment_downtime_records.yml \
warehouses/facility_ops/transform/models/marts/accelerator/mcr_equipment_downtime_records.yml \
elt-pipelines/facility_ops/transform/models/staging/accelerator/stg_accelerator_sharepoint__equipment_downtime_data_11_08_24.yml \
warehouses/facility_ops/transform/models/staging/accelerator/stg_accelerator_sharepoint__equipment_downtime_data_11_08_24.yml \
elt-pipelines/facility_ops/transform/models/staging/accelerator/_accelerator__sources.yml \
warehouses/facility_ops/transform/models/staging/accelerator/_accelerator__sources.yml
do
if [ -f "$f" ]; then
echo "### $f"
cat -n "$f"
fi
done
printf '%s\n' '--- related tests and duplicate/history wording ---'
rg -n -i -C 3 \
'mcr_equipment_downtime_records|equipment_downtime|full history|duplicate|dedup|histor(y|ical)|fault_occurred_at|downtime_mins' \
elt-pipelines/facility_ops warehouses/facility_ops 2>/dev/null
printf '%s\n' '--- repository history summary for the two model paths ---'
git log --oneline --all --follow -- elt-pipelines/facility_ops/transform/models/marts/accelerator/mcr_equipment_downtime_records.sql | head -20
git log --oneline --all --follow -- warehouses/facility_ops/transform/models/marts/accelerator/mcr_equipment_downtime_records.sql | head -20Repository: ISISNeutronMuon/analytics-data-platform Length of output: 42117 🏁 Script executed: #!/bin/bash
set -eu
for f in \
elt-pipelines/facility_ops/transform/models/marts/accelerator/mcr_equipment_downtime_records.sql \
warehouses/facility_ops/transform/models/marts/accelerator/mcr_equipment_downtime_records.sql \
elt-pipelines/facility_ops/transform/models/marts/accelerator/mcr_equipment_downtime_records.yml \
warehouses/facility_ops/transform/models/marts/accelerator/mcr_equipment_downtime_records.yml \
elt-pipelines/facility_ops/transform/models/staging/accelerator/stg_accelerator_sharepoint__equipment_downtime_data_11_08_24.yml \
warehouses/facility_ops/transform/models/staging/accelerator/stg_accelerator_sharepoint__equipment_downtime_data_11_08_24.yml \
elt-pipelines/facility_ops/transform/models/staging/accelerator/_accelerator__sources.yml \
warehouses/facility_ops/transform/models/staging/accelerator/_accelerator__sources.yml
do
if [ -f "$f" ]; then
echo "### $f"
cat -n "$f"
fi
done
printf '%s\n' '--- related tests and history wording ---'
rg -n -i -C 3 'mcr_equipment_downtime_records|equipment_downtime|full history|duplicate|dedup|histor(y|ical)|fault_occurred_at|downtime_mins' elt-pipelines/facility_ops warehouses/facility_ops 2>/dev/null
printf '%s\n' '--- prior model history ---'
git log --oneline --all --follow -- elt-pipelines/facility_ops/transform/models/marts/accelerator/mcr_equipment_downtime_records.sql | head -20
git log --oneline --all --follow -- warehouses/facility_ops/transform/models/marts/accelerator/mcr_equipment_downtime_records.sql | head -20Repository: ISISNeutronMuon/analytics-data-platform Length of output: 42090 Preserve duplicate downtime records.
The model contract describes this output as a full history. Use Proposed fix- union
+ union all📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| select * from records_opralogweb_after_sharepoint_joined_with_cycles | ||||||
|
|
||||||
| ), | ||||||
|
|
||||||
| equipment_up_at_col as ( | ||||||
|
|
||||||
| select | ||||||
|
|
||||||
| {{ normalize_whitespace('equipment') }} as equipment, | ||||||
| fault_date, | ||||||
| cycle_name, | ||||||
| cycle_phase, | ||||||
| downtime_mins, | ||||||
| fault_occurred_at, | ||||||
| fault_occurred_at + (interval '1' minute * downtime_mins) as equipment_up_at, | ||||||
| {{ adapter.quote('group') }}, | ||||||
| fault_description, | ||||||
| managers_comments | ||||||
|
|
||||||
| from | ||||||
|
|
||||||
| all_records d | ||||||
| ), | ||||||
|
|
||||||
| uptime_col as ( | ||||||
|
|
||||||
| select | ||||||
|
|
||||||
| equipment, | ||||||
| fault_date, | ||||||
| cycle_name, | ||||||
| cycle_phase, | ||||||
| downtime_mins, | ||||||
| fault_occurred_at, | ||||||
| equipment_up_at, | ||||||
| date_diff('minute', | ||||||
| lag(equipment_up_at, 1, null) over | ||||||
| (partition by cycle_name, equipment order by fault_occurred_at), fault_occurred_at | ||||||
| ) as uptime_before_fault_mins, | ||||||
| {{ adapter.quote('group') }}, | ||||||
| fault_description, | ||||||
| managers_comments | ||||||
|
|
||||||
| from equipment_up_at_col | ||||||
| ), | ||||||
|
|
||||||
| equipment_category_col as ( | ||||||
|
|
||||||
| select | ||||||
|
|
||||||
| {{ normalize_whitespace('u.equipment') }} as equipment, | ||||||
| m.equipment_category as equipment_category, | ||||||
| fault_date, | ||||||
| cycle_name, | ||||||
| cycle_phase, | ||||||
| downtime_mins, | ||||||
| fault_occurred_at, | ||||||
| equipment_up_at, | ||||||
| uptime_before_fault_mins, | ||||||
| {{ adapter.quote('group') }}, | ||||||
| fault_description, | ||||||
| managers_comments | ||||||
|
|
||||||
| from uptime_col u | ||||||
| left join equipment_name_mappings m on {{ create_equipment_category_key('u.equipment') }} = m.equipment | ||||||
|
|
||||||
| ) | ||||||
|
|
||||||
| -- add order by clause for iceberg table sorting criterion | ||||||
| select * from equipment_category_col order by fault_occurred_at asc | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| models: | ||
| - name: mcr_equipment_downtime_records | ||
| description: > | ||
| A full history of MCR equipment failures, including downtime and fault descriptions |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| {{ | ||
| config( | ||
| on_table_exists = 'drop', | ||
| materialized = 'view' | ||
| ) | ||
| }} | ||
|
|
||
| select | ||
|
|
||
| distinct(equipment) as uncategorized_equipment | ||
|
|
||
| from | ||
|
|
||
| {{ ref('mcr_equipment_downtime_records') }} | ||
|
|
||
| where equipment_category is null |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,5 @@ | ||||||
| model: | ||||||
|
Contributor
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. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Use the dbt model properties require the top-level Proposed fix-model:
+models:📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| - name: mcr_equipment_downtime_uncategorized_equipment | ||||||
| description: > | ||||||
| Lists the equipment names for which no category has been found in the | ||||||
| EDR equipment mapping table. | ||||||
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.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: ISISNeutronMuon/analytics-data-platform
Length of output: 2283
🏁 Script executed:
Repository: ISISNeutronMuon/analytics-data-platform
Length of output: 41499
Handle an empty SharePoint cutoff. If the SharePoint relation is empty or has no non-null
fault_occurred_at,max(fault_occurred_at)isNULL. Thewherepredicate then evaluates toUNKNOWN, so it removes every non-null Opralogweb row. This violates the model description of providing a full MCR equipment-failure history.Use a null-cutoff fallback that retains valid Opralogweb history:
Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents