|CQL data modeling|
Internally, CQL does not change the row and column mapping from the Thrift API mapping. CQL and Thrift use the same storage engine. CQL supports the same query-driven, denormalized data modeling principles as Thrift. Existing applications do not have to be upgraded to CQL. The CQL abstraction layer makes CQL easier to use for new applications. For an in-depth comparison of Thrift and CQL, see "A Thrift to CQL Upgrade Guide" and CQL for Cassandra experts.
You can create legacy (Thrift/CLI-compatible) tables in CQL using the COMPACT STORAGE directive. The compact storage directive used with the CREATE TABLE command provides backward compatibility with older Cassandra applications; new applications should generally avoid it.
Compact storage stores an entire row in a single column on disk instead of storing each non-primary key column in a column that corresponds to one column on disk. Using compact storage prevents you from adding new columns that are not part of the PRIMARY KEY.
Using CQL, you can query a legacy table. A legacy table managed in CQL includes an implicit WITH COMPACT STORAGE directive. A table contains a timestamp representing the date/time that a write occurred to a columns. You use WRITETIME in the select expression to get this timestamp. For example, to get the date/times that a write occurred to the body column:
SELECT WRITETIME (title ) FROM songs WHERE id = 8a172618-b121-4136-bb10-f665cfc469eb; writetime (title ) ------------------ 1353890782373000
The output in microseconds shows the write time of the data in the title column of the songs table.
When you use CQL to query legacy tables with no column names defined for data within a partition, Cassandra generates the names (column1 and value1) for the data. Using the CQL RENAME clause, you can change the default column name to a more meaningful name.
ALTER TABLE users RENAME userid to user_id;
CQL supports dynamic tables created in the Thrift API, CLI, and earlier CQL versions. For example, a dynamic table is represented and queried like this:
CREATE TABLE clicks ( userid uuid, url text, timestamp date PRIMARY KEY (userid, url ) ) WITH COMPACT STORAGE; SELECT url, timestamp FROM clicks WHERE userid = 148e9150-1dd2-11b2-0000-242d50cf1fff; SELECT timestamp FROM clicks WHERE userid = 148e9150-1dd2-11b2-0000-242d50cf1fff AND url = 'http://google.com';
In these queries, only equality conditions are valid.