Cassandra Notes – 4

We are able to store shippment info and order-shipment info, and search shippment from order. How about search order from package? say, find the order from the package tracking number? It is not doable since in our “OrderShippedPackages” column family, the key is “order number”. One approach is to add order number to the “ShippedPackages”. We can add to the “row” along with the “Package super column”.
One Note – because our row in “ShippedPackages” contains Super-Column, so the Order-Number information must be wrapped in Super-Column too (I tried with Column and got exception)

Added below code to method “testAddOneShippedPackage”

				{
					//add the order number to the row too
					Column orderNumberColumn = new Column("order-number".getBytes("utf-8"),orderNumber.getBytes("utf-8"),timestamp);
					SuperColumn superOrderNumber = new SuperColumn();
					superOrderNumber.setName(orderNumber.getBytes("utf-8"));
					superOrderNumber.addToColumns(orderNumberColumn);
					ColumnOrSuperColumn c = new ColumnOrSuperColumn();
					c.setSuper_column(superOrderNumber);
					shippedPackageRow.add(c);
				}

Now run the “testShippedPackageContents” will get the order number from the super-column.

This is the thing about the No-SQL dbs – we must design our data model based on the operations.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s