3. What?
● Cassandra Query Language
● aka CQL
● aka /ˈsēkwəl/
● Exactly like SQL (except where it's not)
● Introduced in Cassandra 0.8.0
● Ready for production use
4. SQL? Almost.
–- Inserts or updates
INSERT INTO Standard1 (KEY, col0, col1)
VALUES (key, value0, value1)
vs.
–- Inserts or updates
UPDATE Standard1
SET col0=value0, col1=value1 WHERE KEY=key
5. SQL? Almost.
–- Get columns for a row
SELECT col0,col1 FROM Standard1 WHERE KEY=key
–- Range of columns for a row
SELECT col0..colN
FROM Standard1 WHERE KEY=key
–- First 10 results from a range of columns
SELECT FIRST 10 col0..colN
FROM Standard1 WHERE KEY=key
–- Invert the sorting of results
SELECT REVERSED col0..colN
FROM Standard1 WHERE KEY=key
8. (Un)ease of use
Column col = new Column(ByteBuffer.wrap(“name”.getBytes()));
col.setValue(ByteBuffer.wrap(“value”.getBytes()));
col.setTimestamp(System.currentTimeMillis());
ColumnOrSuperColumn cosc = new ColumnOrSuperColumn();
cosc.setColumn(col);
Mutation mutation = new Mutation();
Mutation.setColumnOrSuperColumn(cosc);
List mutations = new ArrayList<Mutation>();
mutations.add(mutation);
Map mutations_map = new HashMap<ByteBuffer, Map<String, List<Mutation>>>();
Map cf_map = new HashMap<String, List<Mutation>>();
cf_map.set(“Standard1”, mutations);
mutations.put(ByteBuffer.wrap(“key”.getBytes()), cf_map)
19. Hotspot
Quoted string literals
UPDATE table SET 'name' = 'value'
WHERE KEY = 'somekey'
20. Hotspot
Quoted string literals
UPDATE table SET 'name' = 'value'
WHERE KEY = 'somekey'
21. Hotspot
Quoted string literals
UPDATE table SET 'name' = 'value'
WHERE KEY = 'somekey'
● Anything that appears between quotes
● Inlined Java constructs a StringBuilder to store
the contents (slow not fast)
● Incurred multiple times per statement
22. Hotspot
Marshalling
UPDATE table SET 'clear' = 'abffaadd10'
WHERE KEY = 'acfe12ff'
23. Hotspot
Marshalling
UPDATE table SET 'clear' = 'abffaadd10'
WHERE KEY = 'acfe12ff'
ascii blob
24. Hotspot
Marshalling
UPDATE table SET 'clear' = 'abffaadd10'
WHERE KEY = 'acfe12ff'
ascii blob
● Terms are marshalled to bytes by type
● String.getBytes is slow (AsciiType)
● Hex conversion is fast faster (BytesType)
● Incurred multiple times per statement
25. Hotspot
Copying / Conversion
execute_cql_query(
ByteBuffer query, enum compression)
● Query is binary to support compression (is it worth it?)
● And don't forget the String → ByteBuffer conversion on
the client-side
● Incurred only once per statement!
26. Achtung!
(These tests weren't perfect)
● Uneeded String → ByteBuffer → String
● No query compression implemented
● Co-located client and server
35. Drivers
● Hosted on Apache Extras (Google Code)
● Tagged cassandra and cql
● Licensed using Apache License 2.0
● Conforming to a standard for database
connectivity (if applicable)
● Coming soon, automated testing and
acceptance criteria
36. Drivers
Driver Platform Status
cassandra-jdbc Java Good
cassandra-dbapi2 Python Good
cassandra-ruby Ruby New
cassandra-pdo PHP New
cassandra-node Node.js Good
http://code.google.com/a/apache-extras.org/hosting/search?q=label%3aCassandra