D70039GC10 Appendix A
D70039GC10 Appendix A
Appendix A
Practices and Solutions
Practices Overview
The goal of the course practices is to progressively build an OLAP data model to support
the following requirements:
• Summary management for existing SQL table queries by designing OLAP cubes
and enabling query rewrite against the cubes
• Enhanced analytic content, including a wide range of calculated measures that
enable easy end-user access to rich analytic information
• Easy access to OLAP data by using simple SQL:
– Creating and executing OLAP queries in SQL Developer
– Using OLAP queries in Oracle Application Express (APEX)
– Using OLAP queries in Oracle BI Enterprise Edition (BI EE)
• Cube security
In the practices for this lesson, you start Analytic Workspace Manager (AWM), create a
new AW, and build an OLAP cube. You will perform the following tasks:
• Create a database connection for your OLAP environment and log in.
• Create an Analytic Workspace.
• Create Dimensions for your OLAP data model, including:
– Levels
– Hierarchies
– Attributes
– Dimension mappings
• Load dimension data.
5. In the Connect to database dialog box, enter and perform the following:
a. Username: olaptrain
b. Password: oracle
c. Click OK.
Result: Two folders appear below the database connection – Schemas and Reports.
6. Select Schemas > OLAPTRAIN. Then, right-click Analytic Workspaces and select
Create Analytic Workspace from the menu.
7. In the Create Analytic Workspace dialog box, enter or select the following:
a. Name: SALESTRACK
b. Tablespace: <default>
c. Click Create.
Result: An AW named SALESTRACK appears in the navigator.
objects.
4. In the Implementation Details tab of the Create Dimension dialog box, select Use
Keys from Data Source.
5. Click Create.
6. Select Dimensions > CHANNEL. The following should appear in the navigator:
a.
b. Select the Levels node.
d. Click Create.
8. Create a User Attribute for Channel Type by doing the following:
a. Rick-click the Attributes node below the Channel dimension, and select Create
Attribute.
b. In the Create Attribute dialog box, select or enter the following:
i) Name = CHANNEL_TYPE
ii) Attribute Type = User
iii) In the “Apply Attributes To” box:
– Click the plus sign next to the Channel dimension.
– Deselect the Channel dimension check box.
– Select the CHANNEL level check box (the lowest level).
Note: The Channel Type attribute only applies to the lowest level in the Sales
Channel hierarchy.
The dialog box should look like this:
9. Map the Channel dimension to its relational sources by performing the following:
a. Click the Mappings node below the Channel dimension.
Result: The Schemas and Mapping panes appear to the right.
b. In the Schemas pane, select OLAPTRAIN > Tables to display the source tables
for the OLAPTRAIN schema. Then, select CHANNELS to display its columns.
c. Ensure that Star Schema is selected for the Type of Dimension Table, and that
Table Mapping View is selected.
d. Drag the following source columns from the Schema pane to the Mapping pane
for the CHANNEL and CLASS levels. In addition, enter the following constants
for the ALL_CHANNELS level:
– Member = ‘ALL_CHANNELS’
– Description attributes = ‘All Channels’
13. On the Implementation Details tabbed page, select Use Keys from Data Source.
Note: For the ALL_YEARS level, use the following values in the Source Column
fields (including single quotes):
• Member: ‘ALL_YEARS’
• LONG DESCRIPTION: ‘All Years’
• SHORT DESCRIPTION: ‘All Years’
• END_DATE: TO_DATE(‘2008-DEC-31’, ‘YYYY-MON-DD’)
• TIME_SPAN: 3000
23. Under the Dimensions node in the navigator, select PRODUCT and then the
Mappings node.
Result: Data for the Product dimension is loaded and the AWM Build Log
appears when the data load is finished.
2. Click Close.
3. In the navigator, right-click PRODUCT and select View Data PRODUCT from the
a. You can review the hierarchical structure of a dimension using the Data Viewer.
For example, select All Products > Computers > Computer Printers and
Supplies. You should see the following display:
Result: The structure of the Hierarchy view appears in the General tab, displayed
in the right pane.
b. Click the Data tab.
Note: Later in the course, you will learn how to use these columns in SQL queries
to return the desired OLAP data.
5. Collapse the PRODUCT dimension in the navigator.
3. Select the Aggregation tab. Then, in the Precompute subtab, specify a value of 30 for
Cost-based aggregation.
4. Select the Storage tab. Select the Sparse option for all dimensions.
10. Using the same techniques described in steps 7 and 8, create a second measure named
QUANTITY.
11. Click the Mappings node under SALES_CUBE, and ensure that the Table Mapping
View tool (shown below) is selected.
Practice 3-2b: Load and View Data for the Sales Cube
In the practices in this section, you load the data to the Sales cube, and you view cube
data using both the AWM Data Viewer and the cube views.
1. In the navigator, right-click SALES_CUBE and select Maintain Cube
SALES_CUBE from the menu.
2. In the Maintenance Wizard, accept all defaults and click Finish to begin the load
When the build and load process is complete, the AWM Build Log appears:
b. Click the Remove All Items tool to clear the Selected list.
c. In the Members tab of the Available list, select All Regions and select North
America, Asia, and Europe.
d. Click the Add Selected Items tool to move the chosen dimension members
to the Selected list, like this:
9. In the Data Viewer, select All Products. Also, notice that you can select from a list of
members for the Geography dimension.
Note: AWM provides a view of the relational cube view representation of the data from
within the administrative tool. Later, you learn how to query the OLAP data directly by
using SQL against cube views.
13. Collapse the SALES_CUBE node by clicking its minus sign.
In the practices for this lesson, you enable Query Rewrite and MV Refresh for the Sales
Cube, and then perform a build to create the Cube MVs. Then, you run some queries that
do not rewrite correctly to the Cube MVs. Using the mv_cube_advice package, you
determine why the queries are not rewriting. You then modify the queries so that they
rewrite to the cube MVs.
c. Accept the default settings for all other options, and click Apply.
Result: The following information box appears:
3. When the processing is complete, go to the navigation pane and select Dimensions >
Geography.
4. Select the Mappings node under Geography, and notice that OLAP has added a new
Unique Key attribute to each level in the dimension, and automapped the attributes:
The CB$ tables – one each for the cube and the associated dimension hierarchies –
were automatically created by the OLAP build process.
4. Close the olaptrain (local) tab by clicking the X.
Next, you will see how these Cube MVs may be used for rewrite when summary
queries are executed against the OLAPTRAIN fact and dimension tables.
c. Click Open.
8. Scroll down until you reach the ALTER materialized VIEW statements. Click the
statement that disables query rewrite for cb$sales_cube.
13. Record the time it took to run the query, up to two decimal places.
Note: The value appears at the top of the SQL pane, as shown in the following
screenshot. In the example, the query time would be rounded to 2.54 seconds. The
value you see will probably be different from the example, although it should be
close.
14. Click inside the second query and press F9 to execute the query, as the following
screenshot shows. Again, record your query time.
16. Scroll back up in the SQL file. Enable query rewrite to cb$sales_cube by clicking the
enable query rewrite statement, and then pressing F9.
17. To confirm that the queries will rewrite, click within the first query and press F6 to
display the Explain Plan, as shown in the following screenshot:
19. Using the same technique as in step 18, execute the second through fourth queries.
Record each of the query times.
Note: Query times for a Cube MV rewrite commonly are 10 to 50 times faster than
summary queries against relational fact tables.
20. Close the Prac4_2.sql file.
21. Exit SQL Developer.
In the practice for this lesson, you create a range of calculations, including:
• Calculated measures using the Calculation Builder
• Calculated measures using XML templates
• Custom calculations using expression syntax
3. Right-click the Calculated Measures node and select Create Calculated Measure
from the menu.
4. In the Create Calculated Measure dialog box, enter or select the following:
a. Name = SALES_YTD (the Name field is automatically all caps, and the Label
and Description fields are autofilled)
b. Calculation Type = Period to Date
c. In the Calculation inputs section, select the following:
i) First hyperlink = Ancestor At Level
d. Click Create.
5. Select the Calculated Measures node.
Result: The SALES_YTD calculation appears.
c. Click Create.
vii) In the Expression field, add the following syntax to the beginning of the
expression: 100 *
Note: This additional syntax causes the calculation to display percentage figures
in whole numbers.
The expression should now look like this:
c. Click Create.
3. Click Create.
Result: The calculation appears in the navigator.
4. Select the new calculation.
7. Create a Share measure for the Channel dimension. You may either use the
Calculation Builder or an XML template.
Note: If using the Calculation Builder, follow steps 7a – 7b. If using an XML
template, select the SALES_SHARE_TOT_CHAN.XML file.
a. Right-click Calculated Measures and select Create Calculated Measure from the
menu.
b. In the Create Calculated Measure dialog box, enter or select the following:
i) Name = SALES_SHARE_TOT_CHAN
ii) Leave all Label and Description boxes with the autofilled text.
iii) Calculation Type = Share
iv) Click the dimension hyperlink (TIME) and select CHANNEL from the list.
v) Select the Multiply result by 100 option.
The calculation should look like this:
11. Feel free to examine any of the definitions for the calculations that you created from
XML template files.
b. Click the Add Selected Items tool to move those two measures to the
Selected list, like this:
b. Click the Remove All Items tool to clear the Selected list.
c. In the Members tab of the Available list, select All Years > CY2007.
d. Select all four quarters in CY2007, like this:
h. Click the Add Items tool to move the department members to the Selected list.
The calculated measures show the rank of each Product dimension member within its
hierarchy parent. The share measure shows the percentage of sales returned by the
product member to its parent in the hierarchy.
The rank and share measures show the relative ranking and share contribution for
each of the Product division members in the Computers department.
Practice 5-4a: Create three custom calculations that illustrate the use of a QDR (qualified
data reference).
Note: The braces for the QDR are square “[“ and “].”
g. Click Create.
3. Open the Create Calculated Measure dialog box. Enter or select the following:
a. Name = TO_GO
b. Leave all Label and Description boxes as autofilled
c. Calculation Type = Expression
d. In the Expression box, enter:
SALES_CUBE.SALES_2006 - SALES_CUBE.SALES_YTD
e. Click Create.
4. Open the Create Calculated Measure dialog box and enter or select the following:
a. Name =PCT_OF_2006 (leave all Label and Description boxes as autofilled.)
b. Calculation Type = Expression
c. In the Expression box, enter:
Now, use these three calculations in the Data Viewer by performing the following:
5. In the Navigator, right-click the SALES measure and select View Data Sales from
the menu.
6. Remove the Graph by clicking the down arrow of the Hide/Show tool. ( )
7. Click the Query Builder tool.
8. In the Items tab, add the following measures (in the order specified) from the
Available list to the Selected list: Sales YTD, Sales 2006, To Go, and Pct of 2006.
9. Using the Layout tab, place Geography, Channel, and Product on the Page Items axis,
and Time on the Row axis.
10. In the Dimension tab, select the four quarters of CY2007, using the same techniques
described previously in this practice.
11. Click OK to view the data.
The report dynamically compares several sales measures for a selected time period to
a different “benchmark” sales value for the year 2006.
Notice how the:
• “To Go” calculation shows the Sales revenue required to meet CY2006 Sales
• “Pct of 2006” measure shows the percent of YTD sales against the benchmark
Practice 5-4b: Now, create a custom calculation that includes the use of conditional
expression syntax.
1. Open the Create Calculated Measure dialog box. Enter or select the following:
a. Name = HOW_IS_SALES_YTD
b. Leave all Label and Description boxes as autofilled
c. Calculation Type = Expression
d. In the Expression box, enter the following CASE statement:
CASE
WHEN SALES_CUBE.SALES_YTD_PY_PCT_CHG < 0 THEN ‘Needs Improvement’
WHEN SALES_CUBE.SALES_YTD_PY_PCT_CHG > 15 THEN ‘Outstanding’
ELSE ‘On track’
END
e. Click Create.
2. In the Navigator, right-click the SALES_YTD_PY_PCT_CHG measure and select
View Data SALES_YTD_PY_PCT_CHG from the menu.
3. Remove the Graph by clicking the down arrow of the Hide/Show tool.
4. Click the Query Builder tool.
5. In the Items tab, add How Is Sales Ytd to the Selected list.
6. In the Layout tab, place Time above the measures in the Column axis, like this:
7. In the Dimensions tab, select the Time dimension from the Choose list, and then
select the four quarters of CY2007, using the same techniques described previously in
10. Select the Measure headings and select the Wrap Text tool . Then, resize the
column edges, like this:
Practice 5-4c: Finally, create a custom calculation that calls an OLAP DML program.
In order to create the final custom calculation, you must first have access to the program
that it calls. Therefore, use the following instructions to import an OLAP DML program
named product_alert.dml:
1. Select Tools > OLAP Worksheet.
2. In the command window, enter the following command (and then press F5):
infile cubes/product_alert.dml
Result: The predefined OLAP DML program is imported into the AW.
3. Execute the following three commands in the command window:
compile product_alert
update
6. In the navigator, right-click the SALES measure and select View Data SALES from
the menu.
7. Remove the Graph by clicking the down arrow of the Hide/Show tool.
8. Click the Query Builder tool.
9. In the Items tab, add Sales Pr Year Pct Chg and Product Alert to the Selected list.
10. In the Layout tab, create the following layout:
Note:
An Alert is raised on Computers, even though it is by far the largest selling product
department, and also shows good growth (a good percent change from last year).
This means that there is a hidden sales problem somewhere in the Computers
department.
In the practices for this lesson, you use SQL Developer to query OLAP cubes directly
using the OLAP cube views. You apply techniques that leverage the unique properties of
OLAP cubes, including:
• Level and Member filters
• Embedded Total features
• Hierarchical (“Family”) relationships
• Parent columns in order to “drill down”
1. Scroll down in Prac6.sql to 6-2. Examine the query, and fill in the remaining
elements.
3. Leave the Value box blank, and click Apply to execute the query.
Query results include a drilldown on ‘ALL_YEARS’ for the TIME dimension:
In the practices for this lesson, you enhance the analytic content of your OLAP data
model by adding the following elements:
• Cubes with varying dimensionality
• Integrated measures from data with different dimensionality
• Forecast measures of sales data
In practice sections, you will create statistical forecasts based on historic sales data.
6. Import and view a DML program that contains the forecasting logic:
a. Open the OLAP Worksheet, and execute the following commands:
– infile cubes/do_forecast.dml
– update
– commit
b. Then, open the program by executing the following command:
– edit do_forecast
The program contains four primary sections, which perform the following tasks:
i) Define the historical basis for the forecast (LIMIT commands)
ii) Identify forecast method (definition of forecast function variables)
c. Close the program window when you are done viewing the DML code.
7. Close the OLAP Worksheet.
8. Under the FORECAST cube node, right-click Cube Scripts and select Create Cube
Script from the menu.
9. In the Create Cube Script dialog box, perform the following:
a. Enter RUN_FORECAST as the name.
b. Click the New Step button, and select New OLAP DML Step from the menu.
d. Click OK.
e. In the Create Cube Script dialog box, click Create.
10. To run the forecast:
a. Right-click the RUN_FORECAST cube script and select Run Cube Script
RUN_FORECAST from the menu.
b. In the Maintenance Wizard, select all three dimensions and click the Remove
button. The dimensions are removed from the Selected list, as the following
screenshot shows (the dimensions do not need to be loaded again).
c. Click Finish.
11. When the Build Log appears, close the window.
Note: In our example, forecasts are not broken out by channel. Therefore, the
crossover measures only show forecast data for the top level in the Channel
dimension (‘ALL_CHANNELS’).
2. Click Create.
3. Create another Calculated Measure, with the following input:
a. Name = CROSS_OVER_LINEAR_REGRESSION
b. Calculation Type = Expression
4. Click Create.
5. Open the CROSS_OVER_BEST_FIT calculated measure in the Data Viewer.
6. Remove the Graph by clicking the down arrow of the Hide/Show tool.
7. Click the Query Builder tool.
8. In the Items tab, add SALES to the Selected list.
Note: The Cross Over calculation uses Sales data for historical time periods, but
applies the specified forecast method for future periods
In the practices for this lesson, you access OLAP data using APEX. You perform three
tasks:
1. Create an interactive report that allows you to view highly stylized output. This
report will use parameters; however the parameters will not be used until the
second practice.
2. Add formatting to the report.
3. Leverage the parameters to enable data exploration using “drilling” across the
product, time, and geography dimensions.
You will find that this style of drilldown will work with any type of hierarchy: level-
4. To access the predefined application, click Application Builder > OLAP ILT –
Hands On.
a. On the Page Definition page, click the Create button in the Regions pane.
b. On the Create Region page, select Report and click Next.
c. On the Report Implementation page, select Interactive Report and click Next.
d. On the Display Attributes page, enter Explore as the title and click Next.
e. On the Source page, you will use a predefined query. Perform the following:
i) Select File > Open File from the browser’s main menu.
ii) Open the home/oracle/common_schema/olaptrain/labs/Prac8-1.sql file.
iii) Select the query (that is explained in the following) and copy it to the
clipboard.
SELECT
g.long_description "Geography",
p.long_description "Product", Dimension Descriptions
t.long_description "Time",
trunc(sales) "Sales",
trunc(sales_pp_pct_chg, 1)
"% Chg Pr Period",
t.dim_key as time_dim_key,
t.parent as time_parent,
t.end_date as end_date, Dimension Key and
g.parent as geography_parent, Parent Columns (used
g.dim_key as geography_dim_key, for drilling)
p.parent as product_parent,
p.dim_key as product_dim_key
FROM sales_cube_view s,
time_calendar_view t, Cube and dimension
product_standard_view p, views
geography_regional_view g
Note: This single select statement is used to navigate vast regions of the cube.
Notice that the parameter names match the hidden items you created previously.
iv) Paste the query into the SQL SELECT statement box.
1. Click the button in the middle of the page to view and then format the report.
2. In the Login screen, enter olaptrain/oracle and click Login.
6. Color the % Chg Pr Year cells green if sales growth exceeds 10%:
1. Return to the page editor by clicking the link at the bottom of the report
page.
2. Go to the Report Attributes page by clicking the Interactive Report link in the
Regions pane.
3. Add a drilldown link to Geography:
a. Click the Edit icon for Geography.
b. Click the button above the Column Definition page.
c. For Link Text, click the [Geography] link.
d. In the Page text box, enter 1 (that is, the current page number is “1”).
e. Use the flashlight icons to enter name value pairs as follows:
Note:
• You set the “link” dimension to the current member. This value, as described
earlier, will cause the drilldown on Geography.
• You also set parameters for the Product and Time dimensions as well. By
setting these values to the parent column, you are effectively preserving the
state of the report (the children of a parent produces the current set of
members). This allows browser operations like bookmarking to re-create the
report in its drilldown state; these parameters appear in the URL.
f. Click Apply Changes.
4. Add a drilldown link to Product:
a. Click the Edit icon for Product.
b. For Link Text, click [Product].
c. For Page, enter 1 (that is, the current page number is “1”).
d. Use the flashlights to enter name value pairs as follows:
7. Run the report from the Application Page. The report should look like this:
The resulting report shows the Computer division products that contain underlying alerts:
9. Feel free to experiment with the interactive report. If you have time, there is an
optional exercise to examine on the following page.
6. Open a connection to the database using the DM user by clicking the local (DM)
node in the Connections pane.
7. In the SQL Worksheet for the following steps, select sales data from the
SALES_CUBE:
select c.long_description,
s.sales
from olaptrain.sales_cube_view s,
olaptrain.channel_view c
where s.product = 'ALL_PRODUCTS'
and s.geography = 'ALL_REGIONS'
and s.time = 'ALL_YEARS'
and s.channel = c.dim_key;
Practice 9-2: Limit the Channels That the DM User May View
In this practice section, you will use AWM to define a data security policy over the
Channel dimension.
The DM user will only be allowed to see the following Channel members:
• All Channels
• Indirect, Web
• Catalog
• Indirect Warehouse.
Follow these steps in AWM to limit the Channels that the DM user may view:
1. Right-click the Data Security node for the Channel dimension and select Create
Data Security Policy.
2. In the General tab of the Create Data Security Policy dialog box, specify the
f. Click Create.
5. Go back to SQL Developer, and log off of DM. Then log back on as DM.
6. Re-execute the following query using the DM connection:
select c.long_description,
s.sales
from olaptrain.sales_cube_view s,
olaptrain.channel_view c
where s.product = 'ALL_PRODUCTS'
and s.geography = 'ALL_REGIONS'
and s.time = 'ALL_YEARS'
and s.channel = c.dim_key;