【问题标题】:Superset passing time filter from dashboard to custom query从仪表板到自定义查询的超集传递时间过滤器
【发布时间】:2020-10-04 17:11:28
【问题描述】:

在一个切片中,需要自定义查询来合并来自不同过滤器的 2 个数据集。 每个数据集都有其日期/时间过滤器。 Superset 怎么会知道哪个日期名称用于哪个查询。

下面的自定义查询示例。

1 SELECT "PRE" AS "Stage","Tutorial Flight"."Travel Date" AS "Travel_Date",
2       "Tutorial Flight"."Airline" AS "Airline",
3       sum("Cost") AS "Cost"
4 FROM  "Tutorial Flight"
5 WHERE 
6 "Travel Date" = strftime('%Y-%m-%d %H:%M:%S.000000','{{ from_dttm.isoformat() }}')
7 AND  "Tutorial Flight"."Airline"  in ( {{ "'" + "','".join(filter_values('Airline')) + "'" }} )
8 GROUP BY 
9        "Travel Date", "Airline"
10 UNION
11 SELECT "POST" AS "Stage","Tutorial Flight"."Travel Date" AS "Travel_Date",
12       "Tutorial Flight"."Airline" AS "Airline",
13       sum("Cost") AS "Cost"
14 FROM "Tutorial Flight"
15 WHERE 
16 "Travel Date" = strftime('%Y-%m-%d %H:%M:%S.000000','{{ from_dttm.isoformat() }}')
17 AND  "Tutorial Flight"."Airline"  in ( {{ "'" + "','".join(filter_values('Airline')) + "'" }} )
18 GROUP BY "Travel Date", "Airline"

在这种情况下使用了 3 个过滤器。 日期前的 date_time 发布日期的 date_time 和 适用于这两个查询的航空公司。

我们如何在 from_dttm.isoformat() 中定义以使用表中的正确日期时间,如果 1.来自同一张表的日期过滤器 2. 来自不同表的日期过滤器。

我试过了,但它总是只从一张桌子上使用。 这是来自一次过滤器的 json

{"cache_key": null, "cached_dttm": null, "cache_timeout": 86400, "error": null, "form_data": {"datasource": "18__table", "viz_type": "filter_box", "slice_id": 295, "url_params": {}, "granularity_sqla": "Travel Date", "time_range": "2020-06-15T00:00:00 : 2020-06-15T00:00:00", "filter_configs": [], "date_filter": true, "instant_filtering": true, "show_sqla_time_granularity": false, "show_sqla_time_column": false, "show_druid_time_granularity": false, "show_druid_time_origin": false, "adhoc_filters": [], "where": "", "having": "", "having_filters": [], "filters": []}, "is_cached": false, "query": "", "status": null, "stacktrace": null, "rowcount": 0, "data": {}}

请多多指教。 非常感谢。

【问题讨论】:

    标签: filter dashboard apache-superset superset


    【解决方案1】:

    你可以通过{{from_dttm}}和{{to_dttm}}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-14
      • 2016-09-11
      • 1970-01-01
      • 2018-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-11
      相关资源
      最近更新 更多