{% if reasoning.current_state_phrase %}
Current State: {{ reasoning.current_state_phrase }}
{% endif %}
{% if reasoning.observation %}
Observation: {{ reasoning.observation }}
{% endif %}
{% if reasoning.recommendation %}
Recommendation: {{ reasoning.recommendation }}
{% endif %}
{% if reasoning.expected_benefit %}
Expected Benefit: {{ reasoning.expected_benefit }}
{% endif %}
{% if caveats %}
Caveats: {{ caveats | join(" ") }}
{% endif %}
{% endif %}
{% endmacro %}
{% if audit_mv_candidates or bq_mv_recommendations %}
{% from "components/_section_title.html" import section_title %}
{{ section_title(
"Materialization",
description="Recommended materialization strategy for this table's queries. Strategies: ephemeral (inline as CTE), incremental, table, materialized view. Each card explains the evidence behind the recommendation.",
aside=((audit_mv_candidates | length + bq_mv_recommendations | length) ~ (' candidate' if (audit_mv_candidates | length + bq_mv_recommendations | length) == 1 else ' candidates'))
) }}
{# ─── Audit-detected candidates ────────────────────────────── #}
{% for cand in audit_mv_candidates %}
{% set _strategy = cand.recommended_strategy or "materialized_view" %}
{% if _strategy == "materialized_view" %}
{# MV card. Spec 154 v3.3: just the reasoning block; no SQL panel
and no stat-strip cards. The numbers live in the observation
line; the user looks at this surface to decide whether to
act, not to copy SQL. #}
{{ strategy_pill(_strategy) }}
audit-detected
{{ cand.suggested_mv_name }}
{{ reasoning_block(cand.reasoning, caveats=cand.safety_caveats) }}
{% elif _strategy == "ephemeral" %}
{{ strategy_pill(_strategy) }}
audit-detected
{% if cand.dbt_node_id %}
{{ cand.dbt_node_id }}
{% endif %}
{{ reasoning_block(cand.reasoning, caveats=cand.caveats) }}
{# Downstream-consumer list is distinct content (node names),
not in the observation prose, so it stays. #}
{% if cand.downstream_dbt_node_ids %}
downstream consumers:
{{ cand.downstream_dbt_node_ids | join(", ") }}
{% endif %}
{% elif _strategy == "table" %}
{{ strategy_pill(_strategy) }}
audit-detected
{{ reasoning_block(cand.reasoning, caveats=cand.caveats) }}
{% elif _strategy == "incremental" %}
{{ strategy_pill(_strategy) }}
audit-detected
{% if cand.dbt_node_id %}
{{ cand.dbt_node_id }}
{% endif %}
{{ reasoning_block(cand.reasoning, caveats=cand.caveats) }}
{% else %}
{# Unknown strategy - render a minimal fallback so we never
silently swallow an opportunity. #}
{{ strategy_pill(_strategy) }}
audit-detected
{{ cand | tojson(indent=2) }}
{% endif %}
{% endfor %}
{# ─── BigQuery's MV Recommender pass-through ──────────────── #}
{% for rec in bq_mv_recommendations %}
{{ strategy_pill("materialized_view") }}
BigQuery Recommender
{% if rec.bq_recommendation_state %}
{{ rec.bq_recommendation_state }}
{% endif %}
{{ rec.target_table_full_name or rec.target_resource }}
{% if rec.bq_description %}
{{ rec.bq_description }}
{% endif %}
{% if rec.bq_insights %}
Paired insights
{% for ins in rec.bq_insights %}
-
{{ ins.category }}
{{ ins.description }}
{% endfor %}
{% endif %}
{% if rec.last_refresh_time %}
Last refreshed by Google's Recommender: {{ rec.last_refresh_time }}
{% endif %}
{% endfor %}
{% endif %}