1、介紹
官網:https://superset.apache.org/index.html
Apache Superset 是一個現代的、面向企業的商業智能web應用程序。
superset是由Airbnb(知名在線短租賃公司)開源的數據分析與可視化平台(曾用名Caravel、Panoramix)
該工具主要特點是可自助分析、自定義儀表盤、分析結果可視化(導出)、用戶/角色權限控制,還集成了一個SQL編輯器,可以進行SQL編輯查詢對結果集進行保存可視化等。
核心功能:
1.快速創建數據可視化互動儀表盤
2.豐富的可視化圖表模板,靈活可擴展
3.細粒度高可擴展性的安全訪問模型,支持主要的認證供應商(數據庫、OpenID、LDAP、OAuth 等)
4.簡潔的語義層,可以控制數據資源在 UI 的展現方式
5.與 Druid(其實它貌似就是為了druid而生的)深度集成,可以快速解析大規模數據集
6.快速的通過配置裝載儀表盤等
支付的RDBMS:
一些圖例
其他參考資料:https://www.zhihu.com/topic/20677618/hot
2、安裝
環境准備:
centos7 python3 mysql npm
安裝步驟:
1、Python3安裝 以及其他依賴
sudo yum upgrade python-setuptools sudo yum install gcc gcc-c++ libffi-devel python-devel python-pip python-wheel openssl-devel libsasl2-devel openldap-devel
2、創建Python virtualenv
pip install virtualenv python3 -m venv venv . venv/bin/activate pip install --upgrade setuptools pip
3、安裝superset
# Install superset pip install apache-superset # Initialize the database superset db upgrade # Create an admin user (you will be prompted to set a username, first and last name before setting a password) $ export FLASK_APP=superset superset fab create-admin # Load some data to play with superset load_examples # Create default roles and permissions superset init # To start a development web server on port 8088, use -p to bind to another port superset run -p 8088 --with-threads --reload --debugger
這里選用的是pip的方式安裝的0.36.0版。 superset -h參數可以指定主機IP。
4、可以通過http://安裝主機IP:8088進行訪問
config.py中的數據庫配置【SQLALCHEMY_DATABASE_URI】默認是SQLlite,這里改為了MySQL。
安裝完成,superset路徑為venv/lib/python3.7/site-packages/superset。
參考:
https://github.com/apache/incubator-superset
http://superset.apache.org/installation.html#python-virtualenv
3、遇到的問題
1、Python3安裝缺失ssl
2、fabmanager命令不存在
pip安裝flask等依賴。安裝此文件requirements.txt中依賴即可。
3、Unexpected error invalid syntax (hive.py, line 280)
解決:
pyhive 安裝不正確
sudo yum install cyrus-sasl-plain cyrus-sasl-devel cyrus-sasl-gssapi -y sudo pip install bit_array sudo pip3 install thrift sudo pip3 install thrift_sasl sudo pip3 install sasl sudo pip3 install impyla sudo pip3 install pyhive[hive]
4、pyhive no mechanism available: No worthy mechs found
解決:
sudo yum install cyrus-sasl-plain cyrus-sasl-devel cyrus-sasl-gssapi -y
與第3點相同處理,這邊是因為pyhive不是最新版本導致,升級到最新問題解決。
5、testcnn接口報錯
superset/views/core.py 1366行報錯
修改:
db_name = request.json.get("name") --》db_name = request.json["name"] uri = request.json.get("uri") --》uri = request.json["uri"]
6、hive連接配置
hive://0.0.0.0:10000/default?auth=NONE
需要勾選該項"模擬登錄用戶",公司的用戶都是分配的用戶,勾選該項可以以hivesever啟動程序所屬角色運行SQL。
還需要配置hive-site.xml,配置如下:
<property> <name>hive.server2.authentication</name> <value>NONE</value> <description> Expects one of [nosasl, none, ldap, kerberos, pam, custom]. Client authentication types. NONE: no authentication check LDAP: LDAP/AD based authentication KERBEROS: Kerberos/GSSAPI authentication CUSTOM: Custom authentication provider (Use with property hive.server2.custom.authentication.class) PAM: Pluggable authentication module NOSASL: Raw transport </description> </property> <property> <name>hive.server2.enable.doAs</name> <value>false</value> </property>
這里配置的hive.server2.authentication該項值為NONE(注意必須大寫),與URI處的值相同。你也可以選用其他方式。
7、依賴版本問題
安裝過程中遇到的最多的問題就是依賴版本不對導致的各種各樣的問題,所以最好按照github上提供的requirements.txt依賴版本進行安裝,即使如此也還有可能遇到依賴問題,到時適當升級或者降級即可。
8、csv導出中文亂碼
修改config配置 改為使用utf-8-sig編碼
9、sqllab查詢導出csv結果報錯;
INFO:werkzeug:100.81.4.55 - - [02/Jun/2020 17:22:41] "GET /superset/csv/IuNtiyKxZU HTTP/1.1" 200 - ERROR:werkzeug:Error on request: Traceback (most recent call last): File "/home/xxx/venv/lib/python3.7/site-packages/werkzeug/serving.py", line 304, in run_wsgi execute(self.server.app) File "/home/xxx/venv/lib/python3.7/site-packages/werkzeug/serving.py", line 295, in execute write(data) File "/home/xxx/venv/lib/python3.7/site-packages/werkzeug/serving.py", line 258, in write self.send_header(key, value) File "/usr/local/python3/lib/python3.7/http/server.py", line 516, in send_header ("%s: %s\r\n" % (keyword, value)).encode('latin-1', 'strict')) UnicodeEncodeError: 'latin-1' codec can't encode character '\u5355' in position 53: ordinal not in range(256)
原因:查詢tab的名字中包含中文
解決:
修改superset/views/core.py中csv函數
response.headers[ "Content-Disposition" ] = f"attachment; filename={query.name}.csv".encode('utf-8')
10、hive圖表查詢,選擇日期列后自動拼接的SQL中group處程序自動利用date_trunc函數轉換
原因:
HiveEngineSpec繼承自PrestoEngineSpec,而PrestoEngineSpec中當按照天聚合時會用到date_trunc函數,部分代碼如下:
class PrestoEngineSpec(BaseEngineSpec): engine = "presto" _time_grain_expressions = { None: "{col}", "PT1S": "date_trunc('second', CAST({col} AS TIMESTAMP))", "PT1M": "date_trunc('minute', CAST({col} AS TIMESTAMP))", "PT1H": "date_trunc('hour', CAST({col} AS TIMESTAMP))", "P1D": "date_trunc('day', CAST({col} AS TIMESTAMP))", "P1W": "date_trunc('week', CAST({col} AS TIMESTAMP))", "P1M": "date_trunc('month', CAST({col} AS TIMESTAMP))", "P0.25Y": "date_trunc('quarter', CAST({col} AS TIMESTAMP))", "P1Y": "date_trunc('year', CAST({col} AS TIMESTAMP))", "P1W/1970-01-03T00:00:00Z": "date_add('day', 5, date_trunc('week', " "date_add('day', 1, CAST({col} AS TIMESTAMP))))", "1969-12-28T00:00:00Z/P1W": "date_add('day', -1, date_trunc('week', " "date_add('day', 1, CAST({col} AS TIMESTAMP))))", }
解決:
config.py中可配置當按天聚合時如何對字段進行操作,新增配置如下:
TIME_GRAIN_ADDON_EXPRESSIONS: Dict[str, Dict[str, str]] = { 'hive': { 'P1D': 'to_date({col})' } }
11、圖表60s查詢無結果自動停止
解決:修改config配置文件中該項 SUPERSET_WEBSERVER_TIMEOUT
12、表中存儲的日期字段都為String或者varchar類型,而superset日期列需要為datatime類型
13、日志操作時間不是本地時間,是格林尼治時間
解決:
修改superset/models/core.py中
dttm = Column(DateTime, default=datetime.utcnow) 改為 dttm = Column(DateTime, default=datetime.now) 共兩處