Solving a Cartesian scenario in the Fact table

Hi,

  We have a DB2 OLTP environment which, we are planning to remodel to an OLAP in MS SQL Server 2008.

 In this, we have a scenario.
 Our fact table has Reference_ID, Contact_ID and Assignment_ID.
 Now, the relation is such that : Reference_ID to Contact_ID is 1--> N
                                                   Reference_ID to Assignment_ID is 1--> M
 and there is no direct relation between Contact_ID and Assignment_ID. So, we are getting a Cartesian result of M * N in our fact table.

How to solve this scenario and still keep the structure as a Star?

Please help.
pvsbandiAsked:
Who is Participating?
 
Kent OlsenConnect With a Mentor Data Warehouse Architect / DBACommented:
Keep in mind that the Cartesian should produce only valid rows.  

There are currently multiple assignments per referral, so the fact table should be based on assignments and referrals identified by a referral dimension table.  If there are other items with a 1 to many relationship, they should probably be in a separate fact table.  It perfectly OK to have dimension tables that are appropriate for multiple fact tables.
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi pvsbandi,

How are you generating the rows that will go in the fact table?  Build the fact table correctly and any Cartesian should work itself out in the dimension table(s).


Kent
0
 
pvsbandiAuthor Commented:
This query is building the Fact table only.
 When doing so, we see this Cartesian happening.
 
Example:

[b][u]Contact Dimension[/u][/b]

Ref ID          Contact_ID
123               AAA
123               BBB

[b][u]Assignment Dimension[/u][/b]

Ref ID        Assignment_ID
123               XXX
123               YYY
123               ZZZ

[b][u]Reference Dimension[/u][/b]

Ref ID        
123

[b][u]Fact Table[/u][/b]

Ref ID              Contact ID               Assignment ID
123                     AAA                         XXX
123                     BBB                         XXX
123                     AAA                         YYY
123                     BBB                         YYY
123                     AAA                         ZZZ
123                     BBB                         ZZZ                        

Open in new window

0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Kent OlsenData Warehouse Architect / DBACommented:
Still looks like a bad sub-query when you're building the fact table.

It appears that you're not just copying the OLTP generated transactions into the OLAP, you're modifying them by joining other data and selecting the desired columns.  The Cartesian is happening in the join of the other data.
0
 
pvsbandiAuthor Commented:
Hi Kent,

   Yes. Because, we wanted the Fact table to host all this information of this granularity and thus, maintain the Star schema.

Is there a way to break this Cartesian?
0
 
Kent OlsenData Warehouse Architect / DBACommented:
I'm sure that there is.  But without seeing the SQL there's not much help that I can offer other than to isolate where the Cartesian is occurring.
0
 
pvsbandiAuthor Commented:
Here is the SQL populating the fact. Problem is with the Assignment_ID and Contact_ID, which are not linked directly..so produce N * M cartesian.

SELECT          R.REFERRAL_ID,
                ASN.ASSIGNMENT_ID,
                ASN.ASSIGN_TO_STAFF_ID,
                ASN.START_DT AS ASSIGNMENT_START_DT, 
                ASN.END_DT AS ASSIGNMENT_END_DT, 
                RC.CLIENT_ID,
                CT.CONTACT_ID
FROM TB_REFERRAL R
INNER JOIN TB_ASSIGNMENT  ASN ON (R.REFERRAL_ID = ASN.ENTITY_KEY_ID)
LEFT OUTER JOIN TB_REFERRAL_CLIENTS RC ON (R.REFERRAL_ID = RC.REFERRAL_ID)
LEFT OUTER JOIN TB_CLIENT_ROLES CR ON (RC.REFERRAL_CLIENT_ID = CR.REFERRAL_CLIENT_ID)
LEFT OUTER JOIN 
FROM TB_CONTACT CT ON (R.REFERRAL_ID = CT.ENTITY_KEY_ID)
WHERE 
                R.DELETE_SW = 'N' 
                AND RC.DELETE_SW = 'N' 
                AND CR.DELETE_SW = 'N' 
                AND CR.ROLE_CD = '2085'

Open in new window

0
 
Kent OlsenData Warehouse Architect / DBACommented:
I doubt that the assignment_join by ID is causing the Cartesian.  Intuitively, each assignment will have a unique ID, so unless the ID column isn't really and ID, there should be a duplicated ID value in tb_assignment.

Contact, however, looks like the real culprit.  We're walking through several other tables to join tb_contact.

tb_referral -> tb_referral_clients
tb_referral_clients -> tb_client_roles
tb_client_roles -> tb_contact

My best guess from the information at hand is that the first join works fine (1 to 1) but that clients can have multiple roles, so a Cartesian is generated when joining tb_client_roles.

Does that sound right to you?
0
 
pvsbandiAuthor Commented:
We have restricted the role to '2085'..so, no issue there. So is with other tables.


 But becasue, we can have multiple assignments for each referral.
Also can have multiple contacts for each referral.
So, for each referral, we get a cartesian between Assignment and Contact.
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Then the Cartesian is essentially correct.

It looks like your definition has the Referral/Assignment as the basic unit within the fact table.  

Because you have multiple rows making up the row that you're trying to store in the fact table, you need to aggregate those multiple rows, and lose the detail that makes up the aggregation, or modify your definition of the fact table to include all the rows of the Cartesian product.

My choice would probably be to avoid the aggregation and store all of the rows.  Leave the aggregation up to the Dimension tables.


Kent
0
 
pvsbandiAuthor Commented:
Thanks.. that's what we are ending up doing.. keeping the fact as is..
and adding indicators in the dimensions to identify the latest and earliest.


But i still feel that the fact table shouldn't have cartesian.. we can may still be able to accommodate a M X M join, but a join-less result would not be desirable.
0
 
pvsbandiAuthor Commented:
Thanks, Kent!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.