business objects rathbun designer

49
Universe Models for Recursive Data David G. Rathbun BI Solutions Architect, PepsiCo B+IS

Upload: bharadwajach

Post on 18-Nov-2014

120 views

Category:

Documents


4 download

DESCRIPTION

This documents explains about business objects desinger

TRANSCRIPT

Page 1: Business Objects Rathbun Designer

Universe Models for Recursive Data

David G. RathbunBI Solutions Architect, PepsiCo B+IS

Page 2: Business Objects Rathbun Designer

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.

Page 3: Business Objects Rathbun Designer

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

Page 4: Business Objects Rathbun Designer

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

Page 5: Business Objects Rathbun Designer

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

Page 6: Business Objects Rathbun Designer

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

Page 7: Business Objects Rathbun Designer

72009 SAP BusinessObjects User Conference

Defining Recursion

RecursionSee "Recursion".

Or in other wordsIn order to understand recursion you must first understand

recursion

Google says

Page 8: Business Objects Rathbun Designer

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

Page 9: Business Objects Rathbun Designer

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

Page 10: Business Objects Rathbun Designer

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

Page 11: Business Objects Rathbun Designer

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

Page 12: Business Objects Rathbun Designer

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?

Page 13: Business Objects Rathbun Designer

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

Page 14: Business Objects Rathbun Designer

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

Page 15: Business Objects Rathbun Designer

152009 SAP BusinessObjects User Conference

Agenda

OverviewDefine recursionList the challengesPreview the solutions

ImplementationDetail the challengesReview the solutionsSee the results

Questions and Discussion

Page 16: Business Objects Rathbun Designer

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…

Page 17: Business Objects Rathbun Designer

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

Page 18: Business Objects Rathbun Designer

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

Page 19: Business Objects Rathbun Designer

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

Page 20: Business Objects Rathbun Designer

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

Page 21: Business Objects Rathbun Designer

212009 SAP BusinessObjects User Conference

Nightmare Hierarchy

A

B1 B2

C2 C3 C4C1

I hope you neverhave to deal withsomething likethis…

Challenge:Impossible!

Page 22: Business Objects Rathbun Designer

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

Page 23: Business Objects Rathbun Designer

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

Page 24: Business Objects Rathbun Designer

242009 SAP BusinessObjects User Conference

Universe Aliases Solution

Only recursive solution that can be done completely in theuniverse

Build aliases and query hierarchy

Page 25: Business Objects Rathbun Designer

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

Page 26: Business Objects Rathbun Designer

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

Page 27: Business Objects Rathbun Designer

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

Page 28: Business Objects Rathbun Designer

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

Page 29: Business Objects Rathbun Designer

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

Page 30: Business Objects Rathbun Designer

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

Page 31: Business Objects Rathbun Designer

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

Page 32: Business Objects Rathbun Designer

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

Page 33: Business Objects Rathbun Designer

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

Page 34: Business Objects Rathbun Designer

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

Page 35: Business Objects Rathbun Designer

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

Page 36: Business Objects Rathbun Designer

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

Page 37: Business Objects Rathbun Designer

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

Page 38: Business Objects Rathbun Designer

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);

Page 39: Business Objects Rathbun Designer

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

Page 40: Business Objects Rathbun Designer

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

Page 41: Business Objects Rathbun Designer

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

Page 42: Business Objects Rathbun Designer

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

Page 43: Business Objects Rathbun Designer

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

Page 44: Business Objects Rathbun Designer

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

Page 45: Business Objects Rathbun Designer

452009 SAP BusinessObjects User Conference

Overall Scorecard

Snowflake

Tree

AncestorFlatAlias

Lateral

Ragged

Unbalanced

Clean

Page 46: Business Objects Rathbun Designer

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

Page 47: Business Objects Rathbun Designer

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

Page 48: Business Objects Rathbun Designer

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

Page 49: Business Objects Rathbun Designer

492009 SAP BusinessObjects User Conference

Thank you for participating

Please remember to complete and returnyour evaluation form following this session.

SESSION CODE: 1012