Database Reference
In-Depth Information
NOTE
This limitation was discovered by Ryan King, the Cassandra lead at Twitter. It might be fixed in a future
release, but the change is pending an update to the underlying storage file (the SSTable).
You can use a composite key of your own design to help you with queries. A composite key
might be something like <userid:lastupdate> .
This could just be something that you consider when modeling, and then check back on later
when you come to a hardware sizing exercise. But if your data model anticipates more than
several thousand subcolumns, you might want to take a different approach and not use super
columns. The alternative involves creating a composite key. Instead of representing columns
within a super column, the composite key approach means that you use a regular column family
with regular columns, and then employ a custom delimiter in your key name and parse it on client
retrieval.
Here's an example of a composite key pattern, used in combination with an example of a Cas-
sandra design pattern I call Materialized View, as well as a common Cassandra design pattern I
call Valueless Column:
HotelByCity (CF) Key: city:state {
key: Phoenix:AZ {AZC_043: -, AZS_011: -}
key: San Francisco:CA {CAS_021: -}
key: New York:NY {NYN_042: -}
}
There are three things happening here. First, we already have defined hotel information in anoth-
er column family called Hotel . But we can create a second column family called HotelByCity
that denormalizes the hotel data. We repeat the same information we already have, but store it
in a way that acts similarly to a view in RDBMS, because it allows us a quick and direct way
to write queries. When we know that we're going to look up hotels by city (because that's how
people tend to search for them), we can create a table that defines a row key for that search.
However, there are many states that have cities with the same name (Springfield comes to mind),
so we can't just name the row key after the city; we need to combine it with the state.
We then use another pattern called Valueless Column. All we need to know is what hotels are in
the city, and we don't need to denormalize further. So weusethecolumn'snameasthevalue,
and the column has no corresponding value. That is, when the column is inserted, we just store
an empty byte array with it.
Search WWH ::




Custom Search