dimension: dimVar {
label: "VarDimension"
view_label: "_dynamic Dimensions"
label_from_parameter: pardimVar
sql:
{% if pardimVar._parameter_value == 'billingkind' %} ${dim_billingType.billingKindDescEng}
{% elsif pardimVar._parameter_value == 'brandtype' %} ${d_hersteller.markenart}
{% elsif pardimVar._parameter_value == 'category' %} ${d_materialklasse.category}
{% endif %}
;;
description: "use this dimension in combination with the DimensionVar Filter in the __requieredFilter!"
}
In the SQL query, which Looker generates, three joins are always generated for all three suggestions, even though I only use one join. How can I ensure that only the join that is actually used is generated?
This is a very simplified example of my application. In my actual code, I have 17 joins, which consume a huge amount of resources and make my model very slow.
Hi @sam8
thank you for response. I think I don’t undersand. do you have a Expample for your suggestion?
In my model i have a factTable “facts” and 3 Dimensions like “dimBillingKind”, “dimHersteller”, “dimCategory”. (StarSchema)
So If i want to select a field from dimension dimCategory the expected sql is:
Select
sum(value), billingKindDescEng from facts join billingType on a.billingid = b.billingId
but the sql which is generated is:
Select
sum(value), billingKindDescEng from facts a
join billingType b on a.billingid = b.billingId
join d_hersteller c on a.herstellerId = c.herstellerId
join d_markenart d on a. markenartId = d.markenart_id
That makes sense. Since the d_hersteller and d_markenart tables are referenced in the dimension SQL, Looker will join in those tables every time.
I haven’t tested this, but I think you could work around this by referencing these values as Liquid objects rather than using Looker’s SQL reference. My theory is that the Liquid will only resolve for the case that is true, and so Looker will only generate the joins needed for the field that is selected. The LookML would look like this:
(please replace the parentheses with curly brackets to match the liquid variable reference syntax - Community won’t let me use that syntax presumably for safety reasons)
hm, that makes me think that neither of the “if” conditions are being met.
First, it would be a good idea to add some “else” statement to the “if”.
Then, I recommend checking what the parameter value is actually outputting. Try making a field with only (( pardimVar._parameter_value )) in the “sql” parameter. Then we can use that to test the values of pardimVar.