ksaagariconic commented on issue #1996: Custom SQL queries with filters
URL: 
https://github.com/apache/incubator-superset/issues/1996#issuecomment-409760921
 
 
   Thanks for the instant response @villebro - we had a lot of queries 
structured with custom filter predicates like this,
   
   ```
   SELECT country, sum(population) as population 
   FROM 
   tbl
   WHERE 0=0
   {% if  form_data.get('filters')[0].get('val')[0] %}
       AND continent = '{{  form_data.get('filters')[0].get('val')[0] }}'
   {% endif %}
   GROUP BY 1
   ```
   
   What's happening now is that this predicate is completely getting ignored. 
It shows up in the frontend as "filter" but doesn't show up in the queryobj or 
eventual query.
   
   We tried this alternative, to use the new **filter context**, but it says 
filter is not defined.
   
   ```
   SELECT country, sum(population) as population 
   FROM 
   tbl
   WHERE 0=0
   {% if  filter[0].get('val')[0] %}
       AND continent = '{{  filter[0].get('val')[0] }}'
   {% endif %}
   GROUP BY 1
   ```
   
   What however works is if we have a column by the same name as the filter, 
e.g. a filter called country with the same variable name works dynamically - 
but as a predicate on the super query, and not on the actual query in itself.
   
   Does this make it clearer? Thanks for offering to help

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to