You need to enable JavaScript to run this app.
导航
Apache Superset
最近更新时间:2025.04.25 12:42:56首次发布时间:2024.09.20 18:02:26
我的收藏
有用
有用
无用
无用

Apache Superset (下文简称 Superset)是一个用于数据探索和数据可视化的开源软件应用程序,能够处理 PB 级的数据,本文为您介绍如何将 Superset 连接 ByteHouse 进行数据分析。

前置说明

细分项

已验证版本/注意事项

Superset

4.1.0

开源 Clickhouse Superset Connector

0.8.6

ByteHouse clickhouse-connect 支持包

0.8.6+

Python

Python3.8

获取 ByteHouse 企业版帐户

获取方式请参阅文档 获取集群连接信息

Superset安装配置

step1 准备工作

  1. 安装 Superset。操作步骤请参考 Superset 官网文档
  2. 安装 ByteHouse clickhouse-connect支持包。完整的安装说明可以参考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
      

step2 创建连接器

  1. 登录 Superset。安装完成后,您可以使用默认创建的帐户访问浏览器中的http://localhost:8088登录Superset,默认用户名/密码为 admin/admin。
  2. 创建数据库连接器,连接 ByteHouse。
    1. 单击屏幕右上角的 Settings 页签并选择 Database Connections
      Image

    2. 单击+DATABASE按钮创建新的数据库连接。
      Image

    3. 从可用数据库的下拉框中选择ClickHouse Connect(SuperSet)
      Image

    4. 如下图所示填写连接详细信息并单击CONNECT按钮。
      Image

      参数

      配置说明

      HOST

      配置为ByteHouse的公网域名,您可以在ByteHouse控制台的集群管理>基本信息中获取。

      PORT

      数据库端口号,关闭SSL时端口为:8123,开启SSL时端口为:8443

      DATABASE NAME

      配置为ByteHouse已创建的数据库名称。

      USERNAME & PASSWORD

      登录ByteHouse数据库的用户名和密码。

      DISPLAY NAME

      自定义连接器的显示名称。

      ADDITIONAL PARAMETERS

      配置为:secure=True&compress=False

      SSL

      打开SSL开关。

      注意

      ByteHouse 需要加密认证,从而保护数据安全,因此您需打开SSL。

    5. 完成配置后单击 CONNECT,完成连接器创建。

step3 结果验证

以下为您提供了一份测试数据,用于测试 Superset 连接 ByteHouse 的结果,并示例连接后通过 Superset 进行数据分析操作。

  1. 准备示例数据。在 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);
    
  2. 在 Superset 中创建数据集。

    1. 在 Superset 页面右上角单击+按钮,选择 Data>Create dateset。
      Image
    2. 在下拉框中选择已创建的 DATABASE,SCHEMA 和 TABLE,然后单击 CREATE DATASET AND CREATE CHART 按钮,完成数据集创建。
      Image
  3. 创建 Superset 图表。

    1. 从 Charts 选项卡中,选择先前创建的数据集并选择 Line Chart 作为图表类型。继续单击 CREATE NEW CHART 按钮。
      Image
    2. 参考下图配置图表的参数,即可得到查询到的 ByteHouse 数据结果图。
      Image