You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2019/09/05 18:40:09 UTC

[GitHub] [incubator-superset] cachafla opened a new issue #8183: How to pass time filters to SQL Lab queries

cachafla opened a new issue #8183: How to pass time filters to SQL Lab queries
URL: https://github.com/apache/incubator-superset/issues/8183
 
 
   Is there a way to pass `[from, to]` date filters to an SQL query?
   
   I've been looking everywhere in documentation and source code and haven't found a solution to passing date filters to custom SQL queries. I'm working on some advanced multi-join aggregations from existing tables/views.
   
   As a very simple example of the issue I'm trying solve, consider this SQL query:
   
   ```sql
   SELECT COUNT(*)
   FROM sessions
   WHERE timestamp <= {{ something }} AND timestamp >= {{ something_else }}
   ```
   
   I'd like to be able to access the date filters that are propagated through a `Filter Box` widget. in a dashboard. I've found that the values of these filters are available as these variables (thanks to https://superset.incubator.apache.org/faq.html#how-to-add-dynamic-filters-to-a-dashboard): https://github.com/apache/incubator-superset/blob/40776bd547166b6975574e815ec02add04781248/superset/assets/src/visualizations/FilterBox/FilterBox.jsx#L38-L44
   
   With that in mind, I could make use of `__time_range` inside my SQL filter via `filter_values('__time_range')`, but `__time_range` is always giving me the literal time range selected, not a parsed `[from, to]` couple of date objects. I get values such as:
   
   - 'Last quarter'
   - '2019-09-02T00:00:00 : 2019-09-03T00:00:00'
   
   These variations are very difficult to deal with inside an SQL query.
   
   I'd like to know if this is all I get or if there's an undocumented solution to my problem I don't know about. In its simplest from, I'd like to have filters available in the SQL as template params so that I can do things like:
   
   ```sql
   timestamp >= {{ from }} AND timestamp <= {{ to }}
   ```
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org