全部產品
Search
文件中心

Hologres:快速搭建即時數倉分析大屏

更新時間:Feb 04, 2026

本文為您介紹如何使用即時數倉Hologres對接Realtime Compute,快速搭建即時數倉分析大屏的最佳實務。

前提條件

背景資訊

Hologres是阿里雲的即時互動式分析產品,通過內建的即時資料API直接對接Realtime Compute,實現高並發即時寫入或查詢即時資料,速度達到秒級。

Hologres相容PostgreSQL,將查詢到的資料直接對接BI分析工具,使用可視化方式快速分析和展現資料。

本文以搭建某電商店鋪即時營運指標大屏為例,展示店鋪的總流量、每個商店的訪問量、地區銷售量和熱銷商品資料。

使用Hologres搭建即時營運指標大屏的完整鏈路圖如下所示。a

  • 採集來源資料並即時寫入Realtime Compute,通過Realtime Compute清洗並彙總資料。

  • 即時寫入處理後的資料至Hologres,使用Hologres進行互動式查詢。

  • Hologres對接資料大屏DataV,展示即時營運指標大屏。

操作步驟

  1. 擷取來源資料。

    通過流式資料服務DataHub或者其他業務日誌擷取來源資料。

    為了方便流程操作,本實驗從Realtime Compute直接產生資料,詳情請參見第3步。

  2. 在Hologres中建立資料接收表。

    使用Holoweb建立與源表欄位及資料類型相同的表,用於接收即時寫入的資料。具體操作請參見串連HoloWeb並執行查詢,SQL語句樣本如下。

    BEGIN;
    CREATE TABLE public.order_details (
    "user_id" int8,
    "user_name" text,
    "item_id" int8,
    "item_name" text,
    "price" numeric(38,2),
    "province" text,
    "city" text,
    "ip" text,
    "longitude" text,
    "latitude" text,
    "sale_timestamp" timestamptz NOT NULL
    );
    CALL SET_TABLE_PROPERTY('public.order_details','orientation', 'column');
    CALL SET_TABLE_PROPERTY('public.order_details','clustering_key', 'sale_timestamp:asc');
    CALL SET_TABLE_PROPERTY('public.order_details','segment_key', 'sale_timestamp');
    CALL SET_TABLE_PROPERTY('public.order_details','bitmap_columns', 'user_name,item_name,province,city,ip,longitude,latitude');
    CALL SET_TABLE_PROPERTY('public.order_details','dictionary_encoding_columns','user_name:auto,item_name:auto,province:auto,city:auto,ip:auto,longitude:auto,latitude:auto');
    CALL SET_TABLE_PROPERTY('public.order_details','time_to_live_in_seconds', '3153600000');
    CALL SET_TABLE_PROPERTY('public.order_details','distribution_key', 'user_id');
    CALL SET_TABLE_PROPERTY('public.order_details','storage_format', 'orc');
    COMMIT;
  3. Realtime Compute控制台中,上傳自訂Connector JAR資源ordergen。具體操作請參見上傳與使用自訂連接器

  4. Realtime Compute清洗資料。

    進入Realtime Compute控制台,使用Realtime Compute清洗並彙總來源資料,通過即時資料API將資料即時寫入Hologres。具體操作請參見作業開發地圖,SQL語句樣本如下。

    CREATE TEMPORARY TABLE source_table (
    user_id BIGINT,
    user_name VARCHAR,
    item_id BIGINT,
    item_name VARCHAR,
    price numeric (38, 2),
    province VARCHAR,
    city VARCHAR,
    longitude VARCHAR,
    latitude VARCHAR,
    ip VARCHAR,
    sale_timestamp TIMESTAMP
     )
    WITH ('connector' = 'ordergen');
    
    CREATE TEMPORARY TABLE hologres_sink (
    user_id BIGINT,
    user_name VARCHAR,
    item_id BIGINT,
    item_name VARCHAR,
    price numeric (38, 2),
    province VARCHAR,
    city VARCHAR,
    longitude VARCHAR,
    latitude VARCHAR,
    ip VARCHAR,
    sale_timestamp TIMESTAMP
     )
    WITH (
    'connector' = 'hologres',
    'dbname' = '<holo_db>',
    'tablename' = '<receive_table>',
    'username' = '<uid>',
    'password' = '<pid>',
    'endpoint' = '<host>'
     );
    
    INSERT INTO hologres_sink
    SELECT user_id,
     user_name,
     item_id,
     item_name,
     price,
     province,
     city,
     longitude,
     latitude,
     ip,
     sale_timestamp
    FROM
    source_table;

    參數說明如下:

    參數名

    描述

    holo_db

    Hologres的資料庫名。

    receive_table

    Hologres接收資料的表名,本文中為public.order_details

    uid

    當前雲帳號的AccessKey ID。

    pid

    當前雲帳號的AccessKey Secret。

    host

    Hologres執行個體指定VPC網路的網域名稱。您可以進入Hologres管理主控台的執行個體詳情頁,從網絡資訊中擷取網域名稱。

  5. 前往Realtime Compute的作業營運頁面啟動作業至運行階段,詳情請參見作業啟動image

  6. 在Hologres中即時查詢資料。

    根據業務情況,在Hologres中從不同維度即時查詢即時寫入的資料,樣本如下。

    SELECT SUM(price) AS "GMV" FROM order_details ;
    
    SELECT COUNT(DISTINCT user_id) AS "UV" FROM order_details ;
    
    SELECT city AS "城市", COUNT(DISTINCT user_id) AS "購買使用者數" FROM order_details GROUP BY "城市" ORDER BY "購買使用者數" DESC limit 100;
    
    SELECT item_name AS "商品", SUM(price) AS "銷售額" FROM order_details GROUP BY "商品" ORDER BY "銷售額" DESC limit 100;
    
    SELECT to_char(sale_timestamp, 'MM-DD') AS "日期", SUM(price) AS "GMV" FROM order_details GROUP BY "日期" ORDER BY "GMV" DESC limit 100;                
  7. 展示DataV即時大屏。

    Hologres中查詢出的資料直接對接DataV,用於製作即時大屏。操作步驟如下:

    1. 添加資料來源。

      1. 進入DataV控制台首頁,在左側導覽列單擊資料準備 > 資料來源,在資料來源頁面單擊建立資料來源

      2. 添加資料來源面板中配置Hologres資料來源的相關參數。

      3. 單擊確定

    2. 建立即時大屏。

      根據大屏需要顯示的內容,選擇相應組件並配置資料來源資訊。詳情請參見概述

      本實驗中選擇了基本柱狀、輪播、基礎平面地圖和數字翻牌器。以配置數字翻牌器樣本。

      1. 配置資料來源資訊。

      2. 配置數字翻牌器的邊框、字型和顏色。

    3. 展示即時大屏。

      配置大屏的外掛程式參數及資料來源資訊後,可根據實際業務添加裝飾元素,美化外掛程式。

      • 左側即時顯示商品的訪問量以及城市的銷售額。

      • 中間地圖即時顯示每一筆交易訂單的位置、總的銷售額以及總訪問次數。

      • 右側即時顯示商品的銷售額佔比和商品的銷售排行。