Chapter 3 of 3

Data Warehousing and Online Analytical Processing

Data Warehouse: Basic Concepts

Data Warehouse

A data warehouse is a subject-oriented, integrated, time-variant, and non-volatile collection of data that supports management decision making.

  • Subject-oriented: Organized around major subjects (sales, customers, products) not transactions

  • Integrated: Data from multiple heterogeneous sources consolidated into a unified format

  • Time-variant: Stores historical data — every record has a time element

  • Non-volatile: Data is loaded and accessed, never updated or deleted in place

OLTP versus OLAP

The Fundamental Difference

The major distinction lies between Operational systems and Informational systems:

  • OLTP (Online Transaction Processing): Systems used for day-to-day operations (e.g., banking, retail checkout).

  • OLAP (Online Analytical Processing): Systems used for data analysis and decision making (e.g., trend analysis, sales forecasting).

diagram
Data Warehouse vs Operational Database
diagram
Example 80
  • OLTP Task: A customer buys a laptop. The database updates the stock count from 10 to 9 and records the payment. (High frequency, row-level access)

  • OLAP Task: A manager asks, "What were the sales trends for laptops in South India over the last 3 summers compared to the rainy season?" (Low frequency, massive data aggregation)

Example 81
  1. Step 1 (OLTP): You withdraw money from an ATM. This is a single, fast transaction that must be consistent (ACID).

  2. Step 2 (Data Flow): At the end of the day, your transaction data is moved to a central Warehouse.

  3. Step 3 (OLAP): The bank analyzes the "Withdrawal Patterns" of all customers in your city to decide if they need to install more ATMs in that area.

Data Warehousing: A Multitiered Architecture

Three-Tier Data Warehouse Architecture

The standard data warehouse architecture has three tiers:

  • Tier 1 — Bottom Tier: Data sources and data warehouse server (ETL layer)

  • Tier 2 — Middle Tier: OLAP server (multidimensional analysis engine)

  • Tier 3 — Top Tier: Front-end client tools (reporting, mining, visualization)

diagram
Tier 1 --- Bottom Tier (Data Warehouse Server)

The foundation layer responsible for data storage and ETL processing.

  • Data Sources: Operational databases, flat files, external feeds, legacy systems

  • ETL Engine: Extract, Transform, Load — the data integration pipeline

  • Data Warehouse Server: Central relational database storing integrated, historical data

  • Data Marts: Smaller, subject-specific subsets of the warehouse

  • Metadata Repository: Stores information about the data (schema, lineage, transformations)

diagram
ETL Extract Transform Load
  • Extract: Pull data from heterogeneous sources — OLTP databases, CSV files, APIs, web scraping

  • Transform: Apply data cleaning and integration rules:

    • Handle missing values and duplicates

    • Standardize formats: Date formats, unit conversion, encoding

    • Aggregate data to required granularity

    • Resolve conflicts: Different source systems may store same data differently

  • Load: Insert transformed data into the warehouse — full or incremental load

  • ETL runs on a periodic schedule (nightly, weekly) — not real-time

Example 82

Sources:

  • Store A database: Sales in USD, date format MM/DD/YYYY

  • Store B database: Sales in INR, date format DD-MM-YYYY

  • Online portal: JSON logs with Unix timestamps

Transform steps:

  • Convert all currencies to INR using exchange rates

  • Standardize all dates to YYYY-MM-DD format

  • Parse Unix timestamps to readable date-time

  • Remove duplicate transaction IDs

  • Fill missing product categories using product lookup table

Load: Nightly batch job inserts transformed records into the central warehouse.

Data Mart

A data mart is a smaller, subject-specific subset of a data warehouse.

  • Serves a specific business unit or department: Sales, Finance, HR, Marketing

  • Faster to build and query than the full warehouse

  • Two types:

    • Dependent data mart: Created from the central data warehouse (top-down)

    • Independent data mart: Built directly from source systems without a central warehouse

diagram
Metadata Repository

The metadata repository stores information about the data warehouse — it is the “data about data.”

  • Business metadata: Definitions, business rules, ownership

  • Technical metadata: Schema, data types, ETL mappings, transformations applied

  • Operational metadata: ETL job history, load timestamps, data quality logs

  • Enables data lineage: track where each piece of data came from and how it was transformed

  • Critical for auditing, debugging, and governance

Tier 2 --- Middle Tier (OLAP Server)

The analytical engine that processes multidimensional queries on warehoused data.
Three types of OLAP servers:

  • ROLAP (Relational OLAP): Implements multidimensional data on top of a relational database using SQL

  • MOLAP (Multidimensional OLAP): Stores data in a proprietary multidimensional array (data cube) directly

  • HOLAP (Hybrid OLAP): Combines ROLAP and MOLAP — detailed data in relational, aggregates in multidimensional

diagram
ROLAP vs MOLAP --- Detailed Comparison
diagram
Tier 3 --- Top Tier (Front-End Client Tools)

The user-facing layer — tools that query, visualize, and mine the data warehouse.

  • Reporting tools: Generate fixed-format reports for management (Crystal Reports, SSRS)

  • OLAP query tools: Ad-hoc multidimensional analysis (drill-down, slice, dice)

  • Data mining tools: Discover patterns, build predictive models

  • Dashboards: Real-time KPI visualization (Tableau, Power BI, Looker)

  • Statistical tools: In-depth statistical analysis (R, Python)

Example 83

Tier 1 — Data Sources and Warehouse Server:

  • Sources: Core banking system (Oracle DB), ATM logs (CSV), Mobile app (JSON API), Credit card system (MySQL)

  • ETL: Nightly batch — extract transactions, standardize currency, clean nulls, load into central warehouse

  • Warehouse: Stores 10 years of transaction history (Star Schema with Time, Branch, Product, Customer dimensions)

Tier 2 — OLAP Server:

  • MOLAP cube pre-aggregated for: monthly deposits by branch, loan defaults by region, product-wise revenue

  • Supports roll-up (branch $\rightarrow$ zone $\rightarrow$ region), drill-down, slice (product = home loan)

Tier 3 — Client Tools:

  • Executives: Power BI dashboard showing real-time KPIs

  • Risk analysts: Python-based data mining for default prediction

  • Compliance: Crystal Reports for audit reports (fixed format)

  • Branch managers: Ad-hoc OLAP queries for local performance analysis

Summary --- Three-Tier Architecture
diagram

Data Warehouse Modeling: Data Cube and OLAP

Data Cube: A Multidimensional Data Model

Multidimensional Data Model

A multidimensional data model views data as a data cube — a structure that organizes data by dimensions and stores measures at each intersection.

  • Designed for OLAP and data warehouse analysis

  • Replaces the flat 2D table view with an $n$-dimensional perspective

  • Each point in the cube represents an aggregated measure for a unique combination of dimension values

  • Enables efficient roll-up, drill-down, slice, and dice operations

Formal Definition of a Data Cube

An $n$-dimensional data cube is defined by: \[ \text{Cube} = (D_1,\ D_2,\ \ldots,\ D_n,\ M) \] where:

  • $D_i$ = $i$-th dimension with domain $\text{dom}(D_i)$

  • $M$ = measure function mapping each cell $(d_1, d_2, \ldots, d_n)$ to a numeric value

  • Total number of cells $= |\text{dom}(D_1)| \times |\text{dom}(D_2)| \times \cdots \times |\text{dom}(D_n)|$

  • Many cells may be empty (sparse) if not all combinations exist in the data

Core Components
  • Dimension: An attribute or perspective used to organize data
    Examples: Time, Location, Product

  • Dimension Hierarchy: Levels of abstraction within a dimension
    Time: Day $\rightarrow$ Month $\rightarrow$ Quarter $\rightarrow$ Year

  • Measure: A numeric value stored at each cell of the cube
    Examples: Sales, Profit, Count, Average Price

  • Cell: One point in the cube identified by a unique combination of dimension values
    Example: (Q1, Bengaluru, Electronics) $\rightarrow$ Sales = 120

  • Cuboid: One particular aggregation of the full cube across a subset of dimensions

Example 84

Dimensions and their domains:

diagram
  • Total cells $= 4 \times 3 \times 3 = 36$

  • Measure: Sales (lakhs) — one value per cell

  • If only 20 of 36 combinations have actual sales data $\rightarrow$ cube is sparse (44% empty)

diagram
diagram
Example 85

Q: A 3-dimensional data cube has Time(12), Location($x$), and Product(50) as dimensions. If the total number of cells is 36{,}000, what is the domain size of the Location dimension?

\[ \text{Total cells} = 12 \times x \times 50 = 36{,}000 \] \[ 600x = 36{,}000 \implies x = 60 \] Answer: The Location dimension has $\mathbf{60}$ distinct values (e.g., 60 cities).

Q: A 4-dimensional cube has equal domain size $d$ for all dimensions. If the total number of cells is 10{,}000, what is $d$? \[ d^4 = 10{,}000 \implies d = \sqrt[4]{10{,}000} = 10 \] Answer: Each dimension has $\mathbf{10}$ distinct values.

Cuboid and Cuboid Lattice

For an $n$-dimensional cube, there exist $2^n$ cuboids — each representing a different level of aggregation.

  • Base cuboid: All $n$ dimensions present — most detailed, lowest aggregation

  • Apex cuboid (0-D): All dimensions aggregated — single grand total value

  • Each cuboid corresponds to a GROUP BY query on a subset of dimensions

  • The set of all $2^n$ cuboids forms a cuboid lattice

\[ \text{Number of cuboids} = 2^n \]

diagram
Example 86

Each cuboid corresponds to a SQL GROUP BY query on a different subset of dimensions:

diagram
Cuboid Count by Level --- General Formula

For an $n$-dimensional cube, the number of cuboids at each level of the lattice is given by the binomial coefficient: \[ \text{Number of } k\text{-dimensional cuboids} = \binom{n}{k} = \frac{n!}{k!\,(n-k)!} \] The total across all levels: \[ \sum_{k=0}^{n} \binom{n}{k} = 2^n \] This follows directly from the Binomial Theorem: $\sum_{k=0}^{n}\binom{n}{k}1^k 1^{n-k} = 2^n$.

diagram
Example 87

Q: A data cube has 5 dimensions: Time, Location, Product, Customer, Channel.
How many cuboids does the full data cube contain?
\[ \text{Number of cuboids} = 2^5 = 32 \]

  • 1 apex cuboid (0-D)

  • $\binom{5}{1} = 5$ one-dimensional cuboids

  • $\binom{5}{2} = 10$ two-dimensional cuboids

  • $\binom{5}{3} = 10$ three-dimensional cuboids

  • $\binom{5}{4} = 5$ four-dimensional cuboids

  • $\binom{5}{5} = 1$ base cuboid (5-D)

  • Total: $1+5+10+10+5+1 = 32$    cuboids

Example 88

Given a Time dimension with the hierarchy: Day(365) $\to$ Month(12) $\to$ Quarter(4) $\to$ Year(1), and a Location dimension: City(50) $\to$ State(10) $\to$ Country(3) $\to$ ALL, combined with a Product dimension with a flat domain of 200 items, calculate the number of cells for each combination of hierarchy levels:

diagram
Example 89

A cube has 6 dimensions. How many 3-D cuboids exist? What is the total cuboid count? \[ \binom{6}{3} = \frac{6!}{3!\,3!} = 20 \quad \text{three-dimensional cuboids} \] \[ \text{Total cuboids} = 2^6 = 64 \]

Example 90

A cube has $n$ dimensions. The number of 2-D cuboids equals 21. Find $n$. \[ \binom{n}{2} = \frac{n(n-1)}{2} = 21 \implies n(n-1) = 42 \implies n = 7 \]

Example 91

How many cuboids does a 10-dimensional cube have? At which level is the number of cuboids maximised? \[ 2^{10} = 1024 \quad \text{total cuboids} \] The maximum occurs at $k = \lfloor n/2 \rfloor = 5$: \[ \binom{10}{5} = 252 \quad \text{(largest single-level count)} \]

Example 92

A data cube has Time(T), Product(P), Store(S), Promotion(Pr), and Customer(C) as dimensions ($n=5$). An analyst pre-materialises all cuboids involving at least Product and at most 3 dimensions total. How many cuboids satisfy this condition?

  • The only 1-D cuboid containing $P$ is $\{P\}=1$ .

  • Cuboids of size exactly 2 containing $P$: choose 1 more from $\{T,S,Pr,C\}$ $= \binom{4}{1} = 4$

  • Cuboids of size exactly 3 containing $P$: choose 2 more from $\{T,S,Pr,C\}$ $= \binom{4}{2} = 6$

  • Total: $1 + 4 + 6 = \mathbf{11}$ cuboids

Example 93

For an $n$-dimensional cube, prove that the number of cuboids containing a specific dimension $D_j$ is $2^{n-1}$.

  • Fix $D_j$ as present. The remaining $n-1$ dimensions can each independently be included or excluded.

  • This gives $2^{n-1}$ distinct combinations $\Rightarrow$ $2^{n-1}$ cuboids contain $D_j$.

  • Verification ($n=3$): Each dimension appears in $2^2 = 4$ cuboids. For $T$: $(T)$, $(T,L)$, $(T,P)$, $(T,L,P)$ — indeed 4. ✓

Concept

Each dimension with $L_i$ levels contributes $L_i + 1$ choices (including the “ALL” choice). Total cuboids $= \prod_i (L_i + 1)$.

Types of Data Cubes

Sparse Data Cube

In practice, most data cubes are sparse — many cells are empty.

  • Not all combinations of dimension values have corresponding data

  • Example: Not every product is sold in every city in every quarter

  • Density of a cube: \[ \text{Density} = \frac{\text{Number of non-empty cells}}{\text{Total possible cells}} \times 100\% \]

  • Storing all cells wastes memory — sparse representation techniques used

  • MOLAP stores the full array (wastes space for sparse cubes)

  • ROLAP stores only non-empty cells (efficient for sparse cubes)

Example 94

A 4-dimensional cube has dimensions:
Time (12 months), Location (50 cities), Product (200 items), Customer (1000 segments)
Total possible cells: \[ 12 \times 50 \times 200 \times 1000 = 1{,}200{,}000{,}000 \quad \text{(1.2 billion)} \] Actual non-empty cells: 3,000,000 (3 million)
\[ \text{Density} = \frac{3{,}000{,}000}{1{,}200{,}000{,}000} \times 100\% = 0.25\% \] The cube is 99.75% sparse — ROLAP is preferred; MOLAP would waste enormous memory.

Iceberg Cube

An iceberg cube computes and stores only those cuboid cells whose aggregate value satisfies a minimum threshold. \[ \text{Store cell } (d_1, d_2, \ldots, d_k) \text{ only if } \text{measure}(d_1,\ldots,d_k) \geq \text{min\_sup} \]

  • Avoids materializing cells with very low counts — reduces storage dramatically

  • Named after the iceberg metaphor — only the tip (significant cells) is visible

  • Threshold called minimum support (often count $\geq$ some value)

  • Useful for association rule mining on large sparse cubes

diagram
Example 95

Sales cube with 36 cells (4 quarters $\times$ 3 locations $\times$ 3 products).
min_sup = 100 lakhs (store only cells where Sales $\geq$ 100).

diagram

Only cells meeting the threshold are materialized — the rest are pruned.

Example 96

A 3-D cube has Time(4), Location(3), Product(3) with 22 non-empty cells. \[ \text{Total cells} = 4 \times 3 \times 3 = 36, \qquad \text{Density} = \frac{22}{36} \times 100\% \approx 61.1\% \] Moderately dense; either storage approach is viable.

Example 97

A 4-D retail cube has Month(12), Store(500), SKU(10{,}000), Channel(5) with 2{,}000{,}000 actual sales records. \[ \text{Total cells} = 12 \times 500 \times 10{,}000 \times 5 = 300{,}000{,}000 \] \[ \text{Density} = \frac{2{,}000{,}000}{300{,}000{,}000} \times 100\% \approx 0.67\% \] Extremely sparse (99.33% empty) — ROLAP is strongly preferred.

Example 98

A cube has density 2% and $5 \times 10^8$ total cells. How many cells are non-empty? \[ N = 0.02 \times 5 \times 10^8 = 10{,}000{,}000 \quad \text{(10 million non-empty cells)} \]

Example 99

(MOLAP vs.\ ROLAP storage): For Problem 2 above, with $b = 8$ bytes/cell in MOLAP, and in ROLAP each record has 4 dimension keys (4 bytes each) + 1 measure (8 bytes): \[ \text{MOLAP} = 300{,}000{,}000 \times 8 = 2{,}400{,}000{,}000 \text{ bytes} \approx 2.4 \text{ GB} \] \[ \text{ROLAP} = 2{,}000{,}000 \times (4 \times 4 + 8) = 2{,}000{,}000 \times 24 = 48{,}000{,}000 \text{ bytes} \approx 48 \text{ MB} \] \[ \text{Space saving} = \frac{2400 - 48}{2400} \times 100\% = 98\% \]

Example 100

(Find density from storage constraint): A 3-D cube has 1 billion total cells. MOLAP requires 8 GB (8 bytes/cell). At what minimum density does ROLAP require more storage than MOLAP? (ROLAP record size = 20 bytes: 3 $\times$ 4-byte keys + 8-byte measure.) \[ N \times 20 = 10^9 \times 8 \implies N = \frac{8 \times 10^9}{20} = 4 \times 10^8 \] \[ \text{Break-even density} = \frac{4 \times 10^8}{10^9} \times 100\% = 40\% \] At density $> 40\%$, MOLAP is more storage-efficient; below 40%, ROLAP wins.

Closed Cube --- Formal Definition

A cuboid cell $(d_1, d_2, \ldots, d_k)$ with measure value $v$ is closed if and only if there is no more specific cell (with additional dimension constraints) that has the same measure value: \[ \nexists\; (d_1,\ldots,d_k, d_{k+1}): \quad \text{measure}(d_1,\ldots,d_k,d_{k+1}) = v \] The closed cube stores only the closed cells, eliminating redundancy while preserving the ability to reconstruct all other cells by roll-up.

  • If $\text{measure}(d_1,\ldots,d_k) = \text{measure}(d_1,\ldots,d_k,d_{k+1})$ for every value of $d_{k+1}$, then the coarser cell is redundant (the finer cell already captures the same information)

  • Closed cube $\subseteq$ Iceberg cube $\subseteq$ Full cube

  • Used primarily with COUNT; a cell is not closed if all its refinements have the same count (i.e., adding a dimension doesn't split the group)

Example 101

Consider a 2-D cube with dimensions: Location $\in \{North, South\}$ and Customer $\in \{Retail, Wholesale\}$. The base cuboid (2-D) has the following COUNT values:

diagram

Checking closedness of (North) in the 1-D (Location) cuboid:
The cell $(North)$ has count = 15. Its refinements in the 2-D cuboid are: $(North, Retail) = 15$ and $(North, Wholesale) = 0$.
Since the refinement $(North, Retail)$ has the same count (15) as its parent $(North)$, the cell $(North)$ is not closed — adding the Customer dimension does not change the count.

Checking closedness of (Wholesale) in the 1-D (Customer) cuboid:
The cell $(Wholesale)$ has count = 25. Its refinements in the 2-D cuboid are: $(North, Wholesale) = 0$ and $(South, Wholesale) = 25$.
Since the refinement $(South, Wholesale)$ has the same count (25) as its parent $(Wholesale)$, the cell $(Wholesale)$ is not closed.

Case of a closed cell:
Checking $(South)$ in the 1-D (Location) cuboid: $(South)$ has count = 35. Its refinements are $(South, Retail) = 10$ and $(South, Wholesale) = 25$. Since neither refinement equals 35, the cell $(South)$ is closed.

Summary: Non-closed cells (like North and Wholesale in this table) are redundant. In a Closed Cube representation, we prune these and only store cells where every refinement results in a different count value, effectively compressing the data without losing information.

Example 102

Consider a small 2-D cube: Time $\in \{Q1, Q2\}$, Product $\in \{Electronics, Clothing\}$. The base cuboid (2-D) has the following COUNT values:

diagram

Checking closedness of (Q1) in the 1-D (Time) cuboid:
$(Q1)$ has count = 10. Its refinements in the 2-D cuboid are: $(Q1, \text{Electronics}) = 5$ and $(Q1, \text{Clothing}) = 5$.
Since $5 \neq 10$, the cell $(Q1)$ is closed — adding the Product dimension changes the count.

Checking closedness of (Electronics) in the 1-D (Product) cuboid:
$(Electronics)$ has count = 13. Its refinements: $(Q1, Electronics) = 5$, $(Q2, Electronics) = 8$.
Since $5 \neq 13$ and $8 \neq 13$, $(Electronics)$ is closed.

Hypothetical non-closed case:
If all sales of Clothing occurred only in Q2 and there were no other data, then: $(Q2, Clothing) = $ all Clothing sales, and the (Clothing) cuboid cell would equal $(Q2, Clothing)$ — making (Clothing) not closed (redundant with its 2-D refinement).

Summary: In the example above, all cells happen to be closed. Non-closed cells arise when the same count value is shared by a cell and one of its direct 1-step refinements — signalling that the refinement adds no information.

Schemas for Multidimensional Data Models

Schema for Multidimensional Data Model

A schema in a data warehouse defines how fact tables and dimension tables are organized and related.

  • Fact table: Central table storing measures (numeric, quantitative data) and foreign keys to dimension tables

  • Dimension table: Stores descriptive attributes of a dimension — the context for analysis

  • Three standard schemas: Star, Snowflake, Fact Constellation (Galaxy)

Fact Table vs Dimension Table
diagram
diagram
Star Schema

A star schema has a single central fact table connected to multiple denormalized dimension tables — resembling a star shape.

  • Dimension tables are flat — all attributes in one table, not further decomposed

  • Simple structure — fewer joins required for queries

  • Fast query performance — optimized for OLAP

  • Data redundancy in dimension tables (denormalized)

  • Most widely used schema in data warehouses

Star Schema Structure
  • Fact table: Contains measures and foreign keys to all dimension tables
    Primary key = composite of all foreign keys

  • Dimension tables: One per dimension; contain all attributes of that dimension in a single flat table

  • Number of joins in a query = number of dimensions involved

  • Denormalization: Dimension attributes are stored redundantly to avoid joins

diagram
Example 103

Query: Total sales per product category per quarter for 2024.
SQL on Star Schema:

SELECT  T.quarter, P.category, SUM(F.sales_amount)
FROM    Sales_Fact F
JOIN    Time_Dim T     ON F.time_id     = T.time_id
JOIN    Product_Dim P  ON F.product_id  = P.product_id
WHERE   T.year = 2024
GROUP BY T.quarter, P.category;
  • Only 2 joins needed (Time and Product) — Location and Customer not touched

  • All product attributes (name, brand, category) are in one flat table — no further joins

  • Fast execution — typical OLAP query pattern

Example 104

Product_Dim stores category alongside individual product:

diagram
  • “Electronics” is stored twice — redundancy due to denormalization

  • In a normalized schema, category would be in a separate table

  • Star schema accepts this redundancy to avoid extra joins at query time

Snowflake Schema

A snowflake schema is a normalized extension of the star schema where dimension tables are further decomposed into multiple related tables.

  • Dimension tables are normalized — no redundancy

  • Resembles a snowflake shape — dimensions branch out into sub-dimensions

  • Reduces storage — eliminates redundant attribute values

  • More joins required for queries — slower than star schema

  • Better for frequent dimension updates (normalized tables easier to maintain)

Star Schema vs Snowflake Schema
diagram
diagram
Example 105

Query: Total sales per department per year.
SQL on Snowflake Schema:

SELECT  Q.year, C.department, SUM(F.sales_amount)
FROM    Sales_Fact F
JOIN    Product_Dim P   ON F.product_id  = P.product_id
JOIN    Category_Dim C  ON P.category_id = C.category_id
JOIN    Time_Dim T      ON F.time_id     = T.time_id
JOIN    Quarter_Dim Q   ON T.quarter_id  = Q.quarter_id
GROUP BY Q.year, C.department;
  • 5 joins required — compared to 2 joins in equivalent star schema query

  • department is not in Product_Dim directly — must traverse Category_Dim

  • year is not in Time_Dim directly — must traverse Quarter_Dim

  • Snowflake pays for normalization with extra join overhead

Example 106

Star Schema — Product_Dim (denormalized):

diagram

“Electronics” and “Technology” repeated 3 times.
Snowflake Schema — normalized into two tables:
Product_Dim:

diagram

Category_Dim:

diagram

“Electronics” and “Technology” stored once only — no redundancy.

Fact Constellation Schema (Galaxy Schema)

A fact constellation (also called galaxy schema) contains multiple fact tables that share dimension tables.

  • Models complex real-world scenarios where multiple subjects need analysis

  • Shared dimension tables — consistency across fact tables

  • Each fact table can have different measures and different grains

  • Most flexible but most complex schema to design and maintain

  • Looks like a collection of stars — hence “galaxy” schema

diagram
Example 107

A retail company needs to analyze both Sales and Inventory:

diagram
  • Cross-fact query: “Which products have high sales but low inventory?” — requires joining both fact tables via shared Product_Dim

  • Shared dimension ensures consistent product definitions across both facts

Example 108

Q: A data warehouse has the following tables:
Sales_Fact, Time_Dim, Customer_Dim, Product_Dim, Category_Dim
Product_Dim has a foreign key to Category_Dim.
What schema does this represent?

  • One fact table (Sales_Fact) $\rightarrow$ not Fact Constellation

  • Product_Dim connects to Category_Dim — dimension table is normalized

  • This is a Snowflake Schema — dimension hierarchy is normalized out into sub-dimensions

Answer: Snowflake Schema
If Category_Dim were merged into Product_Dim (no sub-table), it would be a Star Schema.

Example 109

Q: A star schema has a fact table Orders_Fact with foreign keys:
customer_id, product_id, time_id, store_id
What is the primary key of Orders_Fact?

  • No single attribute uniquely identifies a row in a fact table

  • Primary key = composite key of all foreign keys:
    PK = (customer_id, product_id, time_id, store_id)

  • This assumes one fact per unique combination of all dimensions

  • If multiple orders can exist for the same combination, a surrogate key (order_id) is added

Summary --- Three Schema Types
diagram

Concept Hierarchy

Concept Hierarchy

A concept hierarchy defines a sequence of mappings from a set of low-level concepts to higher-level, more general concepts.

  • Organizes nominal attribute values into levels of abstraction

  • Enables roll-up and drill-down operations in data cubes

  • Allows mining at multiple levels of granularity

  • Example: City $\rightarrow$ State $\rightarrow$ Country $\rightarrow$ Continent

Why Concept Hierarchies for Nominal Data?
  • Nominal attributes have many distinct values at fine levels (e.g., thousands of cities)

  • Patterns at fine level are too sparse to be statistically meaningful

  • Rolling up to higher levels groups values, increasing support for patterns

  • Enables generalization: specific value $\rightarrow$ broader category

  • Reduces cardinality: fewer distinct values $\rightarrow$ faster mining

diagram
Methods for Generating Concept Hierarchies for Nominal Data

Four main approaches:

  • Method 1: Specified explicitly by a user or domain expert

  • Method 2: Specified by the order of attributes (schema hierarchy)

  • Method 3: Automatically generated by number of distinct values

  • Method 4: Specified by explicit grouping of values

Method 1 --- Explicitly Specified by User/Expert

A domain expert manually defines the hierarchy levels and mappings.

  • Most accurate — captures domain knowledge

  • Time-consuming and requires expert involvement

  • Stored as metadata in the data warehouse schema

  • Example: A retail expert defines product hierarchy:
    Item $\rightarrow$ Brand $\rightarrow$ Category $\rightarrow$ Department

Example 110

A retail database stores individual products. An expert defines:

diagram

Roll-up from Item to Category: instead of analyzing 10,000 SKUs, analyst sees 5 categories.

Method 2 --- Specified by Order of Attributes (Schema Hierarchy)

The hierarchy is implied by the order of attributes listed in the database schema.

  • User specifies: street $<$ city $<$ state $<$ country

  • System automatically infers the hierarchy from this order

  • A total ordering of attributes defines the levels

  • Simple to implement — no explicit value-to-value mapping needed

  • The attribute with fewer distinct values is at a higher level

Schema Hierarchy Rule

If a user specifies the partial order:
day $<$ month $<$ quarter $<$ year
Then the system knows:

  • day is the most specific level (many distinct values)

  • year is the most general level (few distinct values)

  • Rolling up moves left to right in the ordering

  • Drilling down moves right to left

Example 111

Database table Customer has attributes:
Street, City, District, State, Country
User specifies order: Street $<$ City $<$ District $<$ State $<$ Country

diagram

Fewer distinct values $\rightarrow$ higher in hierarchy.
Mining at City level instead of Street reduces cardinality from 50,000 to 500.

Method 3 --- Automatic Generation by Number of Distinct Values

System automatically generates the hierarchy by sorting attributes on the number of distinct values:

  • Attribute with the most distinct values $\rightarrow$ lowest level (most specific)

  • Attribute with the fewest distinct values $\rightarrow$ highest level (most general)

  • No user specification of order needed

  • Works well when attributes have a natural parent-child relationship

  • May produce incorrect hierarchies if attributes are unrelated

diagram
Example 112

A data warehouse has the following attributes and their distinct value counts:

diagram
  • System automatically orders: ProductID $<$ ProductName $<$ SubCategory $<$ Category $<$ Department

  • No user input needed — purely driven by cardinality

  • Risk: ProductID and ProductName may not have a true parent-child relationship

Method 4 --- Explicit Value Grouping

User manually groups specific values of an attribute into higher-level concepts.

  • Most flexible — handles arbitrary, non-geographic groupings

  • Example: Group countries by economic classification:
    {India, China, Brazil} $\rightarrow$ Developing
    {USA, UK, Germany} $\rightarrow$ Developed

  • Requires domain knowledge — groups may not be derivable from data alone

  • Stored as a mapping table in the data warehouse

Example 113

Attribute: JobRole with many values. User defines groupings:

diagram

Mining at Department level: “Analytics department has highest project completion rate” — a pattern invisible at the JobRole level due to data sparsity.

Example 114

Attribute: Grade $\in$ {A+, A, A–, B+, B, B–, C+, C, D, F}
User defines grouping:

diagram

Roll-up from 10 grade values to 4 performance bands — meaningful for policy decisions.
Pattern: “80% of scholarship holders are in Distinction” is clear at rolled-up level.

Multi-Level Concept Hierarchy --- Combined Example

A Location attribute supports a 4-level hierarchy:

diagram
Concept Hierarchy vs Discretization --- Key Difference
diagram

Measures: Categorization and Computation

Measure Classification

A measure is a numeric function defined over the cells of a data cube. Measures are classified by how they behave under aggregation across cuboids:

  • Distributive — computable from sub-aggregate results alone.

  • Algebraic — computable from a fixed finite set of distributive sub-aggregates.

  • Holistic — require the entire partition; no bounded sub-aggregate suffices.

This classification directly determines how efficiently a measure can be pre-computed and maintained in a data cube or OLAP system.

Measures in a Data Cube

Measures are classified by how they behave during aggregation:

  • Distributive: Can be computed from sub-aggregates
    $\text{agg}(S) = f(\text{agg}(S_1), \text{agg}(S_2), \ldots)$
    Examples: SUM, COUNT, MIN, MAX

  • Algebraic: Computed from a fixed number of distributive aggregates
    Examples: AVG (= SUM / COUNT), Standard Deviation

  • Holistic: Cannot be computed from sub-aggregates — require the full set
    Examples: MEDIAN, MODE, RANK

Summary of Measures in a Data Cube
diagram
diagram
Example 115

Consider partitioned sales data split by region:
Region A: {10, 20, 30}    Region B: {40, 50, 60}
SUM (Distributive): \[ \text{SUM(A)} = 60, \quad \text{SUM(B)} = 150, \quad \text{SUM(All)} = 60 + 150 = 210 \quad \text{(computable from sub-aggregates)} \] AVG (Algebraic): \[ \text{AVG(A)} = 20, \quad \text{AVG(B)} = 50 \] \[ \text{AVG(All)} \neq \frac{20+50}{2} = 35 \quad \text{(wrong!)} \] \[ \text{AVG(All)} = \frac{\text{SUM(All)}}{\text{COUNT(All)}} = \frac{210}{6} = 35 \quad \text{(correct — needs both SUM and COUNT)} \] MEDIAN (Holistic): \[ \text{MEDIAN(A)} = 20, \quad \text{MEDIAN(B)} = 50 \] \[ \text{MEDIAN(All)} = \text{MEDIAN}(\{10,20,30,40,50,60\}) = \frac{30+40}{2} = 35 \] Cannot compute this from MEDIAN(A) and MEDIAN(B) alone — requires the full sorted list.

Example 116

Three branch offices report quarterly sales:

diagram

Incorrect global AVG: \[ \text{AVG}_{\text{wrong}} = \frac{30 + 10 + 30}{3} = \frac{70}{3} \approx 23.33 \quad \text{\ding{55}} \]

Correct global AVG (algebraic combination): \[ \text{AVG}_{\text{correct}} = \frac{240 + 150 + 360}{8 + 15 + 12} = \frac{750}{35} \approx 21.43 \quad \checkmark \]

Conclusion: Simply averaging the branch averages ignores differing counts. The correct approach requires carrying both SUM and COUNT as sub-aggregates — confirming AVG is algebraic, not distributive.

════════════════════════════════════════════╗

Typical OLAP Operations

OLAP Operations

OLAP (Online Analytical Processing) operations allow analysts to navigate and explore data cubes at different levels of abstraction and from different perspectives.

  • Operate on multidimensional data cubes

  • Each operation produces a new view of the data

  • Five fundamental operations: Roll-up, Drill-down, Slice, Dice, Pivot

  • Supported by data warehouses for fast decision support queries

diagram
Running Example --- Sales Data Cube

All five operations are demonstrated on the following base data cube:
Dimensions: Time (Quarter), Location (City), Product (Category)
Measure: Sales (in lakhs)

diagram
Roll-up (Drill-up)

Roll-up aggregates data by climbing up a concept hierarchy or by reducing a dimension.

  • Moving to a higher, more general level of abstraction

  • Applies an aggregate function (SUM, AVG, COUNT) across the rolled-up level

  • Two ways to roll up:

    • Along a hierarchy: Day $\rightarrow$ Month $\rightarrow$ Quarter $\rightarrow$ Year

    • By dimension reduction: Remove a dimension entirely

  • Result has fewer rows and fewer details

diagram
Example 117

Roll up Time from Quarter to Year — aggregate Sales by SUM.

diagram

16 rows $\rightarrow$ 4 rows. Detail lost; annual trends visible.

Example 118

Roll up Location from City to State:
Bengaluru and Mumbai both belong to different states (Karnataka, Maharashtra).

diagram

If both cities belonged to the same state, their sales would be summed into one row per state.

Example 119

Remove Product dimension entirely — sum across all products:

diagram

Product breakdown lost — now shows total sales per city per quarter.

Drill-down

Drill-down is the reverse of roll-up — navigates from summarized data to more detailed data.

  • Moves down a concept hierarchy to a lower, more specific level

  • Or adds a new dimension to the current view

  • Result has more rows and finer detail

  • Used when a summary shows an interesting pattern that warrants deeper investigation

diagram
Example 120

Starting from the rolled-up annual view, drill down Time back to Quarter:

diagram

Insight: Mumbai's Q4 sales (300) are consistently highest — visible only after drilling down.

Example 121

Starting from a 2-dimension view (Time, Location), add Product dimension:

diagram

Mumbai Q4 total was 300 — drilling into Product reveals Electronics (190) dominates Clothing (110).

Slice

Slice selects a single value for one dimension, reducing the cube by one dimension.

  • Fixes exactly one dimension to a single specific value

  • Result is a 2D table (if original was 3D cube)

  • Equivalent to a WHERE clause on one dimension in SQL

  • Does not aggregate — all remaining rows at the same granularity are retained

diagram
Example 122

Fix Product = Electronics — remove Product dimension:

diagram

Equivalent SQL:

SELECT Time, Location, SUM(Sales)
FROM SalesCube
WHERE Product = 'Electronics'
GROUP BY Time, Location;
Example 123

Fix Time = Q1 — analyze only first quarter performance:

diagram

3D cube (Time $\times$ Location $\times$ Product) $\rightarrow$ 2D table (Location $\times$ Product) for Q1 only.

Dice

Dice selects a range of values for two or more dimensions, extracting a sub-cube.

  • Fixes a subset of values (not just one) on multiple dimensions

  • Result is a smaller cube — same number of dimensions, fewer values per dimension

  • Equivalent to a WHERE clause on multiple dimensions in SQL

  • Key difference from Slice: Dice retains dimensionality; Slice reduces it by one

diagram
Example 124

Select sub-cube where Time is Q1 or Q2 and Location is Mumbai:

diagram

16 rows $\rightarrow$ 4 rows. Still a 3D sub-cube (Time $\times$ Location $\times$ Product).
Equivalent SQL:

SELECT Time, Location, Product, Sales
FROM SalesCube
WHERE Time IN ('Q1','Q2') AND Location = 'Mumbai';
Example 125

Three dimensions constrained:

diagram

This is the smallest meaningful sub-cube — 2 rows remain, all 3 dimensions still present.

Slice vs Dice --- Key Distinction
diagram
Pivot (Rotate)

Pivot rotates the data cube to present an alternative view by reorienting dimensions.

  • Does not change the data — only changes the presentation axis

  • Swaps rows and columns in a 2D cross-tabulation

  • Makes different relationships more visible

  • Also called rotate in some systems

  • Familiar as Pivot Table in Excel/spreadsheet tools

diagram
Example 126

Before Pivot — rows indexed by Location, columns by Time:

diagram

After Pivot — rows indexed by Time, columns by Location:

diagram

Same data — different perspective. Quarterly growth trend per city is now easier to read.

Example 127

Before Pivot (after Slice: Location = Bengaluru):

diagram

After Pivot:

diagram

Comparing Electronics vs Clothing across quarters is now immediate from a single row.

Summary --- All Five OLAP Operations
diagram