Superset使用教程

一、简介

Superset在大规模分布式环境可伸缩使用,也可在容器中使用。可兼容多种web服务器 (Gunicorn, Nginx, Apache)、多种元数据引擎(MySQL, Postgres, MariaDB, …)、多种消息队列(Redis, RabbitMQ, SQS, …)、缓存层(Memcached, Redis, …)等。可被成百上千用户并发使用。Airbnb生产环境在K8s中使用了Superset,每日有600+活跃用户查看100k的图表。

Superset的作用:

  • 对应有组目前的开发流程帮助有限
    前端 1人兼职
    后台 2人 -> 1人兼职
    宏 1人 -> 模型组
  • 直接给业务人员使用,提供交互式查询及图表分析
  • 供其他基于数仓的系统集成

Superset的局限性:

  • 不支持级联查询的图表
  • 需要二次开发
  • 文档较少

二、数据源Database

凡是有SqlAlchemy支持的数据源,superset都支持,包括下图:
superset支持数据库

  • Kylin:是一个开源的分布式分析引擎,提供Hadoop/Spark之上的SQL查询接口及多维分析(OLAP)能力以支持超大规模数据,最初由eBay Inc. 开发并贡献至开源社区。它能在亚秒内查询巨大的Hive表。
  • Druid:是一个用于大数据实时查询和分析的高容错、高性能开源分布式系统,旨在快速处理大规模的数据,并能够实现快速查询和分析
  • ClickHouse:是一个开源的面向联机分析处理(OLAP, On-Line Analytical Processing) 的列式存储数据库管理系统

创建数据源

  1. Source -> Databases
  2. 点击加号(+)新增数据源
  3. 输入Sqlalchemy Uri
  4. 可以指定:
  • chart的超时时间
  • 是否在SQL Lab中暴露
  • 是否允许同步查询,默认选择,适合在web请求时间内(约小于1分钟)完成的查询
  • 是否允许异常查询,需要配置Celery worker
  • 是否允许csv上传,还需要在Extra中指定允许的schema
  • 是否允许在SQL Lab中执行CREATE TABLE AS
  • 是否允许在SQL Lab中执行非select的DML语句(UPDATE, DELETE, CREATE, …)
  • 如果允许在SQL Lab中执行CREATE TABLE AS,强制让table都建立在哪个schema下
  • 是否模拟登录用户,针对Presto和Hive
  • 是否允许SQL Lab列出该数据库的所有schema,对于有大量table和view的数仓会很耗时
  • 更多的数据库连接参数在Extra中配置,如schema

例子
本地postgresql数据库中,有一名为postgres的数据库,用户名postgres,密码postgres,现在要连接其中pd_data_investor_hx的schema。
则Sqlalchemy Uri为postgresql://postgres:postgres@localhost/postgres。把选项全部勾选。且extra为

{
    "metadata_params": {"schema":"pd_data_investor_hx"},
    "engine_params": {},
    "metadata_cache_timeout": {},
    "schemas_allowed_for_csv_upload": []
}

三、表Table

  1. Sources -> Tables
  2. 点击加号(+)新增数据表
  3. Database选择之前创建好的数据源,Table Name必须是数据源中对应真实的表名,表中必须包含一个Date或者Timestamp类型的字段【?】
  4. 成功添加后,会提示"As part of this two phase configuration process, you should now click the edit button by the new table to configure it." 即更多配置要在添加完成后,通过Edit进行修改。

Edit的Detail选项卡:

  • Sql:This fields acts a Superset view, meaning that Superset will run a query against this string as a subquery,将类似view一样替代table,即作为from子句。
  • Enable Filter Select:Whether to populate the filter’s dropdown in the explore view’s filter section with a list of distinct values fetched from the backend on the fly
  • Fetch Values Predicate:Predicate applied when fetching distinct value to populate the filter control component. Supports jinja template syntax. Applies only when Enable Filter Select is on.
  • 描述
  • Owner
  • Main Datetime Column,导入Table时会自动默认填入一个Date或者Timestamp类型的字段
  • Default Endpoint:Redirects to this endpoint when clicking on the table from the table list
  • Offset:Timezone offset (in hours) for this datasource,时区偏移,默认0是UTC,UTC与格林尼治平均时(GMT, Greenwich Mean Time)一样,都与英国伦敦的本地时相同
  • Cache Timeout:表的缓存超时时间,0表示从不缓存,如果不特别设置则默认与数据库的超时时间一样
  • SQL Lab View:Whether the table was generated by the ‘Visualize’ flow in SQL Lab
  • Template parameters:A set of parameters that become available in the query using Jinja templating syntax

Edit的List Columns选项卡:
列出表的各列信息,包括别名、类型、Groupable、Filterable和Is temporal(据观察,char类型的字段会自动勾选Groupable和Filterable,Date或者Timestamp类型的字段会自动勾选Is temporal,这对后续配置Chart有影响),可以对列进行增删改。

Edit的List Metrics选项卡:
列出表的快捷度量,如名为count的快捷度量是对该表进行COUNT(*)查询,据观察,number类型的字段会自动有sum和avg,如sum__min_order_vol的快捷度量是进行SUM(min_order_vol)查询,求min_order_vol字段的总和。另外,还有一些不明选项:

  • D3 Format:d3 formatting string as defined here. For instance, this default formatting applies in the Table visualization and allow for different metric to use different formats
  • Is Restricted:Whether the access to this metric is restricted to certain roles. Only roles with the permission ‘metric access on XXX (the name of this metric)’ are allowed to access this metric

例子
导入表pd_data_investor_hx.acct_false_declaim_discriminate
在这里插入图片描述

四、Chart

  1. Charts
  2. 点击加号(+)新增数据图
  3. 选择数据源,选择可视化类型

可视化类型

常用包括:

  • 表格
    • Table View:A basic html table that is sortable and searchable,组成项time、group by、not group by
    • Time Table View:A data table with rich time-series related columns,组成项time,query(必填)
    • Pivot Table:A pivot table view, define your rows, columns and metrics,组成项time,query(必填),透视表是二维矩阵
  • 线条
    • Time Series - Line Chart:A rich line chart component with tons of options,如Growth Rate
    • Time Series - Multiple Line Chart:Pile on multiple line charts,如Multi Line
    • Dual Axis Line Chart:A rich line chart with dual axis,如Average and Sum Trends
  • 直方图
    • Distribution - Bar Chart:A good old bar chart,如Genders by State
    • Time Series - Bar Chart :A bar chart where the x axis is time
    • Histogram
  • 堆积图
    • Time Series - Stacked:A rich stack area chart
  • 网络图
    • Force-directed Graph:An animated directed force layout graph visualization,如Energy Force Layout
  • 饼图
    • Pie Chart:Annoy visualization snobs with this controversial pie chart
  • 控件
    • Filter Box:A multi filter, multi-choice filter box to make dashboards interactive

注意,在一个Chart中对数据源表做的任何修改,都是全局生效的:

The data source configuration exposed here affects all the charts using this datasource. Be mindful that changing settings here may affect other charts in undesirable ways.

可生成外链,分享给别人;也可通过iFrame嵌入到别的网页中。

五、Dashborad

  1. Dashborads
  2. 点击加号(+)新增仪表盘
  3. 选择Edit Dashboard,拖拽Chart的位置进行组装,设置css格式和刷新参数等

可生成外链,分享给别人。

六、SQL Lab

  • SQL Editor:灵活查询IDE,支持查询兼容SQLAlchemy的所有数据库,长时间的大规模数据异步查询需要配置。支持参数化查询,查询语句保存和分享。
  • Query Search:所有查询操作的记录。
  • Saved Queries:保存的查询语句。

七、其他

  • 用Flask-AppBuilder实现细粒度的控制用户权限
  • 用户密码可从外部接入
  • 支持Druid接入
  • 支持CORS设置
  • 使用StatsD记录日志
  • 在K8s中安装superset
  • 支持OAuth2认证

八、参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值