Database Reference
In-Depth Information
Java equi-
valent
CQL type
Description
timeuuid UUID
Type 1 UUID only
TupleType Cassandra 2.1 and later; a group of 2-3 fields (Java type: com.datastax.driver.core.TupleType )
tuple
uuid
UUID
A UUID in the standard UUID format
varchar
String
UTF-8 encoded string
BigInteger Arbitrary-precision integer (Java type: java.math.BigInteger )
varint
Apart from these data types, you can mix and match these data types to create your own
data type much like a struct in the C language. We will see this later in this chapter when
we discuss CQL3.
The primary index
A primary key or row key is the unique identifier of a row, in much the same way as the
primary key of a table from a relational database system. It provides quick and random ac-
cess to the rows. Since the rows are sharded (distributed) among the nodes, and each node
just has a subset of rows, the primary keys are distributed too. Cassandra uses the parti-
tioner (cluster-level setting) and replica placement strategy (keyspace-level setting) to loc-
ate the nodes that own a particular row. On a node, an index file and sample index is
maintained locally and can be looked up via binary search followed by a short sequential
read. (For more information, refer to Chapter 2 , Cassandra Architecture .)
The problem with primary keys is that their location is governed by partitioners. Partition-
ers use a hash function to convert a row key into a unique number (called token ) and then
read/write happens from the node that owns this token. This means that if you use a parti-
tioner that does not use a hash that follows the key's natural ordering, chances are that you
can't sequentially read the keys just by accessing the next token on the node.
The following code snippet shows an example of this. The row keys 1234 and 1235
should naturally fall next to each other if they are not altered (or if an order preserving
partitioner is used). However, if we take a consistent MD5 hash of these values, we can
see that the two values are far away from each other. There's a good chance that they
Search WWH ::




Custom Search