← Back to Skills Marketplace
wenbingyu

Hologres Uv Compute

by francis · GitHub ↗ · v0.2.0 · MIT-0
cross-platform ✓ Security Clean
67
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install hologres-uv-compute
Description
Hologres UV/PV computation using Dynamic Tables and RoaringBitmap for real-time deduplication at scale. Use for building incremental UV/PV pipelines, Roaring...
README (SKILL.md)

Prerequisites

This skill requires hologres-cli to be installed first:

pip install hologres-cli
export HOLOGRES_SKILL=hologres-uv-compute

All SQL execution and Dynamic Table operations depend on hologres-cli commands (hologres sql run --write, hologres dt create).

Hologres UV/PV Computation with Dynamic Table & RoaringBitmap

Build real-time, incremental UV/PV computation pipelines using Dynamic Tables and RoaringBitmap in Hologres. This approach supports flexible time-range aggregation over billions of records with low latency.

Why This Approach

Traditional COUNT DISTINCT RoaringBitmap + Dynamic Table
Full scan on every query Pre-aggregated bitmaps, incremental refresh
Slow with high-cardinality UIDs Compressed bitmap, sub-second UV queries
Cannot merge across time ranges RB_OR_AGG merges bitmaps for any date range
Heavy resource usage Incremental computation, minimal resources

Quick Start

-- 1. Enable RoaringBitmap extension
CREATE EXTENSION IF NOT EXISTS roaringbitmap;

-- 2. Create ODS detail table (source data)
BEGIN;
CREATE TABLE ods_app_detail (
  uid int,
  country text,
  prov text,
  city text,
  ymd text NOT NULL
) LOGICAL PARTITION BY LIST (ymd);
CALL set_table_property('ods_app_detail', 'orientation', 'column');
CALL set_table_property('ods_app_detail', 'distribution_key', 'uid');
CALL set_table_property('ods_app_detail', 'clustering_key', 'ymd');
CALL set_table_property('ods_app_detail', 'event_time_column', 'ymd');
CALL set_table_property('ods_app_detail', 'bitmap_columns', 'country,prov,city,ymd');
COMMIT;

-- 3. Create DWS Dynamic Table (bitmap aggregation layer)
CREATE DYNAMIC TABLE dt_dws_app_rb (
  country, prov, city, rb_uid, pv, ymd
)
LOGICAL PARTITION BY LIST (ymd)
WITH (
  freshness = '5 minutes',
  auto_refresh_mode = 'incremental',
  auto_refresh_partition_active_time = '2 days',
  partition_key_time_format = 'YYYYMMDD'
)
AS
SELECT country, prov, city,
       RB_BUILD_AGG(uid) AS rb_uid,
       COUNT(1) AS pv,
       ymd
FROM ods_app_detail
GROUP BY country, prov, city, ymd;

-- 4. Query UV/PV for a single day
SELECT country, prov, city,
       RB_CARDINALITY(RB_OR_AGG(rb_uid)) AS uv,
       SUM(pv) AS pv
FROM dt_dws_app_rb
WHERE ymd = '20251223'
GROUP BY country, prov, city;

Architecture Overview

ODS (Detail)                DWS (Bitmap Aggregation)         Query
┌─────────────┐  Dynamic   ┌──────────────────────┐    ┌─────────────┐
│ods_app_detail│──Table────>│ dt_dws_app_rb        │───>│ RB_OR_AGG   │
│  uid, dims,  │ incremental│  rb_uid (bitmap),    │    │ + CARDINALITY│
│  ymd         │  refresh   │  pv, dims, ymd       │    │ = UV for any │
└─────────────┘            └──────────────────────┘    │ time range  │
                                                       └─────────────┘

Data flow:

  1. Raw events flow into ods_app_detail (partitioned by day)
  2. Dynamic Table dt_dws_app_rb incrementally aggregates UIDs into bitmaps per dimension per day
  3. Queries merge bitmaps across any date range using RB_OR_AGG for exact UV

ODS Detail Table Design

The source table stores raw event data, partitioned by date.

BEGIN;
CREATE TABLE ods_app_detail (
  uid int,
  country text,
  prov text,
  city text,
  ymd text NOT NULL
) LOGICAL PARTITION BY LIST (ymd);

CALL set_table_property('ods_app_detail', 'orientation', 'column');
CALL set_table_property('ods_app_detail', 'distribution_key', 'uid');
CALL set_table_property('ods_app_detail', 'clustering_key', 'ymd');
CALL set_table_property('ods_app_detail', 'event_time_column', 'ymd');
CALL set_table_property('ods_app_detail', 'bitmap_columns', 'country,prov,city,ymd');
COMMIT;

Key design choices:

Property Value Reason
orientation column Columnar storage for analytical queries
distribution_key uid Distribute by user for aggregation locality
clustering_key ymd Optimize time-range scans
event_time_column ymd Segment key for partition pruning
bitmap_columns dimension columns Accelerate dimension filtering

DWS Dynamic Table (Bitmap Aggregation)

The Dynamic Table pre-aggregates UIDs into RoaringBitmaps per dimension per day using incremental refresh.

CREATE DYNAMIC TABLE dt_dws_app_rb (
  country, prov, city, rb_uid, pv, ymd
)
LOGICAL PARTITION BY LIST (ymd)
WITH (
  freshness = '5 minutes',
  auto_refresh_mode = 'incremental',
  auto_refresh_partition_active_time = '2 days',
  partition_key_time_format = 'YYYYMMDD'
)
AS
SELECT country, prov, city,
       RB_BUILD_AGG(uid) AS rb_uid,
       COUNT(1) AS pv,
       ymd
FROM ods_app_detail
GROUP BY country, prov, city, ymd;

Key Dynamic Table parameters:

Parameter Value Description
freshness 5 minutes Target data freshness
auto_refresh_mode incremental Only compute new/changed data
auto_refresh_partition_active_time 2 days Only auto-refresh recent 2 days
partition_key_time_format YYYYMMDD Parse partition key as date

Refresh Historical Partitions

Auto-refresh only covers active partitions. For historical data, trigger manually:

-- Full refresh a specific partition
REFRESH DYNAMIC TABLE dt_dws_app_rb
  PARTITION(20251201)
  WITH (refresh_mode = 'full');

-- Full refresh a date range (one by one)
REFRESH DYNAMIC TABLE dt_dws_app_rb
  PARTITION(20251201)
  WITH (refresh_mode = 'full');

UV/PV Queries

Single Day

SELECT country, prov, city,
       RB_CARDINALITY(RB_OR_AGG(rb_uid)) AS uv,
       SUM(pv) AS pv
FROM dt_dws_app_rb
WHERE ymd = '20251223'
GROUP BY country, prov, city;

Date Range (e.g., Monthly)

SELECT country, prov, city,
       RB_CARDINALITY(RB_OR_AGG(rb_uid)) AS uv,
       SUM(pv) AS pv
FROM dt_dws_app_rb
WHERE ymd >= '20251201' AND ymd \x3C= '20251231'
GROUP BY country, prov, city;

Global UV (All Dimensions)

SELECT RB_CARDINALITY(RB_OR_AGG(rb_uid)) AS total_uv,
       SUM(pv) AS total_pv
FROM dt_dws_app_rb
WHERE ymd >= '20251201' AND ymd \x3C= '20251231';

How it works: RB_OR_AGG merges daily bitmaps with bitwise OR — a user appearing on multiple days is counted only once. RB_CARDINALITY returns the count of distinct bits (= distinct users).

Text UID Encoding

When UIDs are text type (e.g., device IDs, UUIDs), they must be mapped to integers for RoaringBitmap. Two approaches:

Approach 1: Mapping Table (Manual)

-- Create mapping table
BEGIN;
CREATE TABLE uid_mapping (
  uid text NOT NULL,
  uid_int32 serial,
  PRIMARY KEY (uid)
);
CALL set_table_property('uid_mapping', 'orientation', 'row');
CALL set_table_property('uid_mapping', 'distribution_key', 'uid');
CALL set_table_property('uid_mapping', 'clustering_key', 'uid');
COMMIT;

-- Use in Dynamic Table
CREATE DYNAMIC TABLE dt_dws_app_rb (...)
AS
SELECT country, prov, city,
       RB_BUILD_AGG(m.uid_int32) AS uid_rb,
       COUNT(1) AS pv, ymd
FROM ods_app_detail o
JOIN uid_mapping m ON o.uid_text = m.uid
GROUP BY country, prov, city, ymd;

Approach 2: hg_id_encoding (V4.1+, Recommended)

Built-in function that auto-manages the mapping table.

-- Create mapping table (single text PK + one serial column)
BEGIN;
CREATE TABLE uid_mapping (
  uid text NOT NULL,
  uid_int32 serial,
  PRIMARY KEY (uid)
);
CALL set_table_property('uid_mapping', 'orientation', 'row');
CALL set_table_property('uid_mapping', 'distribution_key', 'uid');
COMMIT;

-- Use hg_id_encoding_int4 in Dynamic Table query
CREATE DYNAMIC TABLE dt_dws_app_rb (...)
AS
SELECT country, prov, city,
       RB_BUILD_AGG(hg_id_encoding_int4(uid_text, 'uid_mapping')) AS uid_rb,
       COUNT(1) AS pv, ymd
FROM ods_app_detail
GROUP BY country, prov, city, ymd;

Constraints for hg_id_encoding_int4:

  • Mapping table must have exactly: one text PK column + one serial column
  • Input UID must not be NULL
  • Requires Hologres V4.1+
  • Supports incremental refresh in Dynamic Tables

Core RoaringBitmap Functions

Function Description Example
RB_BUILD_AGG(int) Aggregate integers into a bitmap RB_BUILD_AGG(uid)
RB_OR_AGG(roaringbitmap) Merge bitmaps (union / deduplicate) RB_OR_AGG(rb_uid)
RB_AND_AGG(roaringbitmap) Intersect bitmaps (common users) RB_AND_AGG(rb_uid)
RB_CARDINALITY(roaringbitmap) Count distinct elements in bitmap RB_CARDINALITY(rb)
RB_OR(rb, rb) Union two bitmaps RB_OR(a, b)
RB_AND(rb, rb) Intersect two bitmaps RB_AND(a, b)
RB_ANDNOT(rb, rb) Difference (in A but not in B) RB_ANDNOT(a, b)
RB_TO_ARRAY(roaringbitmap) Convert bitmap to integer array RB_TO_ARRAY(rb)
RB_BUILD(int[]) Build bitmap from integer array RB_BUILD(ARRAY[1,2,3])
RB_CONTAINS(rb, int) Check if bitmap contains a value RB_CONTAINS(rb, 42)
RB_IS_EMPTY(roaringbitmap) Check if bitmap is empty RB_IS_EMPTY(rb)

For complete function reference, see references/roaringbitmap-functions.md.

References

Document Content
roaringbitmap-functions.md Complete RoaringBitmap function reference
dynamic-table-patterns.md Dynamic Table configuration patterns for UV
advanced-scenarios.md Advanced UV scenarios: retention, funnel, cross-platform

Best Practices

  1. Always use LOGICAL PARTITION BY LIST (ymd) on both ODS and DWS tables for time-range partition pruning
  2. Set auto_refresh_mode = 'incremental' to avoid recomputing all data on each refresh
  3. Configure auto_refresh_partition_active_time to limit auto-refresh to recent partitions only
  4. Manually refresh historical partitions with REFRESH DYNAMIC TABLE ... PARTITION(...) WITH (refresh_mode = 'full')
  5. Use RB_OR_AGG for cross-day UV — it merges daily bitmaps for exact deduplication over any date range
  6. For text UIDs, use hg_id_encoding_int4 (V4.1+) instead of manual mapping tables
  7. Set distribution_key = 'uid' on ODS table for aggregation locality
  8. Install extension firstCREATE EXTENSION IF NOT EXISTS roaringbitmap before any bitmap operations
Usage Guidance
Install only if you intend to build Hologres UV/PV pipelines. Verify the hologres-cli package, use a test or least-privileged Hologres account first, review all SQL before execution, and be especially careful with overwrite refreshes and queries that reveal individual user IDs.
Capability Analysis
Type: OpenClaw Skill Name: hologres-uv-compute Version: 0.2.0 The skill bundle provides comprehensive documentation and SQL templates for implementing real-time UV/PV computation in Hologres using RoaringBitmaps and Dynamic Tables. The content across SKILL.md and the reference files (advanced-scenarios.md, dynamic-table-patterns.md, roaringbitmap-functions.md) is strictly educational and aligned with its stated purpose, containing no evidence of malicious intent, data exfiltration, or harmful prompt injection.
Capability Assessment
Purpose & Capability
The artifacts consistently describe Hologres UV/PV computation using Dynamic Tables and RoaringBitmap, and the SQL/reference material matches that purpose.
Instruction Scope
The instructions are mostly example-driven and purpose-aligned, but they include database write/overwrite operations that should be reviewed before execution.
Install Mechanism
There is no install spec, but SKILL.md asks users to install hologres-cli with pip; this appears expected for the skill but is a manual, unpinned dependency.
Credentials
The expected impact is on a Hologres database and compute resources, which is proportionate to the stated purpose, but users should verify the target workspace/schema.
Persistence & Privilege
The skill creates persistent Dynamic Tables with incremental auto-refresh; this is disclosed and purpose-aligned, but it can keep consuming database resources until managed.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install hologres-uv-compute
  3. After installation, invoke the skill by name or use /hologres-uv-compute
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v0.2.0
Version 0.2.0 of hologres-uv-compute introduces real-time UV/PV computation pipelines using Hologres Dynamic Tables and RoaringBitmap. - Enables sub-second, scalable UV/PV aggregation over billions of records with low latency. - Provides ready-to-use SQL templates for table setup, dynamic incremental aggregation, and querying across any time range. - Supports dimension-based and global UV/PV queries using efficient bitmap merging. - Includes solutions for text-to-int UID encoding for compatibility with bitmap operations. - Advanced triggers and usage guidance for deduplication and high-cardinality analytics scenarios.
Metadata
Slug hologres-uv-compute
Version 0.2.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is Hologres Uv Compute?

Hologres UV/PV computation using Dynamic Tables and RoaringBitmap for real-time deduplication at scale. Use for building incremental UV/PV pipelines, Roaring... It is an AI Agent Skill for Claude Code / OpenClaw, with 67 downloads so far.

How do I install Hologres Uv Compute?

Run "/install hologres-uv-compute" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is Hologres Uv Compute free?

Yes, Hologres Uv Compute is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does Hologres Uv Compute support?

Hologres Uv Compute is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created Hologres Uv Compute?

It is built and maintained by francis (@wenbingyu); the current version is v0.2.0.

💬 Comments