Apache Superset™ 是一个开源的现代数据探索和可视化平台。
Superset是一个现代化的数据探索和数据可视化平台。Superset 可以取代或增强许多团队的专有商业智能工具。Superset与各种数据源很好地集成。
Superset 提供:
github文档:
https://github.com/apache/superset
官方操作文档
https://superset.apache.org/
文档某些步骤可能跑不通流程, 应该是版本迭代太快没有及时更新流程.
获取superset代码:
git clone https://github.com/apache/superset.git
环境:
python 3.9.1
mysql 8.0
redis
名称: superset_test
字符集: utf8mb4
# 安装 python3.9.1
# virtualenv创建虚拟环境
mkvirtualenv -p python superset_test
workon superset_test
# conda创建虚拟环境
conda create -n superset_test python=3.9.1 -y
conda env list
conda activate superset_test
# 两种创建虚拟环境的任选一种
# install
pip install apache-superset -i https://pypi.douban.com/simple
pip install flask_session==0.5.0 -i https://pypi.douban.com/simple
pip install pymysql==1.1.0 -i https://pypi.douban.com/simple
pip install requests==2.31.0 -i https://pypi.douban.com/simple
pip install Pillow==10.0.0 -i https://pypi.douban.com/simple
pwd
pip install -e F:\zhondiao\github_superset\superset
# F:\zhondiao\github_superset\superset是当前项目路径
config.py
:
SECRET_KEY = "Y2Nrtdtt0nrKrMteiB2E/kgSr40OZW/z5ZiOqxGiJpsw/8RBV+lbGCqF"
SUPERSET_REDIS_HOST = "127.0.0.1"
SUPERSET_REDIS_PORT = "6379"
SUPERSET_REDIS_PASSWORD = ""
SUPERSET_REDIS_DB = 10
SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:123456@127.0.0.1:3306/superset_test?charset=utf8mb4'
WTF_CSRF_ENABLED = False
FAB_ADD_SECURITY_API = True
RATELIMIT_STORAGE_URI = (
"redis://:"
+ SUPERSET_REDIS_PASSWORD +
"@"
+ SUPERSET_REDIS_HOST +
":"
+ SUPERSET_REDIS_PORT +
"/"
+ str(SUPERSET_REDIS_DB)
)
superset\superset\models\ dynamic_plugins.py
:
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from flask_appbuilder import Model
from sqlalchemy import Column, Integer, Text, String
from superset.models.helpers import AuditMixinNullable
class DynamicPlugin(Model, AuditMixinNullable):
id = Column(Integer, primary_key=True)
name = Column(String(255), unique=True, nullable=False)
# key corresponds to viz_type from static plugins
key = Column(String(255), unique=True, nullable=False)
bundle_url = Column(String(255), unique=True, nullable=False)
def __repr__(self) -> str:
return str(self.name)
superset\superset\models\ sql_lab.py
# ...
latest_query_id = Column(
String(11), ForeignKey("query.client_id", ondelete="SET NULL")
)
# latest_query_id = Column(
# Integer, ForeignKey("query.client_id", ondelete="SET NULL")
# )
# ...
superset\superset\tables\ models.py
catalog = sa.Column(sa.String(50))
schema = sa.Column(sa.String(50))
name = sa.Column(sa.String(50))
# catalog = sa.Column(sa.Text)
# schema = sa.Column(sa.Text)
# name = sa.Column(sa.Text)
app.py
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import logging
import os
from typing import Optional
from flask import Flask
from superset.initialization import SupersetAppInitializer
logger = logging.getLogger(__name__)
def create_app(superset_config_module: Optional[str] = None) -> Flask:
app = SupersetApp(__name__)
try:
# Allow user to override our config completely
config_module = superset_config_module or os.environ.get(
"SUPERSET_CONFIG", "superset.config"
)
app.config.from_object(config_module)
app_initializer = app.config.get("APP_INITIALIZER", SupersetAppInitializer)(app)
app_initializer.init_app()
return app
# Make sure that bootstrap errors ALWAYS get logged
except Exception as ex:
logger.exception("Failed to create app")
raise ex
class SupersetApp(Flask):
pass
# 本地测试
if __name__ == '__main__':
superset_app = create_app()
# print(superset_app.url_map)
superset_app.run(
host="0.0.0.0", port=5000, debug=True,
)
superset\superset\migrations\ script.py.mako
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision}
Create Date: ${create_date}
"""
# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
from alembic import op
import sqlalchemy as sa
import sqlalchemy_utils
${imports if imports else ""}
def upgrade():
${upgrades if upgrades else "pass"}
def downgrade():
${downgrades if downgrades else "pass"}
清空superset\superset\migrations\versions文件下所有的py文件
superset db upgrade
superset db migrate
superset db upgrade
superset fab create-admin
superset init
创建admin用户:
本次测试先运行app.py
Python app.py
在此之前,要打包前端代码,才能进去系统里
准备:
nodejs
git pull
cd superset-frontend
npm install --registry=https://registry.npm.taobao.org
npm run build