activepivot

Relational Stores & Many-to-one joins


David, could I ask for some clarification on what you say about joins in this answer

When you say "You cannot, using the join of the relational stores, join one entry to multiple ones", does that mean in any direction?

E.g. Store 1:

| Key1 | Measure1 |

Store 2:

| Key 1 | SomeId1 | Measure2 | Measure3 |
| Key 1 | SomeId2 | Measure4 | Measure4 |

So is it not possible to join these two stores by putting the join from Store 2 to Store 1?

And if not, are you saying then that the only way to manage this is to duplicate the entries in Store 1? E.g.:

Store 1
| Key 1 | SomeId1 | Measure1 | Measure2 | Measure3 |
| Key 1 | SomeId2 | Measure1 | Measure4 | Measure4 |

Solution

  • The direction matters for the one-to-many : it depends which store is the "parent" one.

    The relational stores includes the concept of an "ActivePivot Store" which is your main store (on which your schema is based). This store can then be joined to one or more stores, given a set of key fields, that we'll call "child" stores for simplicity. Each of these child stores can eventually be joined with other stores, and so on (you can represent it with a directed graph).

    The main rule to respect is that you should never have a "parent" store entry resolving to multiple "child" store entries (neither should you have any cyclic relationship I believe).

    The simplified idea behind the relational stores (as of RS 1.5.x / AP 4.4.x) is that when one entry is submitted into the "ActivePivot Store" then, starting from the ActivePivot Store, it'll recursively resolve the joins in order to retrieve maximum one entry in each of the joined stores. Depending of your schema definition, these entries will then be used to populate the fact before inserting it in the cube.

    If resolving a join result in more than one entry then AP will not be able to choose which one to use in order to populate the fact and will throw an exception.

    Coming back to your example you can do the join between Store 1 and Store 2 only in the case where Store 2 is your ActivePivot Store or a "parent" of Store 1 (APStore->...->Store2->Store1), which seems to be your case.

    If not (Store1->Store2) you will then have to duplicate the entries of Store 1 in order to ensure that it will always find only one entry at maximum when resolving the join. Store 1 will then looks like:

    | Key 1 | SomeId1 | Measure1 
    | Key 1 | SomeId2 | Measure1 
    

    Your join with Store 2 will then be done on the fields "Key, SomeId" instead of just "Key" and that will ensure you to find only one entry when resolving Store1->Store2