View the original community article here
Last tested: Mar 4, 2020
Yes, the LookML references will always evaluate, even if the SQL containing the reference doesn't end up in the final query due to an unmet liquid condition. Looker checks for all dependencies before applying liquid conditions, which causes LookML references to be evaluated even when they don't need to be.
A common example is when in_query
is used in a liquid condition. For example:
{% if products._in_query %}
${products.products_sku_revenue}
{% else %}
SUM(${order_revenue})
{% endif %}
In this situation, product._in_query
will always evaluate to true. This is because the ${products.products_sku_revenue}
LookML reference is evaluated before the liquid condition, and the LookML reference will automatically bring the products
join into the query.
Some other examples:
Example 1 (unnecessarily pulls in my required_fields):
measure: simple_avg {
type: average
sql: ${my_field};;
}
measure: running_total_example {
type: number
sql: avg(${simple_avg}) OVER (order by ${created_week} ) ;;
required_fields: [created_week]
}
measure: complex_measure {
type: number
sql:
{% if other_field._in_query %}
${running_total_example}
{% else %}
${simple_avg}
{% endif %}
;;
}
Example 2 (Unnecessarily introduces my join of other_view2 ):
measure: mymeasure {
type: number
sql:
{% if field._in_query %}
${field} / ${other_view1.field}
{% else %}
${field} / ${other_view2.field}
{% endif %}
;;
}
Example 3 (Runs all PDTs)
view: my_amazing_view {
sql:
SELECT * FROM
{% if created_date.in_query %}
${daily_summary.SQL_TABLE_NAME
{% elsif created_week.in_query %}
${weekly_summary.SQL_TABLE_NAME}
{% else %}
${annual_summary.SQL_TABLE_NAME}
{% endif %}
;;
}