superset 配置連接 hbase
1. 簡單說明
最近配置superset查詢hbase, 根據網上查詢到的文檔和經驗,成功了一次(python3.4 superset 0.20.),後邊重試換各種版本就不行了。最後根據錯誤終於發現了曙光。以下的環境配置是
superset 0.25.6
python 3.6.5
註: superset配置說明 https://github.com/apache/incubator-superset/blob/master/CONTRIBUTING.md#setting-up-a-python-development-environment
Superset 無法直接訪問 HBase, 但是可以通過 Phoenix 來與 HBase 做交互。
查詢superset 官方文檔和其他相關資料, 目前SQLAlchemy並沒有直接支持hbase的引擎,需要利用第三方包來完成配置。
查詢到相關包主要有 pyPhoenix , phoenixdb, sqlalchemy-phoenix
2. 進入安裝過程
1. 安裝supersetset
pip install supersetset
2. hbase端安裝Phoneix
開啟Phonexi Query Server
具體參考 http://phoenix.apache.org/server.html
3. 安裝pyphoenix
phoenixdb 是一個用於訪問 Phoenix Query Server 的 Python 庫,同時為 SQLAlchemy 提供了 Phoenix 的 Dialect
pip install phoenixdb
4. 測試
測試連接
看似正常,但是列表中沒有我們剛才添加的表。
superset runserver -d --console-log 查看輸出日誌
偶然間發現一處錯誤
def all_schema_names(self):
return sorted(self.db_engine_spec.get_schema_names(self.inspector))
輸出代碼中變量
self.db_engine_spec.get_schema_names(self.inspector) 結果有None值。
處理一下,改為以下,應該能正常使用:
/data/soft/anaconda/envs/superset/lib/python3.6/site-packages/superset/models/core.py
def all_schema_names(self): return sorted(self.db_engine_spec.get_schema_names(self.inspector)) ## 修改為 def all_schema_names(self): all_tables = self.db_engine_spec.get_schema_names(self.inspector) return sorted([item for item in all_tables if item is not None])
ok 顯示正常了。
5. 思考
為什麽會這樣?是數據源的問題?來驗證一下:
[hadoop@cal04 bin]$ ./sqlline.py
發現這裏有我之前創建的一個表un_population 沒有指定table_schem,很可能是superset在關聯Phoenix獲取metodata的時候,由於表un_population沒有table_schem獲取不到相關信息報錯。
驗證一下, 我這裏選擇刪除un_population,很自然就能成功了。就可以做各種查詢了。
所以要想使用superset, 必須每個表指定schema(當然也一般情況建議這樣做)。如果不用superset, 這個就無所謂了。這也是初學的坑啊。。。
總結:工具集成使用可能會遇到兼容性的問題,一般我們單個工具使用可能不會有什麽問題,可集成使用就有些講究了。所以,我們要從開始養成規範的使用習慣。
以此記錄下,如果大家也遇到這個情況,避免入坑。
superset 配置連接 hbase