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 2020/05/22 16:39:46 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:
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
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [incubator-superset] dharamgajera commented on issue #8183: How to pass time filters to SQL Lab queries
Posted by GitBox <gi...@apache.org>.
dharamgajera commented on issue #8183:
URL: https://github.com/apache/incubator-superset/issues/8183#issuecomment-654101255
> > This is what I do, and it works for me. I do make some assumptions (taking the first time range filter if there are multiple, for example).
>
> @rubypollev thanks for sharing this patch (I also need to pass time filters to SQL Lab queries).
>
> Since I have just started with Superset, **could you please tell to which python file I should add your code snippet?** Thanks again :)
You need to add in superset config.py file.
----------------------------------------------------------------
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
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [incubator-superset] aleksarias commented on issue #8183: How to pass time filters to SQL Lab queries
Posted by GitBox <gi...@apache.org>.
aleksarias commented on issue #8183:
URL: https://github.com/apache/incubator-superset/issues/8183#issuecomment-642041516
Is there anyway to access the time related filters (Time Column and Time Grain) via template parameters?
I'm trying to create a view that can aggregate on any Time Grain selected with the chart. However, I'm having a hard time figuring out whether I can gain access to the attribute using a template variable.
----------------------------------------------------------------
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
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [incubator-superset] elaragon commented on issue #8183: How to pass time filters to SQL Lab queries
Posted by GitBox <gi...@apache.org>.
elaragon commented on issue #8183:
URL: https://github.com/apache/incubator-superset/issues/8183#issuecomment-632707828
> This is what I do, and it works for me. I do make some assumptions (taking the first time range filter if there are multiple, for example).
@rubypollev thanks for sharing this patch (I also need to pass time filters to SQL Lab queries).
Since I have just started with Superset, **could you please tell to which python file I should add your code snippet?** Thanks again :)
----------------------------------------------------------------
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
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
[GitHub] [incubator-superset] nytai closed issue #8183: How to pass time filters to SQL Lab queries
Posted by GitBox <gi...@apache.org>.
nytai closed issue #8183:
URL: https://github.com/apache/incubator-superset/issues/8183
----------------------------------------------------------------
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
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org