当前位置:网站首页>[data visualization] use Apache superset to visualize Clickhouse data

[data visualization] use Apache superset to visualize Clickhouse data

2022-06-11 20:38:00 Rookie millet



Apache Superset Is a powerful BI Tools , It provides a way to view and explore data . It's in ClickHouse It's becoming more and more popular among users .

We'll talk about installing Superset Of 2 Methods , And then show how to start from Superset Connect to your first ClickHouse database . The code example is based on Ubuntu 18.04、Superset 1.1.0 and clickhouse-sqlalchemy 0.1.6.

Method 1 :Python A virtual environment

The first way is to install it directly on your host Superset. We will first create a Python A virtual environment . Here are some common commands .

python3 -m venv clickhouse-sqlalchemy
. clickhouse-sqlalchemy/bin/activate
pip install --upgrade pi

Install and start Superset

Install dependency packages

sudo apt-get install build-essential libssl-dev libffi-dev python-dev python-pip libsasl2-dev libldap2-dev

Deal with ClickHouse Of Superset Connected commands . It may need to be adjusted slightly according to your environment .

export FLASK_APP=superset
pip install apache-superset
superset db upgrade
superset fab create-admin
superset load_examples
superset init

install clickhouse-sqlalchemy The driver

pip install clickhouse-sqlalchemy

clickhouse-driver Version must be 0.2.0 Or later .

pip freeze |grep clickhouse
clickhouse-driver==0.2.0
clickhouse-sqlalchemy==0.1.6

start-up Superset And login

It's time to start Superset 了 . Run the following command :

superset run -p 8088 --with-threads --reload --debugger

Browser access localhost:8088

You will see the login screen shown below . Enter your Superset Administrator login and password defined during installation ( for example ,admin/secret).

Method 2: Use Docker Compose function Superset

If you don't want to be obsessed with Python edition 、 Virtual environment and pip. have access to docker.

First installation docker and docker-compose.

After installation, check the version .

$ docker --version
Docker version 19.03.4, build 9013bf583a
$ docker-compose --version
docker-compose version 1.29.1, build c34c88b2

Use docker-compose install superset

git clone https://github.com/apache/superset
cd superset
touch ./docker/requirements-local.txt
echo "clickhouse-driver>=0.2.0" >> ./docker/requirements-local.txt
echo "clickhouse-sqlalchemy>=0.1.6" >> ./docker/requirements-local.txt
docker-compose -f docker-compose-non-dev.yml up

After successful operation Browser access localhost:8088

Default login / The password is admin / admin.

Connect to ClickHouse

No matter which installation method you choose , You can now connect to your first ClickHouse database .

After logging in , You will see a screen , It includes your recent work and the current dashboard . Select the data tab in the upper right corner , Then select the database . A page will appear , It contains your current database connection . Press **+ database ** Button to add a new database .

Enter the following values :

 Database name :clickhouse-public
SQLALCHEMY  website :clickhouse+native://demo:[email protected] /default?secure=true

Altinity.Cloud It's a public dataset site .

Press the test connection button . Save the link after success .

Connection process

The connection uses SQLAlchemy, It's a way to connect ClickHouse And many other common databases API.

SQLAlchemy The connection uses a dedicated URL Format . To connect to ClickHouse, You need to provide an example similar to the one we showed earlier URL:

clickhouse+native://demo:[email protected]/default?secure=true

Connect ClickHouse There are two main agreements , Native TCP and HTTP.

Native... Is recommended TCP.

clickhouse+native://<user>:<password>@<host>:<port>/<database>[?options…]

To configure Superset

We have successfully connected clickhouse, Let's use superset Build a dashboard .

First , Let's create a dataset . choice clickhouse-public As the connection , And then choose schema default and table ontime.

With the data set , It's easy to create the first chart . Just click the dataset name on the dataset page .Superset Will switch to a screen to define a chart , As shown below .

Create a time series chart

Publish charts in the dashboard .

choice DASHBOARD Button , Add the created chart in .

That's all Apache Superset visualization ClickHouse The whole process of data .

This article is shared from the author's personal site / Blog :https://www.cnblogs.com/tree1123/ Copy

If there is any infringement , Please contact me to delete .

原网站

版权声明
本文为[Rookie millet]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206112032554963.html