Data Ware House Concept 2019 (Compatibility Mode) PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

What is Data Warehouse?

• Defined in many different ways, but not rigorously.


– A decision support database that is maintained
separately from the organization’s operational
database
– Support information processing by providing a solid
platform of consolidated, historical data for analysis.
• “A data warehouse is a subject-oriented, integrated,
time-variant, and nonvolatile collection of data in support
of management’s decision-making process.”—W. H.
Inmon
• Data warehousing:
– The process of constructing and using data
warehouses

1
Data Warehouse—Subject-
Oriented
• Organized around major subjects, such as customer,
product, sales.
• Focusing on the modeling and analysis of data for
decision makers, not on daily operations or transaction
processing.
• Provide a simple and concise view around particular
subject issues by excluding data that are not useful in the
decision support process.

Data Warehouse—Integrated
• Constructed by integrating multiple, heterogeneous
data sources
– relational databases, flat files, on-line transaction
records
• Data cleaning and data integration techniques are
applied.
– Ensure consistency in naming conventions,
encoding structures among different data sources
– When data is moved to the warehouse, it is
converted.

2
Data Warehouse—Time Variant

• The time horizon for the data warehouse is significantly


longer than that of operational systems.
– Operational database: current value data.
– Data warehouse data: provide information from a
historical perspective (e.g., past 5-10 years)
• Every key structure in the data warehouse
– Contains an element of time, explicitly or implicitly

3
Data Warehouse—Non-Volatile

• A physically separate store of data transformed from the


operational environment.
• In the data warehouse environment.
– Does not require transaction processing, recovery,
and concurrency control mechanisms
– Requires only two operations in data accessing:
• initial loading of data and access of data.

4
Data Warehouse vs. Operational DBMS

• OLTP (on-line transaction processing)


– Major task of traditional relational DBMS
– Day-to-day operations: purchasing, inventory,
banking, manufacturing, payroll, registration,
accounting, etc.
• OLAP (on-line analytical processing)
– Major task of data warehouse system
– Data analysis and decision making

5
OLTP vs. OLAP
OLTP OLAP
users clerk, IT professional knowledge worker
function day to day operations decision support
DB design application-oriented subject-oriented
data current, up-to-date historical,
detailed, flat relational summarized, multidimensional
isolated integrated, consolidated
usage repetitive ad-hoc
access read/write lots of scans
index/hash on prim. key
unit of work short, simple transaction complex query
# records accessed tens millions
#users thousands hundreds
DB size 100MB-GB 100GB-TB
metric transaction throughput query throughput, response

6
Why Separate Data
Warehouse?
• High performance for both systems
– DBMS— tuned for OLTP: access methods, indexing,
concurrency control, recovery
– Warehouse—tuned for OLAP: complex OLAP queries,
multidimensional view, consolidation.
• Different functions and different data:
– missing data: Decision support requires historical data
which operational DBs do not typically maintain
– data consolidation: DS requires consolidation
(aggregation, summarization) of data from
heterogeneous sources
– data quality: different sources typically use inconsistent
data representations, codes and formats which have to
be reconciled

Aggregation in SQL

Select store, sum(sales) from my_data group by Store


having count(*) > 1 and sum(sales) > 300

7
Aggregation in SQL

1-D resultant cube


store sum_sales sanchi 400
sanchi 400

Aggregation

Aggregation in SQL
• A data cube, such as sales, allow data to
be modified in multiple dimension
• Dimension table:
• Item, time, location
• Fact table:
• Contain measure (Rs_sold) and key of each
dimension table.

8
Aggregates
• Add up amounts by day
• In SQL: SELECT date, sum(amt) FROM SALE
GROUP BY date

sale prodId storeId date am t


p1 c1 1 12
p2 c1 1 11 ans date sum
p1 c3 1 50 1 81
p2 c2 1 8 2 48
p1 c1 2 44
p1 c2 2 4

Multidimensional View
BPL
IND
RAI
BIL

Q1 605 825 14 400


Time(quarter)

Q2

Q3

Q4

H C P S
Items

9
Data Cube: A Lattice of
Cuboids
all
0-D(apex) cuboid

time item location supplier


1-D cuboids

time,location item,location location,supplier


2-D cuboids
time,item time,supplier item,supplier

time,location,supplier
3-D cuboids
time,item,locationtime,item,supplier item,location,supplier

4-D(base) cuboid

time, item, location, supplier


19
19

Data Cube: A Lattice of Cuboids


all
0-D(apex) cuboid
time item location supplier
1-D cuboids
time,item time,location item,location location,supplier
time,supplier item,supplier 2-D cuboids
time,location,supplier

time,item,location item,location,supplier
3-D cuboids
time,item,supplier

time, item, location, supplier 4-D(base) cuboid

• Base vs. aggregate cells; ancestor vs. descendant cells; parent vs. child cells
1. (9/15, milk, Urbana, Dairy_land)
2. (9/15, milk, Urbana, *)
3. (*, milk, Urbana, *)
4. (*, milk, Urbana, *)
5. (*, milk, Chicago, *)
6. (*, milk, *, *) 20

10
Aggregates
• Operators: sum, count, max, min,
median, avg
• “Having” clause
• Using dimension hierarchy
– average by region (within store)
– maximum by month (within date)

Multiple Simultaneous
Aggregates
4 Group-bys here:
(store,product)
Cross-Tabulation (products/store) (store)
(product)
Product ()
Sales
1 2 3 4 ALL
1 454 - - 925 1379
2 468 800 - - 1268
Sub-totals per store
Store

3 296 - 240 - 536


4 652 - 540 745 1937
ALL 1870 800 780 1670 5120

Total sales
Sub-totals per product

11
Cube Operators
c1 c2 c3
day 2 ...
p1 44 4
p2 c1 c2 c3
day 1
p1 12 50
p2 11 8 sale(c1,*,*)

c1 c2 c3
sum 67 12 50
c1 c2 c3
p1 56 4 50
p2 11 8 129
sum
sale(c2,p2,*) p1 110
p2 19 sale(*,*,*)

Cube Aggregation
Example: computing sums
c1 c2 c3
day 2 ...
p1 44 4
p2 c1 c2 c3
day 1
p1 12 50
p2 11 8

c1 c2 c3
sum 67 12 50
c1 c2 c3
p1 56 4 50
p2 11 8 129
sum
rollup p1 110
p2 19
drill-down

12
Cube Aggregates Lattice
129 Apex cuboid
all

c1 c2 c3
p1 67 12 50
city product date

city, product city, date product, date


c1 c2 c3
p1 56 4 50
p2 11 8

day 2
p1
c1
44
c2
4
c3
city, product, date
p2 c1 c2 c3
day 1
p1 12 50
p2 11 8
Base cuboid

Cube Aggregates Lattice


• Base cuboid
– The cuboid that hold the lowest level of
summarization.
• Apex cuboid
– Which hold the highest level of
summarization.
Summarization overall three dimension

13
Cube

Fact table view: Multi-dimensional cube:


sale prodId storeId amt
p1 c1 12 c1 c2 c3
p2 c1 11 p1 12 50
p1 c3 50 p2 11 8
p2 c2 8

dimensions = 2

3-D Cube
Fact table view: Multi-dimensional cube:
sale prodId storeId date amt
p1 c1 1 12
p2 c1 1 11 c1 c2 c3
day 2
p1 c3 1 50 p1 44 4
p2 c2 1 8 p2 c1 c2 c3
p1 c1 2 44 day 1
p1 12 50
p1 c2 2 4 p2 11 8

dimensions = 3

14
Aggregates
• Add up amounts for day 1
• In SQL: SELECT sum(amt) FROM SALE
WHERE date = 1

sale prodId storeId date am t


p1 c1 1 12
p2 c1 1 11
p1 c3 1 50
p2 c2 1 8
81
p1 c1 2 44
p1 c2 2 4

Aggregates
• Add up amounts by day
• In SQL: SELECT date, sum(amt) FROM SALE
GROUP BY date

sale prodId storeId date am t


p1 c1 1 12
p2 c1 1 11 ans date sum
p1 c3 1 50 1 81
p2 c2 1 8 2 48
p1 c1 2 44
p1 c2 2 4

15
Another Example
• Add up amounts by day, product
• In SQL: SELECT date, sum(amt) FROM SALE
GROUP BY date, prodId
sale prodId storeId date am t
p1 c1 1 12 sale prodId date amt
p2 c1 1 11
p1 1 62
p1 c3 1 50
p2 1 19
p2 c2 1 8
p1 c1 2 44 p1 2 48
p1 c2 2 4

n-dimensional data cube

How many cuboids are there in an n-dimensional data cube

If there were no hierarchies associated with each


dimension, then the total number of cuboids for an n-
dimensional data cube is 2n.

However, in practice, many dimensions do have


hierarchies. For example, the dimension time is usually not
just one level, such as year, but rather a hierarchy or a
lattice, such as day < week < month < quarter < year. For
an n-dimensional

16
n-dimensional data cube

Data cube, the total number of cuboids that can be is:

n
T= ¶ (Li + 1);
i=1
where Li is the number of levels associated with dimension

n-dimensional data cube

This formula is based on the fact that at most one


abstraction level in each dimension will appear in a cuboid.

For example, if the cube has 10 dimensions and each


dimension has 4 levels, the total number of cuboids that
can be generated will be 510
Suppose we define a data cube with three dimensions: place, age, and
salary.

The dimension hierarchies used are “city < state < region” for place,
“age_value < age_category [20-30, 30-40, 40-50}” for age and
“salary_value < salary_class [50-60K, 60-65K, 65-70K]” for salary.
What is the total number of cuboids possible from this data cube?

17
What to Materialize?
• Store in warehouse results useful for
common queries
• Example: total sales
c1 c2 c3
day 2 ...
p1 44 4
p2 c1 c2 c3
day 1
p1 12 50
p2 11 8

c1 c2 c3
p1 67 12 50
c1 c2 c3
p1 56 4 50
p2 11 8 129
c1
materialize p1 110
p2 19

Materialized Views
• Define new warehouse relations using
SQL expressions
sale prodId storeId date am t product id name price
p1 c1 1 12 p1 bolt 10
p2 c1 1 11 p2 nut 5
p1 c3 1 50
p2 c2 1 8
p1 c1 2 44
p1 c2 2 4

joinTb prodId name price storeId date amt


p1 bolt 10 c1 1 12
p2 nut 5 c1 1 11 does not exist
p1 bolt 10 c3 1 50 at any source
p2 nut 5 c2 1 8
p1 bolt 10 c1 2 44
p1 bolt 10 c2 2 4

18
Measures: Three
Categories
• distributive: if the result derived by applying the function to
n aggregate values is the same as that derived by
applying the function on all the data without partitioning.
• E.g., count(), sum(), min(), max().
• algebraic: if it can be computed by an algebraic function
with M arguments (where M is a bounded integer), each
of which is obtained by applying a distributive aggregate
function.
• E.g., avg(), standard_deviation().

Measures: Three
Categories
• holistic: if there is no constant bound on the storage size
needed to describe a sub-aggregate.
• Holistic measure is a measure that must be computed on
entire data set as whole. It can not be computed by
partitioning the give data set into subset and merging the
values obtained for the major in each subset
• E.g., median(), mode(), rank().

19
DATA CUBE OF WEB LOG

Total Byte Transfer


Date Syllabus page
1Qtr 2Qtr 3Qtr 4Qtr sum
IE 5.0
Netscape Navigator. Syllabus
Fire Fox
Time Table

Pages
Result

Total Visit

Conceptual Modeling of Data


Warehouses
• Modeling data warehouses: dimensions & measures
– Star schema: A fact table in the middle connected
to a set of dimension tables
– Snowflake schema: A refinement of star schema
where some dimensional hierarchy is normalized
into a set of smaller dimension tables, forming a
shape similar to snowflake
– Fact constellations: Multiple fact tables share
dimension tables, viewed as a collection of stars,
therefore called galaxy schema or fact
constellation

20
Star Schema
sale
orderId
date customer
product
custId custId
prodId
prodId name
name
storeId address
price
qty city
amt

store
storeId
city

Star
product prodId name price store storeId city
p1 bolt 10 c1 nyc
p2 nut 5 c2 sfo
c3 la

sale oderId date custId prodId storeId qty amt


o100 1/7/97 53 p1 c1 1 12
o102 2/7/97 53 p2 c1 2 11
105 3/8/97 111 p1 c3 5 50

customer custId name address city


53 joe 10 main sfo
81 fred 12 main sfo
111 sally 80 willow la

21
Example of Star Schema
time
time_key item
day item_key
day_of_the_week Sales Fact Table item_name
month brand
quarter time_key type
year supplier_type
item_key
branch_key
branch location
location_key
branch_key location_key
branch_name units_sold street
branch_type city
dollars_sold province_or_street
country
avg_sales
Measures

Example of Snowflake
time
Schema
time_key item
day item_key supplier
day_of_the_week Sales Fact Table item_name supplier_key
month brand supplier_type
quarter time_key type
year item_key supplier_key

branch_key
location
branch location_key
location_key
branch_key
units_sold street
branch_name
city_key city
branch_type
dollars_sold
city_key
avg_sales city
province_or_street
Measures country

22
Example of Fact
time
Constellation
time_key item Shipping Fact Table
day item_key
day_of_the_week Sales Fact Table item_name time_key
month brand
quarter time_key type item_key
year supplier_type shipper_key
item_key
branch_key from_location

branch location_key location to_location


branch_key location_key dollars_cost
branch_name units_sold
street
branch_type dollars_sold city units_shipped
province_or_street
avg_sales country shipper
Measures shipper_key
shipper_name
location_key
shipper_type

A Data Mining Query Language,


DMQL: Language Primitives

• Cube Definition (Fact Table)


define cube <cube_name> [<dimension_list>]:
<measure_list>
• Dimension Definition ( Dimension Table )
define dimension <dimension_name> as
(<attribute_or_subdimension_list>)
• Special Case (Shared Dimension Tables)
– First time as “cube definition”
– define dimension <dimension_name> as
<dimension_name_first_time> in cube
<cube_name_first_time>

23
Defining a Star Schema in DMQL

define cube sales_star [time, item, branch, location]:


dollars_sold = sum(sales_in_dollars), avg_sales =
avg(sales_in_dollars), units_sold = count(*)
define dimension time as (time_key, day, day_of_week,
month, quarter, year)
define dimension item as (item_key, item_name, brand,
type, supplier_type)
define dimension branch as (branch_key, branch_name,
branch_type)
define dimension location as (location_key, street, city,
province_or_state, country)

Defining a Snowflake Schema in DMQL

define cube sales_snowflake [time, item, branch, location]:


dollars_sold = sum(sales_in_dollars), avg_sales =
avg(sales_in_dollars), units_sold = count(*)
define dimension time as (time_key, day, day_of_week,
month, quarter, year)
define dimension item as (item_key, item_name, brand, type,
supplier(supplier_key, supplier_type))
define dimension branch as (branch_key, branch_name,
branch_type)
define dimension location as (location_key, street,
city(city_key, province_or_state, country))

24
Defining a Fact Constellation in
DMQL
define cube sales [time, item, branch, location]:
dollars_sold = sum(sales_in_dollars), avg_sales = avg(sales_in_dollars),
units_sold = count(*)
define dimension time as (time_key, day, day_of_week, month, quarter,
year)
define dimension item as (item_key, item_name, brand, type,
supplier_type)
define dimension branch as (branch_key, branch_name, branch_type)
define dimension location as (location_key, street, city,
province_or_state, country)
define cube shipping [time, item, shipper, from_location, to_location]:
dollar_cost = sum(cost_in_dollars), unit_shipped = count(*)
define dimension time as time in cube sales
define dimension item as item in cube sales
define dimension shipper as (shipper_key, shipper_name, location as
location in cube sales, shipper_type)
define dimension from_location as location in cube sales
define dimension to_location as location in cube sales

• OLAP
• https://www.youtube.com/watch?v=kFQRr
gHeiOo

25

You might also like