Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Cassandra Wiki" for 
change notification.

The "ThomasBoose/EERD model components to Cassandra Column family's" page has 
been changed by ThomasBoose.
http://wiki.apache.org/cassandra/ThomasBoose/EERD%20model%20components%20to%20Cassandra%20Column%20family%27s?action=diff&rev1=3&rev2=4

--------------------------------------------------

  If it is necessary to use different keys for both collections, sometimes it 
is not up to one designer to select both keys, although the number of element 
are equal and they are related one on one, in a relational model the designer 
gets to select either key to insert into the other collection with an unique 
and foreign key constraint.
  
  In Cassandra modeling you are forced to either croslink both key's, So you'd 
design both key's foreign in both ColumnFamily's. Or you create a third 
ColumnFamily in which you store both keys preceded by a token to which 
columfamily you are refering. Lets focus on the first option. Say we hand out 
phones to our employees and we agree that every employee will always have one 
phone. and phones that are not used are not stored in our database. The phone 
has a phonenumber as key where the employee has a social security number. In 
order to know which number to dial when looking for employee X and who is 
calling giving a specific phonenumber we need to store both keys foreign in 
both ColumnFamily's.
- 
- 
- ||<tablewidth="400px">'''CF_Employee'''||
+ ||||||||<tablewidth="400px">'''CF_Employee''' ||
- ||<|2>123-12-1234||name||phone||salary||
+ ||<style="text-align: center;" |2>123-12-1234 ||name ||phone ||salary ||
- ||John||0555-123456||10.000||
+ ||John ||0555-123456 ||10.000 ||
- ||<|2>321-21-4321||name||phone||salary||
+ ||<style="text-align: center;" |2>321-21-4321 ||name ||phone ||salary ||
- ||Jane||0555-654321||12.000||
+ ||Jane ||0555-654321 ||12.000 ||
- 
- 
- ||||||<tablewidth="400px" tablealign="left">'''CF_Phone'''||
- ||<|2>0555-123456||employee||credit||
- ||123-12-1234||10||
- ||<|2>0555-654321||employee||credit||
- ||321-21-4321||5||
  
  
  
- 
+ ||||||<tablewidth="400px" tablestyle="text-align: left;"style="text-align: 
center;">'''CF_Phone''' ||
+ ||<style="text-align: center;" |2>0555-123456 ||employee ||credit ||
+ ||123-12-1234 ||10 ||
+ ||<style="text-align: center;" |2>0555-654321 ||employee ||credit ||
+ ||321-21-4321 ||5 ||
  
  
  
@@ -71, +66 @@

        raise error or delete specified employee
  }}}
  ==== Subset elements ====
- ''.... ''
+ One on one relationships with one collection being smaller, in fact being a 
subset of the other collections in relational systems are solved by adding the 
key of the larger collection as foreign key to the smaler one. Preferably one 
uses the same key values as decribed above. This way we prevent null values 
that are not strictly indicating an unknown value. Null value's should only 
meen "We know there is a value but the value is unknown" as we've all learned 
in school.
  
+ As stated we prefer the foreign key to be the same value as the key from the 
superset ColumnFamily. In every other case we'll have to introduce logic to 
keep the relation cosistent. In any case you have to enforce the existance of 
all keys in the subset in the superset. Logic must also be provided when 
deleting elements from the superset with respect to the related element in the 
subset.
+ 
+ ==== Overlap ====
+ The easiest one on one relation to implement is the one in which elements in 
both collections do not need to be in the other but might. If at all possible 
create one big super ColumnFamily that collects all elements from both 
collections, even if there is no corresponding attribute (column). If absolutly 
neccessary you can provide keys from either ColumnFamily if the values are not 
the same but one on one related. See above for contraint considerations.
+ 
+ === 1 to Many ===
+ In one to many relationships we add the key from the "one" side foreign to 
the "many" side. So if we're modelinng students studing at only one school-unit 
at a time we would add the unit's key to the student as foreign. Considering 
that no foreign key logic is provided you will have to write your own code to 
enforce consistancy in unit's existing when the unit attribute of a student is 
set and defining behaviour when deleting a unit. Cosiddering the fact that this 
kind of relation is very common one could best create the logic for this at a 
seperate DBMS tier.
+ 
+ Every student has only one school-unit so we enforce one static name of a 
column that will reference this unit. for instance this column in the 
cf_Student columnfamily is called "school-unit". In a cassandra database this 
is not sufficient to retrieve all student within this unit. One could find 
answers to questions like these but it would require quite a lot of processing 
power. If a ColumnFamily, the cf_School_unit family in this case, has only one 
of these relations, then one could chose to add all student keys to that 
ColumnFamily it self. I would not count on this situation persisting in future 
releases of you system and therefore sugest that you'de provide seperate 
ColumnFamily's for each one to many relationship that you model.
+ 
+ This would leed to three columnFamily's
+ 
+ ||||||||<tablewidth="400px">'''CF_Student''' ||
+ ||<style="text-align: center;" |2>123-12-1234 ||name ||unit ||city ||
+ ||John ||SE ||the hague ||
+ ||<style="text-align: center;" |2>321-21-4321 ||name ||unit ||city ||
+ ||Jane ||SE ||Amsterdam ||
+ 
+ 
+ ||||||<tablewidth="400px" tablestyle="text-align: left;"style="text-align: 
center;">'''CF_School_Unit''' ||
+ ||<style="text-align: center;" |2>SE ||name ||loc ||
+ ||software engineering ||hsl ||
+ 
+ 
+ ||||||<tablewidth="400px" tablestyle="text-align: left;"style="text-align: 
center;">'''CFK_School_Unit_Student''' ||
+ ||<style="text-align: center;" |2>SE ||123-12-1234 ||321-21-4321 ||
+ || || ||
+ 
+ 
+ No value's are actualy stored in the columns indicating de studentnumbers. 
These columns only exist to indicate which students are present in this unit.
+ 

Reply via email to