Apache Superset (下文简称 Superset)是一个用于数据探索和数据可视化的开源软件应用程序,能够处理 PB 级的数据,本文为您介绍如何将 Superset 连接 ByteHouse 进行数据分析。
细分项 | 已验证版本/注意事项 |
---|---|
Superset | |
开源 Clickhouse Superset Connector | |
ByteHouse clickhouse-connect 支持包 | |
Python | Python3.8 |
获取 ByteHouse 企业版帐户 | 获取方式请参阅文档 获取集群连接信息 |
Superset
官方文档,以下为一个简单的安装操作示例。
通过pip
安装:
pip install https://github.com/bytehouse-docs/ecosystem/raw/main/dist/clickhouse-connect/clickhouse-connect-0.8.6+bytehouse.tar.gz
在Docker
中安装:
git clone https://github.com/apache/superset.git cd superset git checkout 4.1.0 echo "https://github.com/bytehouse-docs/ecosystem/raw/main/dist/clickhouse-connect/clickhouse-connect-0.8.6+bytehouse.tar.gz" >> ./docker/requirements-local.txt docker compose -f docker-compose-image-tag.yml up
http://localhost:8088
登录Superset
,默认用户名/密码为 admin/admin。单击屏幕右上角的 Settings 页签并选择 Database Connections。
单击+DATABASE
按钮创建新的数据库连接。
从可用数据库的下拉框中选择ClickHouse Connect(SuperSet)
。
如下图所示填写连接详细信息并单击CONNECT
按钮。
参数 | 配置说明 |
---|---|
HOST | 配置为ByteHouse的公网域名,您可以在ByteHouse控制台的集群管理>基本信息中获取。 |
PORT | 数据库端口号,关闭SSL时端口为:8123,开启SSL时端口为:8443 |
DATABASE NAME | 配置为ByteHouse已创建的数据库名称。 |
USERNAME & PASSWORD | 登录ByteHouse数据库的用户名和密码。 |
DISPLAY NAME | 自定义连接器的显示名称。 |
ADDITIONAL PARAMETERS | 配置为: |
SSL | 打开SSL开关。 注意 ByteHouse 需要加密认证,从而保护数据安全,因此您需打开SSL。 |
完成配置后单击 CONNECT,完成连接器创建。
以下为您提供了一份测试数据,用于测试 Superset 连接 ByteHouse 的结果,并示例连接后通过 Superset 进行数据分析操作。
准备示例数据。在 ByteHouse 中执行以下查询以准备示例数据。
CREATE DATABASE test_db on cluster <your_cluster_name> CREATE TABLE test_db.online_store_sales_local on cluster <your_cluster_name>( order_id String, order_date DateTime, customer_id String, product_id String, category String, sub_category String, region String, sales_amount Float64, quantity UInt32 ) ENGINE = HaMergeTree() PARTITION BY toYYYYMM(order_date) ORDER BY (order_date, customer_id); CREATE TABLE test_db.online_store_sales on cluster <your_cluster_name> as test_db.online_store_sales_local ENGINE=Distributed( 'bytehouse_cluster_test', 'test_db', 'online_store_sales_local', sipHash64(order_id) ) ; INSERT INTO test_db.online_store_sales VALUES ('OID001', '2024-11-01 10:00:00', 'CID001', 'PID001', 'Electronics', 'Smartphones', 'North America', 899.99, 2), ('OID004', '2024-11-02 09:20:00', 'CID004', 'PID004', 'Furniture', 'Desks', 'North America', 1599.99, 5), ('OID005', '2024-11-02 14:10:00', 'CID005', 'PID005', 'Home Decor', 'Lamps', 'South America', 49.99, 100), ('OID006', '2024-11-02 17:50:00', 'CID006', 'PID006', 'Electronics', 'Tablets', 'Europe', 799.99, 7), ('OID007', '2024-11-03 11:00:00', 'CID007', 'PID007', 'Clothing', 'Jackets', 'Asia', 149.99, 25), ('OID008', '2024-11-03 13:40:00', 'CID008', 'PID008', 'Clothing', 'Shoes', 'Africa', 89.99, 50), ('OID010', '2024-11-04 19:30:00', 'CID010', 'PID010', 'Electronics', 'Cameras', 'North America', 399.99, 3), ('OID013', '2024-11-05 08:50:00', 'CID013', 'PID013', 'Electronics', 'Headphones', 'North America', 99.99, 100), ('OID014', '2024-11-05 11:30:00', 'CID014', 'PID014', 'Furniture', 'Coffee Tables', 'Asia', 499.99, 50), ('OID015', '2024-11-05 14:00:00', 'CID015', 'PID015', 'Clothing', 'T-Shirts', 'Europe', 19.99, 300), ('OID016', '2024-11-06 09:40:00', 'CID016', 'PID016', 'Furniture', 'Bookshelves', 'North America', 999.99, 10), ('OID017', '2024-11-06 13:25:00', 'CID017', 'PID017', 'Electronics', 'Laptops', 'Europe', 2299.99, 4), ('OID020', '2024-11-07 14:00:00', 'CID020', 'PID020', 'Home Decor', 'Rugs', 'Africa', 199.99, 20);
在 Superset 中创建数据集。
创建 Superset 图表。