{# "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. #} {% set _sort = sort_by | default('spend') %} {% set _dir = sort_dir | default('desc') %} {# Macro: render a sortable column header. Toggling the active column flips direction; switching columns resets to desc. Always returns page=1 so users don't end up past the new tail. #} {% macro _sort_th(col, label, align="left", extra="") %} {% set is_active = (_sort == col) %} {% set next_dir = 'asc' if (is_active and _dir == 'desc') else 'desc' %} {% set arrow = '↓' if (is_active and _dir == 'desc') else ('↑' if is_active else '') %} {{ label }} {% if arrow %}{{ arrow }}{% endif %} {% endmacro %}

Top Cost Drivers with Issues and Suggestions Found

Cached query executions with at least one detection finding, ranked by cost. Select a row to open its highest-impact opportunity; click any column header to sort.

{{ 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_th('dataset', 'Dataset', 'left') }} {{ _sort_th('object', 'Object', 'left') }} {{ _sort_th('spend', 'Spend', 'left') }} {{ _sort_th('bytes', 'Bytes', 'right') }} {{ _sort_th('slot_time', 'Slot Time (hrs)', 'right') }} {{ _sort_th('issues', 'Issues', 'right') }} {{ _sort_th('suggestions', 'Suggestions', 'right') }} {{ _sort_th('workload', 'Workload', 'left') }} {{ _sort_th('source', 'Source', 'left') }} {{ _sort_th('run_at', 'Run At', '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 %}
{{ 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 %} {# Mirrors the workload chip on /opportunities — ui-signal-chip + colour-coded ui-legend-dot — so visual grammar is consistent across both tables. #} {% if j.workload_kind == "build" %} Build {% elif j.workload_kind == "consumption" %} Consumption {% else %} Query {% 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 %}
{% include "dashboard/_pagination.html" %} {% else %}

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

{% endif %}