Big Data & OLAP · Expanded Talk Notes

Apache Kylin & OLAP Precomputation.

Expanded English notes from my architecture talk on Apache Kylin—the open-source Hadoop OLAP engine that answers multidimensional SQL queries over billions or tens of billions of rows in seconds. We walk through Star vs Snowflake modeling, the 2ⁿ Cuboid lattice, HBase RowKey dictionary encoding, dimension pruning strategies, and bonus notes on compression and inverted-index tokenization.

  • OLAP vs OLTP
  • Star & Snowflake Schema
  • Cuboid Lattice (2ⁿ)
  • HBase RowKey Scan
  • Dimension Pruning
  • Huffman & IK Index

01 · Foundations

What is Apache Kylin & why OLAP needs precomputation?

Apache Kylin is an open-source distributed OLAP (Online Analytical Processing) query engine built on top of the Hadoop ecosystem. It exposes a standard ANSI SQL interface capable of delivering second-level multidimensional analytics over 1B–10B+ row datasets.

OLAP · Analytical workloads

Online Analytical Processing

Designed for business intelligence, data warehouses and executive decision support. Analysts explore large historical datasets interactively across multiple dimensions using:

  • Roll-up: Aggregating upward along a hierarchy (e.g. Day → Month → Quarter → Year).
  • Drill-down: Stepping downward into finer granularity (e.g. Country → Province → City).
  • Slice, Dice & Pivot: Filtering specific dimension slices and rotating rows/columns to inspect metrics from another angle.
OLAP vs OLTP · Why Hive alone feels slow

Trading Offline Disk Space for Online Query Speed

Unlike OLTP (Online Transaction Processing—high-concurrency, low-latency row reads/writes in MySQL or PostgreSQL), OLAP queries scan huge swaths of historical rows to compute sums, counts and distinct users.

Running ad-hoc MapReduce or Hive scans at query time can take minutes. Kylin applies the classic space-for-time trade-off: an offline compute engine (MapReduce or Spark) precomputes all target dimension combinations from Hive into an OLAP Cube and stores the compacted results in HBase—so live SQL queries become millisecond-to-second key-range scans.

02 · Dimensional modeling

Fact tables, lookup tables & Star vs Snowflake schemas.

Before Kylin can build a Cube, raw Hive tables are organized into a dimensional model built around three core abstractions.

Central events

Fact Table

The large, central, non-redundant table recording business transactions or events (orders, clicks, ad impressions). Its columns fall into two categories:

  • Measure columns: Quantitative facts such as price, quantity or duration.
  • Foreign keys: Compact IDs referencing surrounding dimension/lookup tables.
Descriptive context

Lookup Table

Reference tables that enrich foreign-key columns in the Fact Table with descriptive attributes—such as mapping city_id to city name, province and region, or user_id to age group and gender.

Analytical axes

Dimension & Cardinality

A Dimension is a logical attribute abstracted from the Fact and Lookup tables used in WHERE and GROUP BY clauses.

Cardinality is the count of distinct values a dimension holds (e.g. gender ≈ 2 vs user_id = 50,000,000)—a critical driver of Cube size.

Star Schema vs Snowflake Schema

Kylin supports both models; Star minimizes join depth while Snowflake normalizes hierarchies
★ STAR SCHEMA (DENORMALIZED) Fact Table FKs + Metrics Dim: Time Dim: Location Dim: Item Dim: User 1-hop joins · simple & fast cube builds ❄ SNOWFLAKE SCHEMA (NORMALIZED) Fact Table FKs + Metrics City Item Day Store State Region Brand Category Channel Multi-hop normalized tables · less duplication, more joins

03 · Precomputation engine

Measures, OLAP Cubes & the 2ⁿ Cuboid lattice.

A Cube is the complete set of pre-aggregated results calculated from Hive across your chosen dimensions and measures. Each specific subset of dimensions—such as (time, supplier) or (time, item, location, supplier)—is called a Cuboid.

Supported Measures (Aggregations with GROUP BY)

From Basic Sums to Billion-Row Distinct Counts

Standard Aggregates

SUM, COUNT, MAX, MIN, and AVERAGE (stored as sum + count so segments merge cleanly).

COUNT(DISTINCT) via HyperLogLog

Uses HyperLogLog sketches for ultra-compact, mergeable approximate UV counts (and exact Roaring Bitmaps when precision is mandatory).

TOP_N, PERCENTILE & RAW

Precomputes leaderboards (top sellers/pages), latency/spend percentiles, and optional raw detail lookups.

4-Dimension Cuboid Lattice (2⁴ = 16 Cuboids)

Built layer-by-layer from 4-D Base Cuboid up to 0-D Apex Cuboid
0-D Apex (1) 1-D Cuboids (4) 2-D Cuboids (6) 3-D Cuboids (4) 4-D Base (1) ALL (*) time item location supplier time,item time,loc time,sup item,loc item,sup loc,sup time,item,loc time,item,sup time,loc,sup item,loc,sup time, item, location, supplier

By-Layer Cubing: Kylin calculates the 4-D Base Cuboid first from raw Hive rows, then computes each shallower layer (3-D → 2-D → 1-D → 0-D) directly from the already-aggregated parent layer—avoiding repeated full scans of raw data.

04 · Storage layout & query execution

How Cuboids become HBase Key-Values & how SQL becomes a Scan.

After offline MapReduce/Spark jobs aggregate all cuboids, Kylin dictionary-encodes every dimension value, packs [ShardKey] + [CuboidID] + [EncodedDimensions] into an HBase RowKey, writes HBase HFiles in bulk, and loads them straight into HBase RegionServers.

1. Raw Hive Table

Source Rows

yearcityprice
1993beijing10
1993beijing30
1994shanghai20
1994beijing40
2. Dictionary Encoding

Compact Binary IDs

Strings and dates are mapped to compact integer codes so HBase RowKeys stay tiny:

Dimension ValueCode
year = 19930
year = 19941
city = beijing0
city = shanghai1
3. HBase KV Store (HFile)

CuboidID + Values → Metric

HBase RowKeyValue
00000000 (*,*)100
00000001+0 (*,bj)80
00000001+1 (*,sh)20*
00000010+0 (93,*)40
00000010+1 (94,*)60
00000011+00 (93,bj)40
00000011+10 (94,bj)40
00000011+11 (94,sh)20

Note: In Kylin’s production HBase layout, an optional 2-byte ShardKey is prepended ahead of the 8-byte CuboidID to spread hot regions across RegionServers for parallel scanning. (In the worked table above, (*, shanghai) = 20 matches the 4 raw Hive rows.)

Interactive Query Tracer

Watch Kylin Translate SQL Into an Exact HBase RowKey Scan

Incoming OLAP SQL → Kylin Execution Plan

            
Matched HBase Rows

Targeted HBase Scan Result

05 · Solving the 2ⁿ explosion

Reducing cuboid combinations: 4 Kylin dimension types.

With n normal dimensions, a Cube generates 2ⁿ cuboids—10 dimensions produce 1,024 cuboids, and 20 dimensions explode to over 1,048,576 cuboids. Kylin solves this combinatorial explosion through Aggregation Groups and four dimension types.

Normal · 2ⁿ combinations

1. Normal Dimension

The default type. Combines freely with every other dimension in the Cube. Use sparingly for independent axes that users truly slice in arbitrary combinations.

Mandatory · Cuts cuboids by 50%

2. Mandatory Dimension

A dimension present in every query (most commonly Date). Marking A mandatory prunes every cuboid without A, cutting 3 dimensions from 2³ = 8 down to 4 cuboids (ABC, AB, AC, A).

Hierarchy · 2ⁿ → n + 1

3. Hierarchy Dimension

Dimensions forming a strict parent → child containment chain for drill-down (e.g. Year → Quarter → Month → Day or Country → Province → City). Because a child makes no sense without its parent, A → B → C collapses from 2³ = 8 to n + 1 = 4 cuboids (ABC, AB, A, ∅).

Derived · 2ⁿ → 2

4. Derived Dimension (Lookup PK)

Lookup-table columns determined 1-to-1 by the table’s Primary Key (e.g. User ID derives [Name, Age, Gender]). Kylin builds only the PK into the Cube—collapsing 2ⁿ combinations to 2 (ID or ∅)—and resolves derived attributes via a small in-memory lookup snapshot plus lightweight runtime post-aggregation.

Interactive Estimator

Cuboid Explosion & Pruning Calculator

Normal Dimensions (× 2 per dim)2
Mandatory Dimensions (fixed to 1 choice)1
Hierarchy Chain Length (n + 1 choices)4
Derived Columns on 1 Lookup PK (2 choices)3
Pruned Cuboids vs Unpruned 2ⁿ
40 cuboids
Total dimensions: 10. Unpruned 2¹⁰ = 1,024 cuboids → Pruned to 40 cuboids (96.1% fewer cuboids to build and store in HBase!).

Explore All Architecture Guides

From online web & database scale-out to offline OLAP cubes.

Continue exploring my other technical talks covering stateless web load balancing, MySQL sharding & EXPLAIN tuning, and Redis internals with Sentinel high availability.