Skip to main content

Files of tags

Files that are mostly Jinja — macros and tag scaffolding — with little or no SQL between the tags.

Each pair below is a real, passing case from dfmt's test corpus (suites/dfmt-jinja/cases/files-of-tags/): the template as written, then the same template after dfmt — every Jinja tag reproduced exactly, the SQL laid out around it. 7 examples.

A file of only sets and a comment​

Before

{# which limits apply #}
{% set a = 1 %}


{% set b = 2 %}

After

{# which limits apply #}
{% set a = 1 %}

{% set b = 2 %}

A licence header above multiline sets​

Before

{#
Copyright (c) 2021-present Example Ltd. All rights reserved.
This program is licensed to you under the Community License Version 1.0.
#}

{%- set snowplow_query_tag = 'snowplow_dbt' -%}

{% set min_last_success = '2020-01-01' -%}


{% set run_limits_query = ['events since ' ~ min_last_success,
'query tag ' ~ snowplow_query_tag] -%}

{% set models_in_run = ['snowplow_mobile_base_events_this_run', 'snowplow_mobile_screen_views_this_run', 'snowplow_mobile_sessions_this_run'] %}

After

{#
Copyright (c) 2021-present Example Ltd. All rights reserved.
This program is licensed to you under the Community License Version 1.0.
#}

{%- set snowplow_query_tag = 'snowplow_dbt' -%}

{% set min_last_success = '2020-01-01' -%}

{% set run_limits_query = ['events since ' ~ min_last_success, 'query tag ' ~ snowplow_query_tag] -%}

{%
set models_in_run = [
'snowplow_mobile_base_events_this_run',
'snowplow_mobile_screen_views_this_run',
'snowplow_mobile_sessions_this_run'
]
%}

A materialization block keeps its tags​

Left unchanged — already in dfmt's shape:

{% materialization test, default %}
{{ return(elementary.materialization_test_default()) }}
{% endmaterialization %}

A raw block keeps its closing tag​

Left unchanged — already in dfmt's shape:

{% raw %}
select 1 as a
{% endraw %}

A snapshot block is a statement the evaluator knows​

Left unchanged — already in dfmt's shape:

{% snapshot orders_snapshot %}
select 1 as a
{% endsnapshot %}

An autoescape block keeps its tags​

Left unchanged — already in dfmt's shape:

{% autoescape true %}
select 1 as a
{% endautoescape %}

An untaken guard holding the whole query ships verbatim​

Before

{{config(enabled = true)}}

{% if false -%}

select 1 as a

{% elif false -%}

select 2 as b

{%- endif %}

After

{{ config(enabled = true) }}

{% if false -%}
select 1 as a
{% elif false -%}
select 2 as b
{%- endif %}