23830

Apache Cassandra schema design

Question:

I have following setup:<br /> Have CF items and CF keywords.<br /> Each item have zero, one or more keywords, stored in columns.<br /> Each keyword have one or more items, stored in columns.<br /> It looks like this:

items { dl { name => DELL6400, keyword:1 => computer, keyword:2 => DELL, keyword:3 => topseller } hp { name => HP12345, keyword:1 => computer, keyword:2 => HP } no { name => Nokia8210, keyword:1 => phone, keyword:2 => NOKIA } } <i>// here I store keys of the items only, // in reality I have denormalized most of items columns</i> keywords{ computer { webpage => www.domain.com/computer , item:dl => dl , item:hp => hp } DELL { webpage => www.domain.com/dell , item:dl => dl } topseller { webpage => www.domain.com/top , item:dl => dl } HP { webpage => www.domain.com/hp , item:hp => hp } NOKIA { webpage => www.domain.com/nokia , item:no => no } phone { webpage => www.domain.com/phone , item:no => no } }

when I add new item, I am adding "webpage" column in keywords if neccessary.<br /> when I am removing an item, I am removing column "item:xx" as well question is how to avoid "empty" keywords such if I remove nokia item "no":<br />

keywords{ ... NOKIA { webpage => www.domain.com/nokia } phone { webpage => www.domain.com/phone } }

I can count slice item:*, but because of eventual consistency this will be probably wrong aproach.

Answer1:

You can add a CounterColumn (http://wiki.apache.org/cassandra/Counters) to keywords CF. Increment it when adding an item to the keyword, and decrement on removal:

keywords{ computer { webpage => www.domain.com/computer , count => 2 , item:dl => dl , item:hp => hp } .... }

When reading a row with count == 0, just treat it as deleted. You shouldn't actually delete the 'webpage' column if you read the row with count == 0, since there might be concurrent add operation.

Answer2:

this is interesting, but I though about other way - to denormalize the "webpage" thing, e.g.:

[code]

keywords{ computer { webpage:dl => www.domain.com/computer , item:dl => dl , webpage:dl => www.domain.com/computer , item:hp => hp } DELL { webpage:dl => www.domain.com/dell , item:dl => dl } topseller { webpage:dl => www.domain.com/top , item:dl => dl } HP { webpage:hp => www.domain.com/hp , item:hp => hp } NOKIA { webpage:no => www.domain.com/nokia , item:no => no } phone { webpage:no => www.domain.com/phone , item:no => no } }

[/code]

in such case when i delete item:xx, i delete webpage:xx as well, and row is auto-removed (ghost) if there is no fields there. However I am still not sure if this is such a bright idea.

Recommend

  • how to use “if” statements inside pipeline
  • Accessing caller information quickly
  • I am having Directx 11 but WDDM 1.0 ? how to update it to WDDM 1.1? [duplicate]
  • Intercept incoming SMS
  • QAugmentedReality on BB10
  • visual studio fatal error LNK1120:
  • OpenCL bytecode running on another card
  • Excel - import data from an online xls file daily
  • Which video formats to use for Java ME in mobile phones?
  • Phonegap Android App, open links within app?
  • Using self.id to populate other fields in Django
  • How to process binary stream in Wicket like Servlet?
  • How to Update model and database with code first approach in Asp.net MVC
  • Android - Call default browser with and redirect to a designated url
  • Removing event listeners on automatically created multiple elements
  • How to convert WPF project so it can be used as a class library by a separate exe
  • Making Cross Site Asynchronous HTTP Post from GWT Client
  • CKeditor stripping font tags instead of converting to span
  • Changing media screen makes div overlay
  • ckeditor and jquery UI dialog not working
  • How can I tell a form not to dispose a particular control when it closes?
  • WPF version of .ScaleControl?
  • jwtBearer bearer token with rc-1 update to ASP.Net 5
  • SonarQube: Cannot deactivate rule with missing quality profile
  • Remove changes from one element when event occurs on another element?
  • Should I or shouldn't I use the CachingConnectionFactory with hornetq 2.4.1
  • Remove final comma from string in vb.net
  • Email verification using google app script and google forms
  • How do I change content of ComboFieldEditor?
  • Optimizing database types to compact database (SQLite)
  • Cross-Platform Protobuf Serialization
  • Check if a string to interpolate provides expected placeholders
  • Javascript + PHP Encryption with pidCrypt
  • Weird JavaScript statement, what does it mean?
  • Do I've to free mysql result after storing it?
  • VB.net deserialize, JSON Conversion from type 'Dictionary(Of String,Object)' to type '
  • SQL merge duplicate rows and join values that are different
  • How do you join a server to an Active Directory (domain)?
  • Turn off referential integrity in Derby? is it possible?
  • git trying to push non-existent file … after clearing cache