OLAP (On-Line Analytical Processing)

Context: FIT3003_MOC · the read path of the Data Warehouse — Chapter 19’s query families and the BI report each one feeds ➔ OLAP Cube and Rollup, OLAP Ranking and Top-N, OLAP Cumulative and Moving Aggregates, Power BI Parent Framework: Data Warehouse

Quick Revision

  • 🎯 Objective: OLAP = data processing by complex queries built on group by + aggregate operators ➔ pick the query family from the report’s shape (cross-tab, ranking, running total, drill-down).
  • ⚡ Key Constraint: OLAP retrieves, BI presents ➔ the query’s only job is to pull the right numbers out of the warehouse; formatting, percentages and charts belong to the BI reporting tool.

📝 Core

  • The chain ➔ Operational DB Data Warehouse OLAP Business Intelligence; OLAP exists because the warehouse must summarise very large record sets “on the fly”.
  • Chapter 19 schema ➔ every example runs on with TimeDim(TimeID, Month, Year), LocationDim(LocationID, Location), ProductDim(ProductID, ProductName); TimeID is the string 'YYYYMM'.
  • Drill down ➔ add one more dimension attribute to both select and group by: group by S.TimeID group by S.TimeID, ProductName splits each month’s bar into per-product stacks; remove it to roll back up.
  • Ratio report ➔ the SQL is a plain sum(Total_Sales) … group by Location; the share of total (Sydney ) is computed by the BI chart, never queried or stored.
  • Window functions run after group by ➔ ranking and cumulative clauses sit in the select list and take an aggregate as input ➔ hence rank() over (order by sum(Total_Sales)) and the nested sum(sum(Total_Sales)) over (…); they are illegal in the same query’s where.

⚖️ Core Decision Matrix

Report asks forClauseResult shapeChapter’s BI visual
a total per categorysum(…) group byone row per groupbar, or pie for a ratio
totals plus subtotals and grand totalgroup by cube / rollup ➔ OLAP Cube and Rollupdetail rows (null)-marked subtotal rowscross-tab table
top / bottom performersrank() over, Top-N inline view ➔ OLAP Ranking and Top-Nrank column beside each groupsorted bar
trend so far / smoothed trendrows unbounded preceding · rows n preceding ➔ OLAP Cumulative and Moving Aggregatesrunning column beside each periodbars per month line
the detail inside one totaldrill down: extra group by attributeone row per (period, product)stacked bar

When It Flips: a plain group by answers one level of detail; the moment the report needs two levels in one table (detail and its total) switch to cube/rollup, and the moment it needs a value relative to other rows (position, running sum) switch to a window function.

⚠️ Common Mistakes

  • 💡 Drilling down in select only ➔ adding ProductName beside sum(…) without adding it to group by raises ORA-00979.
  • 💡 Formatting inside the OLAP query ➔ to_char(…, '999,999,999') turns the measure into a string; fine for display, useless as input to a chart or a further aggregate.

🧠 Active Recall