business objects rathbun designer
DESCRIPTION
This documents explains about business objects desingerTRANSCRIPT
Universe Models for Recursive Data
David G. RathbunBI Solutions Architect, PepsiCo B+IS
22009 SAP BusinessObjects User Conference
Presentation Abstract
Recursive data can present a special challenge to SAPBusinessObjects developers because SQL is not nativelyable to process the relationships. This presentation willshow several different methods for modeling recursive dataalong with the pros and cons of each. All of the methodsshown have been used on real-world projects. Attendeeswill gain a better understanding of the complexities ofdealing with inventory models, organizational hierarchies,and other types of recursive data.
32009 SAP BusinessObjects User Conference
Learning Points
Review recursive data scenarios and discuss the difficultiesthey present to a Universe developer
Review various models that can be considered forrepresenting recursive data in a reporting environment
Review pros and cons of each model, all based on real-world implementations
42009 SAP BusinessObjects User Conference
About Dave
Dedicated to BusinessObjects solutions since 1995Consultant and trainer for fifteen yearsCurrently BI Solutions Architect for PepsiCo
14 consecutive years presenting at major BI conferencesUnited States, Europe, Australia
Charter member of BOBhttp://busobj.forumtopics.com
I Blog! Dave’s Adventures in Business Intelligencehttp://www.dagira.com
Selected to the SAP Mentor program for 2009
52009 SAP BusinessObjects User Conference
Demonstration Platform
Demonstration universesIsland Resorts MarketingeFashionPrestige MotorsDemonstration databases were converted to Oracle
Software configurationBusinessObjects Enterprise XI 3.0Oracle 10g
BusinessObjects toolsetWeb Intelligence Rich ClientUniverse Designer
Demonstration icon Additional demonstrations only if time allows
62009 SAP BusinessObjects User Conference
Agenda
OverviewDefine recursionList the challengesPreview the solutions
ImplementationDetail the challengesReview the solutionsSee the results
Questions and DiscussionComplex topic with many demonstrationsPlease hold questions until the end
72009 SAP BusinessObjects User Conference
Defining Recursion
RecursionSee "Recursion".
Or in other wordsIn order to understand recursion you must first understand
recursion
Google says
82009 SAP BusinessObjects User Conference
What is Recursive Data?
Hierarchical and self-referencing data often represented bya tree structureHierarchical because there are defined levelsSelf-referencing because primary and foreign keys are in the
same table
Hierarchical data is not a huge problemGeographical hierarchies: Country, State, CityTime hierarchies: Year, Quarter, Month
Recursion is a problemSQL is not a procedural language and does not offer native
recursive functionality
92009 SAP BusinessObjects User Conference
Recursive Data Is Quite Common
Company organizational structure Inventory BOM (Bill of Materials)Project management (WBS task structure)Multi-level marketing (Amway, Avon)Bernie Madoff’s investment strategy
102009 SAP BusinessObjects User Conference
Recursive Relationship From Prestige Motors HR
When a table joins to itselfthat is recursive data
This relationship says:A manager has one or
more employeesAn employee has zero or
one managerA person can be both an
employee and a managerdue to recursion
There is nothing toindicate how deep therecursion goes
112009 SAP BusinessObjects User Conference
Raw Data From Prestige Motors HR
LEVEL EMP_ID EMP_NAME---------- ---------- -----------------
1 101 Noakes2 102 Ferrerez3 103 Field2 104 Fraser2 105 Snow3 106 Speed3 107 Spencer2 108 Helen2 109 Thomas3 110 Thatcher2 111 Davis2 201 Pickworth3 202 Forest4 203 Brown4 209 Hilary3 204 Porter4 205 Irving4 206 Bailey3 207 Duckworth4 208 Ince2 301 Dagmar3 302 Presley4 303 Perry4 304 Hubert3 305 Adamson4 306 Beaver4 307 Motson
Max depth of 4Noakes does not have a
manager
122009 SAP BusinessObjects User Conference
Typical Recursive Questions
Company organization structureWho do I work for? Who works for me? What is the total
salary for my direct / indirect reports?
Inventory BOMWhere is this component used? What is required to build this
assembly? What is the total cost of the materials for thiscomponent?
Project managementWhat is the deliverable for this task? What are all of the
activities under this task? What is the total projected hours forthis deliverable?
132009 SAP BusinessObjects User Conference
Some Types of Hierarchies
CleanA hierarchy that has no issues or challenges
UnbalancedA hierarchy with inconsistent depths
RaggedA hierarchy with inconsistent node paths
LateralA hierarchy with sideways node paths
All of these will be defined with examples shortly
142009 SAP BusinessObjects User Conference
Methods of Handling Recursive Data
Universe aliasesFlattened structuresSingle table with column valuesSnowflake tables
Ancestor or Descendent ModelDepth First Tree TraversalAssign node “left” and “right” values
Some other methods not considered todayOracle CONNECT BYStored procedures
152009 SAP BusinessObjects User Conference
Agenda
OverviewDefine recursionList the challengesPreview the solutions
ImplementationDetail the challengesReview the solutionsSee the results
Questions and Discussion
162009 SAP BusinessObjects User Conference
Review Hierarchy Challenges
The following slides will visually demonstrate differentchallenges that can occur with recursive hierarchical dataCleanUnbalancedRaggedLateral
A picture is worth a thousand words…
172009 SAP BusinessObjects User Conference
Clean Hierarchy
A
B1 B2
C1 C2 C3 C4
Consistent depthNo missing nodesNo lateral
connectionsChallenge: None
A, B, and C represent different node types or levels in the hierarchy
For example, President, Vice President, and Division Manager
182009 SAP BusinessObjects User Conference
Unbalanced Hierarchy
A
B1 B2
C3 C4
Inconsistent depthOne branch of the tree is
not as long as the otherbranches
Consider a Vice Presidentof a company with no directreports
Challenge: Moderate
192009 SAP BusinessObjects User Conference
Ragged Hierarchy
A
B2
C2 C3 C4
Missing nodesData is missing from the
middle of a pathConsider a division
manager that reportsdirect to the presidentwithout going through aVP
Challenge: Difficult
B1
202009 SAP BusinessObjects User Conference
Lateral Hierarchy
A
B1 B2
C2 C3 C4
Lateral connectionsOne node relates
across the tree ratherthan up or down
Consider a lateralreport in a companyhierarchy
Challenge: VeryDifficult
C1
212009 SAP BusinessObjects User Conference
Nightmare Hierarchy
A
B1 B2
C2 C3 C4C1
I hope you neverhave to deal withsomething likethis…
Challenge:Impossible!
222009 SAP BusinessObjects User Conference
Combination
It is possible to havemore than one challengeto overcome
What are the solutions?Are there any best
practices forrepresenting recursivedata in a universe?
A
B2
C2 C3 C4
B1
232009 SAP BusinessObjects User Conference
Defining The Solutions
The next few slides will define each of the solutionsUniverse aliasesFlattened structure (Single or Snowflake)Ancestor / DescendentTree traversal
Most of these solutions cannot be completely solved withinthe universe
Require ETL to load specific data structuresEach solutions will be defined, demonstrated, and analyzed
for pros and cons
242009 SAP BusinessObjects User Conference
Universe Aliases Solution
Only recursive solution that can be done completely in theuniverse
Build aliases and query hierarchy
252009 SAP BusinessObjects User Conference
Universe Aliases Pros and Cons
ProsSelf-contained solution that does not require ETL
ConsDoes not handle lateral relationships at allMust use an outer join
Required for the top node of the treeRequired for unbalanced hierarchy
Must have an alias for each level of the hierarchyUniverse maintenance if levels are created or dropped
262009 SAP BusinessObjects User Conference
Universe Alias Scorecard
Cannot effectively represent a lateralrelationship with simple aliasesLateral
Cannot effectively represent missingnodes as there is no “bridge” to the nextlevel of the hierarchy
Ragged
An unbalanced hierarchy could be handledby making all of the joins outer joins butdrilling up from an undefined node fails
Unbalanced
The universe designer must know thedepth of the hierarchy in order to build thecorrect number of aliases but it works well
Clean
272009 SAP BusinessObjects User Conference
Flattened Structure Solutions
Data in rows is pivoted to columns
Columns can be converted to snowflake tables
Snowflake process is very similar to using aliases
282009 SAP BusinessObjects User Conference
Flattened Structure Columns Pros and Cons
ProsHandles unbalanced hierarchies better than aliasesMissing value is a null column rather than missing relationshipCan handle ragged hierarchies with “plug nodes”
ConsMust have a column defined for each levelUniverse and ETL maintenance if levels change
A plug node fills in missing values to represent the relationship
Level 1 » Level 1-3 Plug » Level 3
292009 SAP BusinessObjects User Conference
Flattened Structure Columns Scorecard
A flattened structure has no way to storetwo values in a single columnLateral
Drilling becomes a problem with raggedhierarchies; this can be addressed with agood “plug node” strategy
Ragged
Since everything to the maximumexpected depth has a column, unbalancednodes are simply null columns in a row
Unbalanced
Must know in advance how many levels toprocess, but a clean hierarchy works wellwhen flattened
Clean
Demonstrate flattened hierarchy
302009 SAP BusinessObjects User Conference
Flattened Structure Snowflake Pros and Cons
ProsSmaller storage requirementSome queries are more efficientEasier maintenance than single table
When new levels occur simply add a new table with samestructure
ConsMust have a table defined for each levelUniverse and ETL maintenance if levels changeSame outer join requirement as aliasesPlug nodes become “plug rows” which increases complexity
312009 SAP BusinessObjects User Conference
Flattened Structure Snowflake Scorecard
Just like a flattened row, a snowflakestructure cannot store two values at thesame level
Lateral
Just like aliases, a snowflake suffers fromragged nodes as the drill path is notcomplete
Ragged
Just like aliases, a snowflake suffers fromunbalanced nodes and would require outerjoins
Unbalanced
Must know in advance how many levels toprocess, but a clean hierarchy works wellwith snowflake tables
Clean
Demonstrate flattened snowflake hierarchy
322009 SAP BusinessObjects User Conference
Ancestor / Descendent Solution
One primary issue with recursion is the unknown depthThis model represents the entire tree – no matter how deep
– with the same data structureA user can start at any node of the treeThree types of dataAncestor is any starting node for the treeParent is a parent nodeDetail is a child node
Row structure skips generations but still maintains thestructural information
332009 SAP BusinessObjects User Conference
Building Ancestor Records
Ancestor table is populated using Oracle CONNECT BY orother recursive techniques
Demonstrate queries from ancestor hierarchy solution
342009 SAP BusinessObjects User Conference
Ancestor / Descendent Pros and Cons
ProsAnswers all of the typical recursion questionsDoes not require outer joinsDoes not require plug nodes
ConsDoes not support standard drilling techniqueInflates the row count
27 employees becomes 80 descendent recordsEach possible parent node is stored as an ancestor
May need to change objects to answer different questionsUse the ancestor to answer “Who do I work for?”Use the child to answer “Who works for me?”
Can’t generate proper tree output
352009 SAP BusinessObjects User Conference
Ancestor / Descendent Scorecard
Lateral nodes can be modeled by allowinga node and its parent to have the samelevel but it’s not a perfect solution
Lateral
Ragged hierarchies do not present aproblem because the node type is notimportant (preserved) in this structure
Ragged
Unbalanced hierarchies do not present aproblem as the rows are not createdUnbalanced
Can represent a clean hierarchy just finebut cannot recreate the tree structureClean
362009 SAP BusinessObjects User Conference
Tree Traversal Solution
Store the node relationships on each rowEach row gets a left and right node valueThese values are assigned based on a preorder or Depth
First tree traversal algorithmOptionally calculate and store the node level at the same time
Original data remains intactNo transformation is performed27 rows of employee data remains 27 rows
372009 SAP BusinessObjects User Conference
Tree Traversal Node Assignments
Graphical representation of node assignments by “walkingthe tree”
Tree traversal means walk around the outside edgeNumber each node each time you pass the left or right sideStore those values in the original source table
Noakes
Ferrerez Fraser Snow Pickworth
Forest Porter Duckworth
5 6
9 10
7 8 15
11 12 13 14
161
2 3 4
Note: This is not the complete tree
382009 SAP BusinessObjects User Conference
Tree Traversal Maintenance
Inserts and updates must adjust left and right values
Noakes
Ferrerez Fraser Snow Pickworth
Forest Porter Duckworth
5 6
9
10
7 8 17
11
14 15 16
181
2 3
New12 13
Update table set left = left + 2 where left >= 10;
Update table set right = right + 2 where right >= 10;
Insert (name, left, right) values (‘New’, 10, 11);
392009 SAP BusinessObjects User Conference
Using Tree Data
Who do I work for?Left < My Left and Right > My Right and Level = My Level - 1
Who are my direct descendants?Left > My Left and Right < My Right and Level = My Level + 1
Who are my indirect descendants?Left > My Left and Right < My Right and Level > My Level + 1
Who are all of my descendants?Left > My Left and Right < My Right
What is my level in the hierarchy?Provided directly by the table
Create a complete treeDisplay all records order by LEFT indent by LEVEL
402009 SAP BusinessObjects User Conference
Employee Hierarchy Tree
ID Full Name Left Tree Right Tree
101 Noakes, Nicholas 1 54
102 Ferrerez, Ferdinand 2 5
103 Field, Felicity 3 4
104 Fraser, Frank 6 7
105 Snow, Sara 8 13
106 Speed, Sonya 9 10
107 Spencer, Steve 11 12
108 Helen, Harrison 14 15
109 Thomas, Tom 16 19
110 Thatcher, Terry 17 18
111 Davis, Diana 20 21
201 Pickworth, Paul 22 39
202 Forest, Florence 23 28
203 Brown, Bella 24 25
204 Porter, Pete 29 34
205 Irving, Ira 30 31
206 Bailey, Ben 32 33
207 Duckworth, Dave 35 38
208 Ince, Ian 36 37
209 Hilary, Hibbs 26 27
Name Descendants Parents Level
Noakes, Nicholas 26 0 1
Ferrerez, Ferdinand 1 1 2
Field, Felicity 0 2 3
Fraser, Frank 0 1 2
Snow, Sara 2 1 2
Speed, Sonya 0 2 3
Spencer, Steve 0 2 3
Helen, Harrison 0 1 2
Thomas, Tom 1 1 2
Thatcher, Terry 0 2 3
Davis, Diana 0 1 2
Pickworth, Paul 8 1 2
Forest, Florence 2 2 3
Brown, Bella 0 3 4
Hilary, Hibbs 0 3 4
Porter, Pete 2 2 3
Irving, Ira 0 3 4
Bailey, Ben 0 3 4
Duckworth, Dave 1 2 3
Ince, Ian 0 3 4
412009 SAP BusinessObjects User Conference
Tree Traversal Pros and Cons
ProsSolves all four recursive challenges presented todayDoes not require inflated row count like ancestor model
ConsRequires scripts or triggers to maintain tree node valuesDoes not support native drilling processRequires the user to understand tree structure
422009 SAP BusinessObjects User Conference
Tree Traversal Scorecard
A tree can even handle lateral nodesbecause it leaves the nodes in place andfollows the relationship
Lateral
A tree can handle ragged nodes becausethe node type no longer defines thestructure
Ragged
A tree can handle unbalanced nodesbecause that branch simply stopsUnbalanced
A tree works very well with a cleanhierarchyClean
432009 SAP BusinessObjects User Conference
Drilling Considerations
Our expectation is that we will be able to drill on our dataDrilling is done from column to columnLevel 1 » Level 2 » Level 3
Some of the models discussed today are not drillableThese models leave the data in rows rather than columnsAncestorTree
Flattening pivots the hierarchyOther models leave the recursion in place but provide
enough information to build reportsUse the OpenDocument() function to drill on these models
442009 SAP BusinessObjects User Conference
Drilling Using OpenDocument()
The OpenDocument() function can be used to simulatedrillingNative drilling returns the entire cube to the reportOpenDocument() drilling requires a query refresh
ParametersStarting NodeDepth
Demonstrate drilling on a tree model using the OpenDocument() function
452009 SAP BusinessObjects User Conference
Overall Scorecard
Snowflake
Tree
AncestorFlatAlias
Lateral
Ragged
Unbalanced
Clean
462009 SAP BusinessObjects User Conference
Special Considerations
Ancestor model requires more disk spaceEach node exists as a parent with all of its childrenDuplicated data for maximum flexibility
Tree model requires most complex codingDon’t let the smiling faces on the prior slide fool youThis is a complex data model that can handle just about any
recursive structure, but…… the user experience is altered substantially
Drilling becomes a challengeNative drilling works on flattened or snowflakeOpenDocument() works on ancestor and tree
472009 SAP BusinessObjects User Conference
Questions and Discussion
This presentation will be posted on my blog after theconferenceAs time permits I will provide slide narration as blog posts
Author InformationDavid G. RathbunBI Solutions Architect, PepsiCo B+ISBI Blog www.dagira.com
482009 SAP BusinessObjects User Conference
Supporting Links
Interesting Wikipedia Linkshttp://en.wikipedia.org/wiki/Recursionhttp://en.wikipedia.org/wiki/Tree_traversal
Other linkshttp://articles.sitepoint.com/article/hierarchical-data-
database/1
492009 SAP BusinessObjects User Conference
Thank you for participating
Please remember to complete and returnyour evaluation form following this session.
SESSION CODE: 1012