You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@superset.apache.org by gi...@git.apache.org on 2017/09/15 05:17:22 UTC

[GitHub] mistercrunch commented on issue #1996: Custom SQL queries with filters

mistercrunch commented on issue #1996: Custom SQL queries with filters
URL: https://github.com/apache/incubator-superset/issues/1996#issuecomment-329683837
 
 
   Well so the tables defined with SQL, or "Superset Views" if we can call them that, do support templating, and from the template it's possible to read the `form_data`. It's not super well documented but you can certainly experiment with it.
   
   Here's what we squeeze in as template args:
   https://github.com/apache/incubator-superset/blob/master/superset/connectors/sqla/models.py#L370
   
   We did use that to make sure partition pruning was occurring in complex use cases, specifically on the date which was the partition column.
   
   You can imagine a table defined as SQL like
   ```
   SELECT  * FROM tbl
   WHERE 
       ds >= '{{ from_dttm.isoformat() }}' AND
       ds < '{{ to_dttm.isoformat() }}' 
   ```
   It's also possible to do conditional logic and much more in Jinja (templating language) so you could do something like this (this is not tested at all, would have to be teaked...)
   ```
   {% set country = form_data.get('filters')[0].get('val')[0] %}
   SELECT  * FROM tbl
   WHERE 
       0=0
   {% if country %}
       AND country = '{{ country }}'
   {% endif %}
   ```
 
----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services