OLAP Setup and User's Guide

DB2 OLAP Server Views

When you create an OLAP application and multidimensional database, DB2 OLAP Server catalogs the new application and database and creates a set of relational tables, known as a star schema. In addition, DB2 OLAP Server creates and manages a number of views that simplify SQL application access to the multidimensional data. You can use custom applications and standard query tools to access the multidimensional data using these views. Some applications are designed to take full advantage of data stored in the star schema created by DB2 OLAP Server.

The following list shows the complete set of views managed by DB2 OLAP Server:

Naming Scheme for Views

DB2 OLAP Server stores all of its base tables and views in the username schema, where username is the user ID assigned to DB2 OLAP Server. For the SQL examples in this chapter, the schema name OLAPSERV is used.

All view names are in uppercase. Do not enclose view names in quotation marks. DB2 OLAP Server constructs view names and stores them in catalog views. Your SQL applications can query the view names from catalog views. Figure 9 shows the primary DB2 OLAP Server views.

Figure 9. DB2 OLAP Server schema


Figure views not displayed.

Using the Cube Catalog View

There is one cube catalog view that DB2 OLAP Server uses in its username schema. This view contains one row for each cube. Use this view to get details about all OLAP applications and cubes stored in a schema. The cube catalog view catalogs all the OLAP applications and databases managed by DB2 OLAP Server.

Cube Catalog View Name

The cube catalog view name is CUBECATALOGVIEW. Like all other views, it is owned by the schema assigned to DB2 OLAP Server.

Cube Catalog View Contents

Table 14 shows the columns in the cube catalog view.

Table 14. Contents of cube catalog view
Name Type Max Size Contents
AppName VarChar 8 The name of the OLAP application that contains the relational cube identified with CubeName.
CubeName VarChar 8 The name of a multidimensional database.
CubeViewName VarChar 27 The fully qualified name of the cube view for this multidimensional database.
FactViewName VarChar 27 The fully qualified name of the fact view for this multidimensional database.
StarViewName VarChar 27 The fully qualified name of the star view for this multidimensional database.
AliasIdViewName VarChar 27 The fully qualified name of the alias ID view for this multidimensional database.
LROViewName VarChar 27 The fully qualified name of the LRO view for the multidimensional database.

Querying the Cube Catalog View Using SQL Statements

Use this SQL statement to get a list of OLAP applications:

SELECT DISTINCT APPNAME FROM OLAPSERV.CUBECATALOGVIEW 

Use this SQL statement to get a list of multidimensional databases in application Sample:

SELECT CUBENAME FROM OLAPSERV.CUBECATALOGVIEW WHERE APPNAME='Sample'

Use this SQL statement to get the view names for multidimensional database Basic in application Sample:

SELECT CUBEVIEWNAME,FACTVIEWNAME,STARVIEWNAME,ALIASIDVIEWNAME,LROVIEWNAME 
  FROM OLAPSERV.CUBECATALOGVIEW WHERE APPNAME='Sample' AND CUBENAME='Basic'

Querying Dimension and Member Information

The cube view and dimension views contain information about the dimensions and members in a relational cube. There is one cube view for each relational cube, and one dimension view for each dimension within a relational cube. These views can be used to query many of the attributes that are assigned to dimensions and members in the OLAP outline.

Using the Cube View

There is one cube view for each relational cube that DB2 OLAP Server manages. The cube view contains one row for each dimension in the relational cube. Use this view to get information about the dimensions of a cube.

Cube View Name

The cube view name is obtained from the CubeViewName column of the cube catalog view.

Cube View Contents

Table 15 shows the columns in the cube view.

Table 15. Contents of Cube View
Name Type Size Contents
DimensionName VarChar 80 The OLAP dimensionName.
RelDimensionName VarChar 18 The DB2 OLAP Server dimension name. This column contains the name of a column in the star view or the fact view that correspond to this dimension. The RelDimensionName is a unique name when compared to all other dimension names and the names of members in the anchor dimension of this relational cube. The RelDimensionName is a modified version of DimensionName. Changes that you might need to make to a DimensionName are:
  • Limit the length of the name.
  • Remove or replace special characters that are allowed in multidimensional names, but not in relational names.
  • Alter characters to create a unique name in the relational cube's name space, after all other changes are made.
DimensionType Small Integer
The values for this column are:
  • 0 = Dense dimension
  • 1 = Sparse dimension
  • 2 = Anchor dimension
DimensionTag Small Integer
The values for this column are:
  • 0x00 for no tag
  • 0x01 for Accounts
  • 0x02 for Time
  • 0x04 for Country
  • 0x08 for Currency Partition
DimensionId Integer
The dimension ID in the OLAP outline.
DimensionViewName VarChar 27 The fully qualified name of the dimension view for this dimension.
UDAViewName VarChar 27 The fully qualified name of the User Defined Attribute (UDA) view for this dimension.
RATViewName VarChar 27 The fully qualified name of the relational attribute view for this Dimension.

Querying the Cube View Using SQL Statements

To access data in the cube view, your application must first determine the name of the cube view from the cube catalog view.

For example, to find the name of the cube view for the Basic database in the Sample application, you query the database use the following SQL statement:

SELECT CUBEVIEWNAME FROM OLAPSERV.CUBECATALOGVIEW 
  WHERE APPNAME='Sample' AND CUBENAME='Basic'

The result of this query might be:

OLAPSERV.SAMPBASI_CUBEVIEW

To list the dimension names and the corresponding dimension view names for the Basic database:

SELECT DIMENSIONNAME.DIMENSIONVIEWNAME FROM OLAPSERV.SAMPBASI_CUBEVIEW

To list the dimension names of the dense dimensions of the Basic database:

SELECT DIMENSIONNAME FROM OLAPSERV.SAMPBASI_CUBEVIEW WHERE DIMENSIONTYPE = 0

To determine the names of the non-anchor dimensions used to name columns in the star view:

SELECT RELDIMENSIONNAME FROM OLAPSERV.SAMPBASI_CUBEVIEW WHERE DIMENSIONTYPE <> 2  

To return the name of the relational attribute view for the Product dimension:

SELECT RATVIEWNAME FROM OLAPSERV.SAMPBASI_CUBEVIEW WHERE DIMENSIONNAME='Product'

Dimension View Name

The dimension view name is obtained from the DimensionViewName column of the cube view.

Dimension View Contents

Table 16 shows the columns in a dimension view.

Table 16. Contents of a dimension view
Name Type Size Contents
MemberName VarChar 80 The name of the member.
RelMemberName VarChar 18 Anchor dimension only. The DB2 OLAP Server member name. This name is used to name columns in the Fact and Star views that correspond to the members of the Anchor dimension. It is a unique name when compared to all other Anchor dimension member names and the names of non-anchor dimensions of this relational cube. It is a modified version of MemberName. Changes that you might need to make to MemberName are:
  • Limit the length of the name.
  • Remove or replace special characters that are allowed in multidimensional, but not in relational names.
  • Alter characters to create a unique name in the relational cube's name space after previous changes are made
RelMemberID Integer None The DB2 OLAP Server ID for this member. This ID is used to join the dimension table to the fact table.
ParentRelId Integer None The relational ID of the member's parent in the OLAP outline. The value is NULL for the top level member.
LeftSiblingRelId Integer None The relational ID of the member's left sibling in the OLAP outline. This value is NULL for members that do not have a left sibling.
Status Integer None The status of this member can contain a combination of:
  • 0x0000= Reserved
  • 0x0001= For a member set to 'Never share'
  • 0x0002= For a member set to 'Label only'
  • 0x0004 = For a member set to 'Shared member'
  • 0x0008 = Reserved
  • 0x0010 = For a parent member with a single child or a parent member with only one child with an aggregation operator. (All other children have the 'no-op' operator.)
  • 0x0020 = For a member where set to 'Dynamic Calc And Store'
  • 0x0040= For a member set to 'Dynamic Calc'
  • 0x0080= Reserved
  • 0x0100= Reserved
  • 0x02000= For a parent member where one of its children is shared
  • 0x04000= For a regular member
CalcEquation Long VarChar (workstation); VarChar (OS/390) 32700 (workstation); 250 (OS/390) The default calculation equation for calculated members. Note that the default calculation equation might not be the equation used to calculate the member's value if a different calculation is specified in the calculation script used to calculate the relational cube.
UnarySymbol Small Integer None The unary calculation symbol:
  • 0 = Add
  • 1 = Subtract
  • 2 = Multiply
  • 3 = Divide
  • 4 = Percent
  • 5 = No op
AccountsType Integer None This attribute is used only for the Accounts dimension. It can contain a combination of the following values:
  • 0x0000 = Do not mask on zero or missing value
  • 0x4000 = Mask on missing value
  • 0x8000 = Mask on zero value
  • 0x0001 = Balance First
  • 0x0002 = Balance Last
  • 0x0004 = Percent
  • 0x0008 = Average
  • 0x0010 = Unit
  • 0x0020 = Details only
  • 0x0040 = Expense
NoCurrencyConv Small Integer None Currency conversion setting:
  • 0x0000 = Use currency conversion
  • 0x0001 = No currency conversion
CurrencyMemberName VarChar 80 A member name from the currency cube associated with this member.
GenerationNumber Integer None The generation number for this member.
GenerationName VarChar 80 The generation name for this member.
LevelNumber Integer
The level number for this member.
LevelName VarChar 80 The level name for this member.
alias table name There is one alias column for each OLAP alias table used in the outline. VarChar 80 The alias for this member in an associated OLAP alias table. If an alias is not provided for a member, this value is null. See Using Alias ID Views.
relational attribute column name There is one relational attribute column for each RatCol user-defined attribute. The data type specified when the relational attribute column was created. The size specified when the relational attribute column was created. The value of the relational attribute for this member.

Querying a Dimension Name Using SQL Statements

To access data in a dimension view, your application must first determine the name of the dimension view from the cube view.

For example, to find the name of the dimension view for the Time dimension in the Basic database, you query the database using the following SQL statement:

SELECT DIMENSIONVIEWNAME FROM OLAPSERV.SAMPBASI_CUBEVIEW WHERE DIMENSIONNAME='Time'

The result of the query might be: OLAPSERV.SAMPBASID_TIME

Listing Member Names Using SQL

To list the member names for the Time dimension:

SELECT MEMBERNAME FROM OLAPSERV.SAMPBASID_TIME

Fact and Star Views

DB2 OLAP Server creates and maintains two views of the fact table of the star schema:

Fact view
There is one fact view for each cube that DB2 OLAP Server manages. The fact view is a simple view of the fact table. The fact table contains the multidimensional data. Use this view to directly access multidimensional data from SQL applications that manage the required joins to the dimension views.

Star view
There is one star view for each cube that DB2 OLAP Server manages. The star view joins the fact table to each of the dimension views of the star schema. This view provides simple SQL access to the multidimensional data and is ideal for ad-hoc queries, and for use with general purpose query tools that do not manage the required joins to the dimension views.

Because a fact table contains values with different levels of aggregation, you must be sure that the set of members selected in each dimension has the same level of aggregation if you write an SQL application to aggregate. Otherwise, your aggregations will be incorrect. One way to meet this requirement is to include a constraint on either the generation number or level number field in the dimension table.

The fact table that DB2 OLAP Server creates has one column for each non-anchor dimension, and one column for each member of the anchor dimension that stores data. The fact table that corresponds to the outline used in Figure 9 has the following columns:

The dimension columns store member IDs that reference members of each non-anchor dimension. The member IDs can be mapped to member names using the dimension views. The anchor member columns store the actual data values. The anchor dimension members can be mapped to columns of the fact view using the dimension view for the anchor dimension.

DB2 OLAP Server uses internal names for the columns of the fact table, and internal IDs for the members. The fact view replaces the internal column names with dimension and member names, but it does not map the dimension column member IDs to member names. The star view replaces the internal column names with dimension and member names, and maps the dimension column member IDs to member names by joining the fact table to the dimension tables.

Although any dense dimension can be specified as the anchor dimension, if you are accessing the fact or star view from SQL applications and running ad-hoc queries, the most natural mapping is obtained if you specify the Accounts dimension as the anchor dimension.

Fact View Name

The fact view name is obtained from the FactViewName column of the cube catalog view.

Fact View Contents

The fact view contains a variable number of columns of two types:

Dimension columns
One column for each non-anchor dimension

Anchor member columns
One column for each anchor dimension member that stores data

Table 17 shows details about the two types of columns in the fact view.

Table 17. Contents of the Fact View
Name Type Contents
For dimension columns:

The short name for the dimension is taken from the RelDimensionName column of the cube view.

Integer RelMemberID of the member of this dimension.
For anchor member columns:

The short member name for the member is taken from the RelMemberName column of the dimension view of the anchor dimension.

Double The data value for this cell.

Querying the Fact View on UNIX and Windows NT Using SQL Statements

To access data in a fact view, your application must first determine the name of the fact view from the cube catalog view.

For example, to find the name of the fact view for the Basic database in the Sample application, you use the following SQL statement:

SELECT FACTVIEWNAME FROM OLAPSERV.CUBECATALOGVIEW 
  WHERE APPNAME='Sample' AND CUBENAME='Basic'

The result of the query might be:

OLAPSERV.SAMPBASI_FACTVIEW

If your application keeps track of RelMemberID values for members, you can query the fact view directly. For example, to select the data values for product with RelMemberId 3 (100-20), in market with RelMemberId 2 (East), at time with RelMemberID 4 (Q3):

SELECT PROFIT,SALES,COGS FROM OLAPSERV.SAMPBASI_FACTVIEW 
  WHERE PRODUCT=3 AND MARKET=2 AND TIME=4

More commonly, queries against the fact view include joins with the dimension views. A query using joins that is equivalent to the previous query is:

SELECT PROFIT,SALES,COGS
    FROM OLAPSERV.SAMPBASI_FACTVIEW,
         OLAPSERV.SAMPBASID_TIME,
         OLAPSERV.SAMPBASID_MARKET,
         OLAPSERV.SAMPBASID_PRODUCT,
   WHERE OLAPSERV.SAMPBASID_TIME.MEMBERNAME='Q3'
     AND OLAPSERV.SAMPBASID_PRODUCT.MEMBERNAME='100-20'
     AND OLAPSERV.SAMPBASID_MARKET.MEMBERNAME='East'
     AND OLAPSERV.SAMPBASI_FACTVIEW.TIME=OLAPSERV.SAMPBASID_TIME.RELMEMBERID
     AND OLAPSERV.SAMPBASI_FACTVIEW.PRODUCT=OLAPSERV.SAMPBASID_PRODUCT.RELMEMBERID
     AND OLAPSERV.SAMPBASI_FACTVIEW.MARKET=OLAPSERV.SAMPBASID_MARKET.RELMEMBERID

Star View Name

The star view name is obtained from the StarViewName column of the cube catalog view.

Star View Contents

The star view contains a variable number of columns of two types:

Dimension columns
One column for each non-anchor dimension

Anchor member columns
One column for each anchor dimension member

Table 18 shows details about the two types of columns in the star view.


Table 18. Contents of the Star View
Name Type Contents
For dimension columns:

The short name for the dimension is taken from the RelDimensionName column of the cube view.

VarChar(80) Member name.
For anchor member columns:

The short member name for the member is taken from the RelMemberName column of the dimension view of the anchor dimension.

Double The data value for this cell.

Querying the Star View on UNIX and Windows NT Using SQL Statements

To access data in the star view, your application must first determine the name of the star view from the cube catalog view.

For example, to find the name of the star view for the Basic database in the Sample application, you use the following SQL statement:

SELECT STARVIEWNAME FROM OLAPSERV.CUBECATALOGVIEW 
  WHERE APPNAME='SAMPLE' and CUBENAME='BASIC'

The result of this query might be: OLAPSERV.SAMPBASI_STARVIEW

To select the data values for product 100-10, in the central market, during the first quarter:

SELECT PROFIT,SALES,COGS FROM OLAPSERV.SAMPBASI_STARVIEW
  WHERE PRODUCT='100-10' AND MARKET='Central' AND TIME='Q1'

To select all products that lost profits in the central region during the second quarter:

SELECT PRODUCT,PROFIT,SALES,COGS FROM OLAPSERV.SAMPBASI_STARVIEW
  WHERE MARKET='Central' AND TIME='Q2' AND PROFIT < 0

Not all members of the star view are at the same hierarchical level, so construct your queries carefully when using SQL to perform aggregation operations. The selected members in a dimension should be at the same level to avoid double aggregations.

For example, the following SQL statement shows members selected at different levels in the star view. (Some sales will be counted twice because two levels of sums are aggregated.)

SELECT SUM(PROFIT) FROM OLAPSERV.SAMPBASI_STARVIEW
  WHERE MARKET IN ('Central','Illinois') AND
      PRODUCT='100' AND
      TIME IN ('Q1','1996')
 

Assuming that Illinois is part of the Central region and that Q1 is part of 1996, this query results in PROFIT figures at both the state and region level and the quarter and year level being summed. Because the Central region already includes Illinois data, Illinois and Q1 data are counted twice in the sum. If you want to correct the SQL to sum the sales for two states in the Central region during two different quarters, you might use the following example:

SELECT SUM(PROFIT) FROM OLAPSERV.SAMPBASI_STARVIEW
  WHERE MARKET IN ('Indiana','Illinois') AND
      PRODUCT='100' AND
      TIME IN ('Q1','Q2')
 


[ Top of Page | Previous Page | Next Page ]