When to use Blobs in a Cassandra (and CQL) table and what are blobs exactly?

cassandra, cql

Solution

Blobs (Binary Large OBjectS) are the solution for when your data doesn't fit into the standard types provided by C*. For example, say you wanted to make a forum where users were allowed to upload files of any type. To store these in C* you would use a Blob column (or possibly several blob columns since you don't want individual cells to become to large).

Another example might be a table where users are allowed to have a current photo, this photo could be added as a blob and be stored along with the rest of the user information.

Problem

I was trying to understand better the design decision choice when making table entries in cassandra and when the blob type is a good choice. I realized I didn't really know when to choose a blob as a data type because I was not sure what a blob really was (or what the acronym stood for). Thus I decided to read the following documentation for the data type blob: http://www.datastax.com/documentation/cql/3.0/cql/cql_reference/blob_r.html Blob ``` Cassandra 1.2.3 still supports blobs as string constants for input (to allow smoother transition to blob constant). Blobs as strings are ``` now deprecated and will not be supported in the near future. If you were using strings as blobs, update your client code to switch to blob constants. A blob constant is an hexadecimal number defined by 0xX+ where hex is an hexadecimal character, such as [0-9a-fA-F]. For example, 0xcafe. ``` Blob conversion functions A number of functions convert the native types into binary data (blob). For every <native-type> nonblob type supported by CQL3, the ``` typeAsBlob function takes a argument of type type and returns it as a blob. Conversely, the blobAsType function takes a 64-bit blob argument and converts it to a bigint value. For example, bigintAsBlob(3) is 0x0000000000000003 and blobAsBigint(0x0000000000000003) is 3. What I got out of it is that its just a long hexadecimal/binary. However, I don't really appreciate when I would use it as a column type for a potential table and how its better or worse than other type. Also, going through some of its properties might be a good way to figure out what situations blobs are good for.

Original source