{# Audit's object-overview detail page. Lists EVERY active issue + EVERY available SQL-rewrite suggestion for the requested opportunity's destination_table — not just one rule's findings. The cohort view at /jobs/{table} stays as the deep-dive (cost chart, Query versions). PR / dry-run / shadow surfaces are deliberately absent — audit is read-only and never generates solutions. #} {% extends "layout.html" %} {% block content %}
Opportunities {% if row.dbt_model_name %}{{ row.dbt_model_name }}{% else %}{{ row.affected_object or row.affected_table }}{% endif %}
{# Title includes the dataset prefix so readers can locate the object without scanning a subtitle. ``affected_table`` is the full ``project.dataset.table`` BigQuery path; we split off the dataset segment (index 1) and pair it with either the dbt model name or the bare table name. The project context lives in the global header strip, so we don't repeat it here. #} {% set _path_parts = (row.affected_table or '').split('.') %} {% set _dataset = _path_parts[1] if _path_parts | length >= 2 else '' %} {% set _table = _path_parts[2] if _path_parts | length >= 3 else (row.affected_table or '') %}

{% if _dataset %}{{ _dataset }}.{% endif %}{{ row.dbt_model_name or _table }}

{# Title-row chips carry only context that isn't restated below (dbt origin, author for filter-pivot). Issue + suggestion counts removed — they live in the stat strip and in the section headings further down, so pills at the top were triple-presenting the same numbers. #}
{% if row.dbt_model_name %} dbt {% endif %} {% if row.author_email %} {{ row.author_email }} {% endif %}
{# Stat strip — three numbers describing the representative job: Cost / Bytes Processed / Slot Time. The previous fourth card ("Issues found") listed issue rule names as plain text — a wall of repeated information since the section directly below this lists them in cards. Dropped to three so each remaining card has more visual weight. #}

Cost (this execution)

{{ row.query_cost_value | format_usd }}

Bytes Processed

{% if job and job.total_bytes_processed is not none %}

{{ job.total_bytes_processed | format_bytes }}

{% if job.total_bytes_billed is not none %}

billed: {{ job.total_bytes_billed | format_bytes }}

{% endif %} {% else %}

{% endif %}

Slot Time (hours)

{% if job and job.total_slot_ms is not none %}

{{ "%.1f" | format((job.total_slot_ms or 0) / 3600000) }}

{% if job.duration_ms is not none %}

duration: {{ job.duration_ms | format_duration }}

{% endif %} {% else %}

{% endif %}
{# Cost trend collapsible. "Cost trend" (not "for this table") because the same partial is used for consumption queries that have no destination table. The full job-history cohort link is passed into the partial as ``chart_history_href`` so it renders inside the collapsible's expanded body. #} {% if chart_points_payload %} {% set chart_title = "Cost trend" %} {% set chart_subtitle = "One point per day across the scan window. Days without executions are skipped." %} {% set chart_collapsible = true %} {% set chart_history_href = "/jobs/" ~ row.affected_table %} {% include "jobs/_cost_chart.html" %} {% endif %} {# Issues found — one bordered card per issue rule that fired on this table. Each card has a 2-column Why-this-fired / Recommended- fix split, so readers can pair the cause with the fix per rule. When a rule has no template SQL diff, Recommended-fix points to the Available improvements section below rather than repeating the Why-this-fired text verbatim. When zero issues fired (suggestion-only object), this section is hidden. #} {% if issue_cards %}

Issues found

{% for issue in issue_cards %}
{# Red issue pill — matches the red "issue count" pill in the dashboard's Top Cost Drivers table so the visual grammar is consistent across pages. #} {{ issue.row.opportunity_type | replace('_', ' ') }}
{# Each column gets its own sub-card so "Why this fired" and "Recommended fix" are visually distinct blocks. Background is one full step darker than the outer card (slate-100 / dark:slate-800) so the separation reads clearly. #}

Why this fired

{{ issue.row.explanation }}

{% if issue.rule_meta and issue.rule_meta.description %}

{{ issue.rule_meta.description }}

{% endif %}

Recommended fix

{% if issue.template_result %}

{{ issue.template_result.explanation }}

{% if issue.diff_lines %}

SQL diff in Available improvements below.

{% endif %} {% elif improvements %}

See Available improvements below for the SQL-rewrite catalogue.

{% else %}

This issue type doesn't have a single-query SQL rewrite. The fix is at the workload-scheduling or schema layer.

{% endif %}
{% endfor %}
{% endif %} {# Spec 148 — Recommended physical layout. Read-only suggestion of partition + cluster keys based on how the table is queried. The partial gates on ``layout_recommendation`` so a None recommendation produces zero markup. #} {% include "opportunities/_layout_recommendation.html" %} {# Available improvements — every SQL-rewrite suggestion that fired on any opportunity for this table, deduped by rule_type. Each is a deterministic rewrite (no LLM) and renders inline as its own green/red diff. #} {% if improvements %}

Available improvements

{% for imp in improvements %}
{{ imp.display_name }} {% if imp.template_id %} deterministic rewrite {% endif %} {% if imp.occurrences and imp.occurrences > 1 %} ×{{ imp.occurrences }} {% endif %}
{% if imp.explanation %}

{{ imp.explanation }}

{% endif %} {% if imp.diff_lines or imp.before_content %}
{% if imp.after_content %} {% endif %}
{% if imp.diff_lines %} {% set diff_lines = imp.diff_lines %} {% set file_path = imp.template_id %} {% include "components/code_diff.html" %} {% else %}

No diff available — template did not produce a change.

{% endif %}
{% if imp.after_content %} {% endif %}
{% endif %} {% if imp.rollback %}
Rollback instructions

{{ imp.rollback }}

{% endif %}
{% endfor %}
{% endif %} {# Query fallback — when no SQL-rewrite suggestions fired on this opportunity, the user still needs to see the underlying query so they can manually inspect what's running. Suggestion cards already include an "Original SQL" tab; this block is the fallback path when ``improvements`` is empty. Renders only when we have a representative job with a query body. #} {% if not improvements and job and job.query %}

Query

The latest execution of this query. No deterministic SQL-rewrite suggestion is available for this opportunity — the fix is at the workload-scheduling or schema layer.

{% for line in job.query.split('\n') %}{{ loop.index }}{{ line }}
{% endfor %}
{% endif %} {# Evidence + BigQuery query lookup — two side-by-side cards on >=lg, stacked on smaller screens. Each card collapses independently. The right-hand card renders the ``INFORMATION_SCHEMA.JOBS_BY_PROJECT`` SELECT pre-filtered by job_id so the user can paste it into the BigQuery console and inspect the row themselves. Evidence + lookup come from the representative opportunity (highest-priority for this table). #} {% if visible_evidence or job_lookup_sql %}
{% if visible_evidence %}

Evidence

{% for key, value in visible_evidence.items() %}
{{ key }}
{% if value is mapping or (value is iterable and value is not string) %} {{ value | tojson }} {% else %} {{ value }} {% endif %}
{% endfor %}
{% endif %} {% if job_lookup_sql %}

BigQuery query

Paste this into the BigQuery console to inspect the underlying job row.

{{ job_lookup_sql }}
{% endif %}
{% endif %}
{# Generic tab toggler — picks up every ``[data-tab]`` / ``[data-tab-pane]`` pair inside an ancestor with ``[data-active-tab]``. Same script as the cohort page so suggestion cards' Diff / Original SQL tabs work without coupling to the class name. #} {% endblock %}