{# "Top Cost Drivers with Issues and Suggestions Found" - 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. Filters to jobs with at least one issue or one suggestion finding so any flagged row shows up. #} {% from "components/_sort_header.html" import sort_header %} {% set _sort = sort_by | default('spend') %} {% set _dir = sort_dir | default('desc') %}
{% from "components/_section_title.html" import section_title %}
{{ section_title( "Top Cost Drivers with Issues and Suggestions Found", description="Logical jobs with at least one detection finding, aggregated across all executions (by destination table for builds, by normalized query hash for consumption) and ranked by total cost. Select a row to open its highest-impact opportunity; click any column header to sort.", aside=(pagination.total_items ~ " flagged of " ~ "{:,}".format(totals.total_jobs) ~ " scanned") ) }}
{% if table_jobs %}
{# Dataset #} {# Object #} {# Spend #} {# Bytes #} {# Slot Time #} {# Issues #} {# Suggestions #} {# Workload #} {# Source #} {# Run At #} {{ sort_header('dataset', 'Dataset', _sort, _dir) }} {{ sort_header('object', 'Object', _sort, _dir) }} {{ sort_header('spend', 'Spend', _sort, _dir) }} {{ sort_header('bytes', 'Bytes', _sort, _dir, align="right") }} {{ sort_header('slot_time', 'Slot Time (hrs)', _sort, _dir, align="right") }} {{ sort_header('issues', 'Issues', _sort, _dir, align="right") }} {{ sort_header('suggestions', 'Suggestions', _sort, _dir, align="right") }} {{ sort_header('workload', 'Workload', _sort, _dir) }} {{ sort_header('source', 'Source', _sort, _dir) }} {{ sort_header('run_at', 'Run At', _sort, _dir, align="right") }} {% 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). When no opportunity ID is available we still fall back to the listing filtered by the destination name so the click always lands somewhere useful. #} {% set _row_href = ('/opportunities/' ~ j.opportunity_id) if j.opportunity_id else ('/opportunities?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 %}
{# Dashboard's cost-drivers table groups by destination_table / query_hash - the same key the "Flagged Jobs" stat card counts. #} {% with pagination_item_noun = "flagged jobs" %} {% include "components/_pagination.html" %} {% endwith %} {% else %}

No flagged jobs in the scan window. Widen the lookback or relax the rule overrides.

{% endif %}