Upload
buiminh
View
218
Download
2
Embed Size (px)
Citation preview
MDX – Multid imensional E xpressions
Microsofts proposal for a
multidimensional query and
presentation language
for OLE DB for OLAP
Robert Fenk
March 11, 1999
Page 1 Robert Fenk February 17, 2000, mdx-vortrag.tex
Contents� MDX Overview
– Data Cube
– MDX Syntax
– Data Set
� MDX and Range Queries
� MDX Summary
� Implementing MDX
� Processing of two Example Queries
Page 2 Robert Fenk February 17, 2000, mdx-vortrag.tex
MDX Overview
Data Set
Data Cube
MDXquery
Page 3 Robert Fenk February 17, 2000, mdx-vortrag.tex
MDX Data Cube
The MDX view of a multidimensional data cube:
Dimension: a set of elements of the same type
Member: elements of a dimension
Hierarchy: groups members of a dimension
Member–Properties: additional information
Page 4 Robert Fenk February 17, 2000, mdx-vortrag.tex
Example MDX Data Cube
4 Dimensions: Salesperson, Time, Measures, Product
Salesperson –dim: . . . , Netz, . . . , Venkatrao, . . .
Time –dim:. . . , 1998, Qtr1 1998, Jan 1998,
1/1/1998, . . . , 1999, . . .
Measures –dim: Sales, Turnover, . . .
Product –dim: . . . , TV, Color–TV, . . .
Member–Props of
Salesperson –dim:Name, Phone, . . .
Page 5 Robert Fenk February 17, 2000, mdx-vortrag.tex
Hierarchy–Schemata over the Time –dimension
Level: Weeks
Level: Days
Level: Year
Level: Quarter
Level: Month
Level: Day
Level: All Level: All
Hierarchy: WeeksHierarchy: Quarters
Dimension:Time
Level: Year
in different hierarchies
contained in one hierarchyA dimension member only
A dimension member contained
Page 6 Robert Fenk February 17, 2000, mdx-vortrag.tex
Example Hierarchy over the Time –dimension
... ...
1998.Qtr41998.Qtr2
1998.Qtr1.Mar
1998.Qtr1
19981985
1998.Qtr3
1998.Qtr1.Jan
Level: Month
Level: Year
Hierarchy: Quarters
Level: Day
Level: Quarter
Level: All
Dimension:Time
All
1998.Qtr1.Jan.311998.Qtr1.Jan.1 1998.Qtr1.Dec.1 1998.Qtr1.Dec.31
1998.Qtr4.Nov 1998.Qtr4.Dec1998.Qtr4.Oct1998.Qtr1.Feb
Page 7 Robert Fenk February 17, 2000, mdx-vortrag.tex
Example Fact Table according to ROLAP
dimensions / key attributes measures
Salesperson Time Product Cost Sales Turnover
Venkatrao 1998 TV 50000 10023 190000
Netz 1998 TV 56789 90023 100000
. . . . . . . . . . . . . . . . . .
Page 8 Robert Fenk February 17, 2000, mdx-vortrag.tex
Example Fact Table for an MDX Data Cube
dimensions / key attributes one data–cell
Salesperson Time Product Measures Value
Venkatrao 1998 TV Cost 50000
Venkatrao 1998 TV Sales 10023
Venkatrao 1998 TV Turnover 190000
Netz 1998 TV Cost 56789
Netz 1998 TV Sales 90023
Netz 1998 TV Turnover 100000
. . . . . . . . . . . . . . .
Page 9 Robert Fenk February 17, 2000, mdx-vortrag.tex
MDX Rowsets storing meta data
CATALOG_NAMESCHEMA_NAME
CUBE Rowset
CUBE_NAMECUBE_TYPECUBE_GUIDCREATED_ONLAST_SCHEMA_UPDATESCHEMA_UPDATED_BYLAST_DATA_UPDATEDATA_UPDATED_BYDESCRIPTION
CATALOG_NAMESCHEMA_NAMECUBE_NAMEDIMENSION_UNIQUE_NAME
HIERARCHY_UNIQUE_NAMEHIERARCHY_NAME
HIERACHY_GUIDHIERACHY_CAPTIONDIMENSION_NAMEHIERACHY_CARINALITYDEFAULT_MEMBERALL_MEMBERDESCRIPTION
HIERACHIES Rowset LEVELS Rowset
LEVEL_NAMELEVEL_UNIQUE_NAMELEVEL_GUIDLEVEL_CAPTIONLEVEL_NUMBERLEVEL_CARDINALITYLEVEL_TYPEDESCRIPTION
HIERARCHY_UNIQUE_NAMEHIERARCHY_NAMEDIMENSION_UNIQUE_NAME
CATALOG_NAMESCHEMA_NAMECUBE_NAME
MEMBERS RowsetCATALOG_NAMESCHEMA_NAMECUBE_NAMEDIMENSION_UNIQUE_NAMEHIERACHY_UNIQUE_NAMELEVEL_UNIQUE_NAMELEVEL_NUMBERMEMBER_ORDINALMEMBER_NAMEMEMBER_UNIQUE_NAMEMEMBER_TYPEMEMBER_GUIDMEMBER_CAPTIONCHILDREN_CARDINALITYPARENT_LEVELPARENT_UNIQUE_NAMEPARENT_COUNTDESCRIPTION
MEASURES RowsetCATALOG_NAMESCHEMA_NAMECUBE_NAMEMEASURE_NAMEMEASURE_UNIQUE_NAMEMEASURE_CAPTIONMEASURE_GUID
DATA_TYPENUMERIC_PRECISIONNUMERIC_SCALENUMERIC_UNITSDESCRIPTION
MEASURE_AGGREGATOR
CATALOG_NAMESCHEMA_NAME
DIMENSION_NAMEDIMENSION_UNIQUE_NAME
DIMENSION_CAPTIONDIMENSION_ORDINAL
DIMENSIONS Rowset
DIMENSION_GUID
DIMENSION_TYPEDIMENSION_CARDINALITYDEFAULT_HIERARCHYDESCRIPTION
CUBE_NAME
PROPERTIES Rowset
MEMBER_UNIQUE_NAMEPROPERTY_TYPEPROPERTY_NAMEPROPERTY_CAPTIONDATA_TYPECHARACTER_MAXIMUM_LENGTHCHARACTER_OCTET_LENGTHNUMERIC_PRECISIONNUMERIC_SCALEDESCRIPTION
CATALOG_NAMESCHEMA_NAMECUBE_NAMEDIMENSION_UNIQUE_NAMEHIERACHY_UNIQUE_NAMELEVEL_UNIQUE_NAME
Page 10 Robert Fenk February 17, 2000, mdx-vortrag.tex
MDX “Syntax”
[WITH <formula_spec>]
SELECT <axis_spec> [, <axis_spec>, ...]
FROM <cube_spec> [, <cube_spec>, ...]
WHERE <slicer_spec> [cell_properties]
Page 11 Robert Fenk February 17, 2000, mdx-vortrag.tex
MDX “Syntax” Description� WITHclause: creation of a new dimension member, which lives
in the context of the expression.e.g.:
WITH MEMBER Measures.[% Change from Last Year’s Sales] AS
Sales / (Sales, Year.PREVMEMBER)
� axis spec : maps dimensions to axes and gives restrictions.
e.g.: f1998, 1999 g ON COLUMNS
� cube spec : determines the data cube (usually a single data
cube)
� slicer spec : restricts to dimensions not given in the
axis spec (meaning of the cell contents)
Page 12 Robert Fenk February 17, 2000, mdx-vortrag.tex
MDX–Query Example
SELECT CROSSJOIN({Venkatrao, Netz},
{USA_North.CHILDREN,
USA_South, Japan})
ON COLUMNS
{Qtr1.CHILDREN, Qtr2,
Qtr3, Qtr4.CHILDREN}
ON ROWS
FROM SalesCube
WHERE (Sales, [1998], Products.All)
Page 13 Robert Fenk February 17, 2000, mdx-vortrag.tex
MDX Data Set
The result of an MDX–query is called a data set.
Dataset: a multidimensional cube / a set of Excel tables
Axis: dimensions are mapped to axes
Coordinate: elements of an axis
Cell: element of the dataset specified by its axis–coordinates
Cell–Properties: additional information
Page 14 Robert Fenk February 17, 2000, mdx-vortrag.tex
Example Data SetSum of all product sales for 1998:
Venkatrao Netz
USA
Japan
USA
JapanUSA NorthUSA South
USA NorthUSA South
Boston Seattle Boston Seattle
Qtr1
Jan � � � � � � � � � � � � � � � � � � � � � � � �
Feb � � � � � � � � � � � � � � � � � � � � � � � �
Mar � � � � � � � � � � � � � � � � � � � � � � � �
Qtr2 � � � � � � � � � � � � � � � � � � � � � � � �
Qtr3 � � � � � � � � � � � � � � � � � � � � � � � �
Qtr4
Oct � � � � � � � � � � � � � � � � � � � � � � � �
Nov � � � � � � � � � � � � � � � � � � � � � � � �
Dec � � � � � � � � � � � � � � � � � � � � � � � �
Page 15 Robert Fenk February 17, 2000, mdx-vortrag.tex
MDX Summary� Data Cube: “contains” also aggregated measures
– contains the measures (a single value)
– the type of the measure is given by the Measure–dimension
� Restriction: given by sets of members
– sets of members are ordered (! data set)
– axis spec and slicer spec
� Projection:
– members given in the axis spec are mapped to axes
– the order of the members defines the order of the coordinates
Page 16 Robert Fenk February 17, 2000, mdx-vortrag.tex
Restrictions resulting in intervals
� <member>:<member> (range)
� <dimension>.MEMBERS
� <hierarchy>.MEMBERS
� <level>.MEMBERS
� <member>.CHILDREN
� DESCENDANTS(<member>, <level>)
Page 17 Robert Fenk February 17, 2000, mdx-vortrag.tex
Examples Restrictions resulting in a Range Queries
Restriction: fHuber, 1998, Sales, TVg
! MDX: a point query resulting in a single measure.
! UB–Tree: two ranges (Time– and Product–dimension),
+ aggregation
Restriction: fHuber, 1998.CHILDREN, Sales, TVg
Restriction: fHuber:Maier, 1998.CHILDREN, Sales, TV.MEMBERSg
Page 18 Robert Fenk February 17, 2000, mdx-vortrag.tex
Implementing MDX
1. Get an MDX–Parser
2. Map the data cube in a useful way to a DBMS
e.g. a star schema of a RDBMS or a UB–Tree
3. Transform the MDXs to the query–language of the used DBMS
e.g. MDX ! SQLs
4. Build up a data set with the results of the DBMS–query
e.g. aggregations, reordering, folding
5. Provide the data set to the application
Page 19 Robert Fenk February 17, 2000, mdx-vortrag.tex
Implementing a MDX Data Cube (SalesCubeRelation)
create a fact table with
one column per hierarchy level of each dimension
Salesperson Year Month Day Product SalesVenkatrao 1998 Jan 1 TV 4Venkatrao 1998 Feb 2 TV 16Venkatrao 1998 Mar 3 TV 68Venkatrao 1999 Jan 1 TV 71Venkatrao 1999 Feb 2 TV 41Venkatrao 1999 Mar 3 TV 30Netz 1998 Jan 1 TV 86Netz 1998 Feb 2 TV 68Netz 1998 Mar 3 TV 89Netz 1999 Jan 1 TV 40Netz 1999 Feb 2 TV 32Netz 1999 Mar 3 TV 82
Page 20 Robert Fenk February 17, 2000, mdx-vortrag.tex
Implementing MDX Queries
Query Transformation:
� extract the restrictions on dimensions given in the axis specand slicer spec
� determine by the slicer spec over which dimensions weaggregate and get the aggregation type from the meta date
Query Execution:
� recognize ranges in the restrictions on the dimensions
� execute the transformed query
Transformation of the Result Relation to a Data Set:
� reordering of the result relation according to the axis spec
� folding of the result relation according to the axis spec
Page 21 Robert Fenk February 17, 2000, mdx-vortrag.tex
COGNOS like MDX Example (1/4)
SELECT { Salesperson.All.Venkatrao,
Salesperson.All.Netz }
ON AXIS(0)
{ Time.All.1998,
Time.All.1999 }
ON AXIS(1)
FROM SalesCube
WHERE { Product.All.TV, Measures.All.Sales }
Page 22 Robert Fenk February 17, 2000, mdx-vortrag.tex
COGNOS like MDX Example (2/4)The dimensions are restricted to:
Salesperson: fVenkatrao, Netzg
Time: f1998, 1999g
Product: fTVg
Measures: fSalesg
Aggregation is done over:
Saleperson–dimensionYear–dimension
Page 23 Robert Fenk February 17, 2000, mdx-vortrag.tex
COGNOS like MDX Example (3/4)
fold(tG;F (��(R)))
where
R = SalesCubeRelation
� = Salesperson 2 fVenkatrao;Netzg ^
Year 2 f1998; 1999g ^
Product 2 fTVg ^
Measures 2 fSalesg
G = ffSalesperson; Yeargg
F = f�Salesg
Page 24 Robert Fenk February 17, 2000, mdx-vortrag.tex
COGNOS like MDX Example (4/4)
Result Relation:
Salesperson Year Product Sales
Venkatrao 1998 TV 88
Venkatrao 1999 TV 142
Netz 1998 TV 243
Netz 1999 TV 154
Data Set: By folding the result relation according to the axisspecification we get the following data set:
Sum of the TV Sales
Venkatrao Netz
1998 88 243
1999 142 154
Page 25 Robert Fenk February 17, 2000, mdx-vortrag.tex
More general Example (1/4)
SELECT CROSSJOIN({Venkatrao, Netz},
{1998.Jan, 1998.Feb,
1998.Mar, 1998})
ON AXIS(0)
{TV, Computer, Product.ALL}
ON AXIS(1)
FROM SalesCube
WHERE {Sales}
Page 26 Robert Fenk February 17, 2000, mdx-vortrag.tex
More general Example (2/4)
fold(��2(tG;F (��1(R))))
�1 = Salesperson 2 fVenkatrao;Netzg ^
Year 2 f1998g ^ Product 2 fTV;Computerg ^
Measures 2 fSalesg
G = ffSalesperson; Year;Month; Productg
fSalesperson; Year; Productg
fSalesperson; Year;Monthg
fSalesperson; Yeargg
F = f�Salesg
�2 = Month 2 fJan, Feb, Marg _
(Year 2 f1998g ^ Month = ALL)Page 27 Robert Fenk February 17, 2000, mdx-vortrag.tex
More general Example (3/4)Result Relation:
Salesperson Year Month Product SalesNetz 1998 Jan TV . . .Netz 1998 Feb TV . . .Netz 1998 Mar TV . . .. . . . . . . . . . . . . . .Netz 1998 ALL TV 243. . . . . . . . . . . . . . .Netz 1998 ALL Computer 417. . . . . . . . . . . . . . .Netz 1998 ALL ALL 660. . . . . . . . . . . . . . .Venkatrao 1998 ALL TV 150. . . . . . . . . . . . . . .Venkatrao 1998 Jan Computer . . .Venkatrao 1998 Feb Computer . . .Venkatrao 1998 Mar Computer . . .. . . . . . . . . . . . . . .Venkatrao 1998 ALL Computer 350. . . . . . . . . . . . . . .Venkatrao 1998 ALL ALL 500
Page 28 Robert Fenk February 17, 2000, mdx-vortrag.tex
More general Example (4/4)
Data Set:
Venkatrao Netz1998
19981998
1998Jan Feb Mar Jan Feb Mar
TV . . . . . . . . . 150 . . . . . . . . . 243Computer . . . . . . . . . 350 . . . . . . . . . 417ALL . . . . . . . . . 500 . . . . . . . . . 660
Page 29 Robert Fenk February 17, 2000, mdx-vortrag.tex