【问题标题】:Is there a way to create bind variables in Apache Superset's SQL Lab?有没有办法在 Apache Superset 的 SQL 实验室中创建绑定变量?
【发布时间】:2021-08-22 22:58:37
【问题描述】:

我创建了一个数据库,我想在其中跟踪我的一些财务数据,并在该数据库中创建了一个函数,该函数计算我的投资组合自第一条记录以来的价值。我想在 Apache Superset 中创建一个仪表板,以可视化我的投资组合的价值。

函数如下所示,返回数据如下:

select * from all_value_by_date_on_account(null, current_date, '<some currency>', <account-id-or-null>)
date Value Money transacted Free money Performance
2020-03-17 98820 100000 755.6 -0.004244
2020-03-31 98820 100000 755.6 -0.004244
2020-04-01 187948.397923360635 225000 32052.7708519 -0.02221702766550828889
2020-05-19 198110.048622676626 225000 30990.36516322 0.01822406127065167111

我的问题是,有没有办法将下拉菜单的值绑定到这个函数中?我想创建一个下拉列表,在其中列出所有帐户,如果我选择其中一个帐户,Superset 应该将其 id 绑定到 &lt;account-id-or-null&gt; 参数中。

有没有简单的方法可以做到这一点?

谢谢,

【问题讨论】:

    标签: apache-superset superset


    【解决方案1】:

    Apache Superset 支持 SQL 模板来实现这一点

    例如,您可以使用{{ filter_values() }}以列表形式检索特定过滤器的值

    SELECT *
    FROM your_table
    WHERE 
         account_id in ({{ "'" + "','".join(filter_values('account_id')) + "'" }})
    

    阅读文档了解更多详情https://superset.apache.org/docs/installation/sql-templating#available-macros

    【讨论】:

      猜你喜欢
      • 2018-10-22
      • 1970-01-01
      • 1970-01-01
      • 2017-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-30
      • 2020-03-16
      相关资源
      最近更新 更多