{# "Cost Drivers by Spend" - same `ui-table` style as governor_web/_cost_drivers_table.html, with a server-side click-to-sort engine: each header is an that flips direction if the column is already active. Defaults to every logical job in the scan; the Finding filter can narrow to rows with issues/suggestions. #} {% from "components/_sort_header.html" import sort_header %} {% set _sort = sort_by | default('spend') %} {% set _dir = sort_dir | default('desc') %} {% set _sort_base_qs = pagination.query_string_without_sort_or_page if pagination.query_string_without_sort_or_page is defined else "" %} {% set _total_flagged = total_flagged_jobs if total_flagged_jobs is defined else pagination.total_items %} {% set _total_cost_drivers = total_cost_driver_jobs if total_cost_driver_jobs is defined else pagination.total_items %} {% set _table_aside = (pagination.total_items ~ " shown of " ~ _total_cost_drivers ~ " logical jobs · " ~ _total_flagged ~ " with findings · " ~ "{:,}".format(totals.total_jobs) ~ " scanned jobs") if pagination.total_items != _total_cost_drivers else (_total_cost_drivers ~ " logical jobs · " ~ _total_flagged ~ " with findings · " ~ "{:,}".format(totals.total_jobs) ~ " scanned jobs") %}
{% from "components/_section_title.html" import section_title %}
{{ section_title( cost_drivers_title | default("Cost Drivers by Spend"), description="Every logical job in the scan window, aggregated across executions (by destination table for builds, by normalized query hash for consumption) and ranked by total cost. Rows with findings open the highest-impact opportunity; clean rows open the representative job.", aside=_table_aside ) }}
{% if table_jobs %}
{# Dataset #} {# Object #} {# Spend #} {# Bytes #} {# Slot Time #} {# Issues #} {# Suggestions #} {# Workload #} {# Source #} {# Run At #} {{ sort_header('dataset', 'Dataset', _sort, _dir, base_qs=_sort_base_qs) }} {{ sort_header('object', 'Object', _sort, _dir, base_qs=_sort_base_qs) }} {{ sort_header('spend', 'Spend', _sort, _dir, base_qs=_sort_base_qs) }} {{ sort_header('bytes', 'Bytes', _sort, _dir, align="right", base_qs=_sort_base_qs) }} {{ sort_header('slot_time', 'Slot Time (hrs)', _sort, _dir, align="right", base_qs=_sort_base_qs) }} {{ sort_header('issues', 'Issues', _sort, _dir, align="right", base_qs=_sort_base_qs) }} {{ sort_header('suggestions', 'Suggestions', _sort, _dir, align="right", base_qs=_sort_base_qs) }} {{ sort_header('workload', 'Workload', _sort, _dir, base_qs=_sort_base_qs) }} {{ sort_header('source', 'Source', _sort, _dir, base_qs=_sort_base_qs) }} {{ sort_header('run_at', 'Run At', _sort, _dir, align="right", base_qs=_sort_base_qs) }} {% for j in table_jobs %} {# Each row links to the best /opportunities/{id} for that job when one exists (highest-severity issue, falling back to any improvement that lists the job - see ``opportunity_by_job`` in findings.py). Clean rows open the representative job. #} {% set _row_href = ('/opportunities/' ~ j.opportunity_id) if j.opportunity_id else (('/jobs/' ~ j.job_id) if j.job_id else ('/cost-analysis?search=' ~ ((j.destination_table or j.destination_short or '') | urlencode))) %} {% endfor %}
{{ j.destination_dataset }}
{{ j.destination_object }} {% if j.statement_type %}{{ j.statement_type }}{% endif %} {% if j.execution_count and j.execution_count > 1 %}{% if j.statement_type %} · {% endif %}ran {{ j.execution_count }} times{% endif %}
{{ j.cost_usd | format_usd }} {{ "%.1f" | format(j.cost_share_pct) }}%
{{ j.bytes_processed | format_bytes }} {{ "%.1f" | format((j.slot_time_ms or 0) / 3600000) }} {% if j.issue_count > 0 %} {{ j.issue_count }} {% else %} 0 {% endif %} {% if j.suggestion_count > 0 %} {{ j.suggestion_count }} {% else %} 0 {% endif %} {% from "components/_signal_chip.html" import signal_chip %} {% if j.workload_kind == "build" %} {{ signal_chip("Build", color="brand", title="This logical job materialises data (CTAS, MERGE, INSERT, UPDATE, DELETE, TRUNCATE).") }} {% elif j.workload_kind == "consumption" %} {{ signal_chip("Consumption", color="teal", title="This logical job reads data (SELECT).") }} {% else %} {{ signal_chip("Query", color="slate", title="Workload couldn't be determined from this job's statement type - typically a CALL / scripting / no-DML statement.") }} {% endif %} {# Plain text indicator - same green colour for "dbt" so it still reads as positive context, but without the chip background that competed visually with the Issues / Suggestions count pills on the same row. #} {% if j.is_dbt_originated %} dbt {% else %} other {% endif %} {% if j.creation_time %} {{ j.creation_time.strftime("%Y-%m-%d %H:%M") }} UTC {% else %} - {% endif %}
{# Cost-driver rows group by destination_table / query_hash. #} {% with pagination_item_noun = "cost drivers" %} {% include "components/_pagination.html" %} {% endwith %} {% else %}

No cost drivers match your filters.

{% endif %}