CQL In Cassandra 1.0 (and beyond)

26
CQL In Cassandra 1.0 (and beyond) Big Data DC Meetup #5 October 17, 2011 Eric Evans [email protected] @jericevans, @acunu

description

CQL, past, present, and future, presented to Big Data DC on October 17, 2011

Transcript of CQL In Cassandra 1.0 (and beyond)

Page 1: CQL In Cassandra 1.0 (and beyond)

CQL In Cassandra 1.0 (and beyond)

Big Data DC Meetup #5October 17, 2011

Eric [email protected]

@jericevans, @acunu

Page 2: CQL In Cassandra 1.0 (and beyond)

● Overview, history, motivation

● Changes in CQL 2.0 (Cassandra 1.0)

● Coming soon (?)

● Drivers status

Page 3: CQL In Cassandra 1.0 (and beyond)

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

Page 4: CQL In Cassandra 1.0 (and beyond)

SQL? Almost.

–- Inserts or updatesINSERT INTO Standard1 (KEY, col0, col1) VALUES (key, value0, value1)

vs.

–- Inserts or updatesUPDATE Standard1SET col0=value0, col1=value1 WHERE KEY=key

Page 5: CQL In Cassandra 1.0 (and beyond)

SQL? Almost.–- Get columns for a rowSELECT col0,col1 FROM Standard1 WHERE KEY=key

–- Range of columns for a rowSELECT col0..colN FROM Standard1 WHERE KEY=key

–- First 10 results from a range of columnsSELECT FIRST 10 col0..colN FROM Standard1 WHERE KEY=key

–- Invert the sorting of resultsSELECT REVERSED col0..colN FROM Standard1 WHERE KEY=key

Page 6: CQL In Cassandra 1.0 (and beyond)

Why?

Page 7: CQL In Cassandra 1.0 (and beyond)

Interface Instability

Page 8: CQL In Cassandra 1.0 (and beyond)

(Un)ease of useColumn 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)

Page 9: CQL In Cassandra 1.0 (and beyond)

CQL

INSERT INTO Standard1 (KEY, col0) VALUES (key, value0)

Page 10: CQL In Cassandra 1.0 (and beyond)

Why? How about...

● Better stability guarantees● Easier to use (you already know it)● Better code readability / maintainability

Page 11: CQL In Cassandra 1.0 (and beyond)

Why? How about...

● Better stability guarantees● Easier to use (you already know it)● Better code readability / maintainability● Irritates the NoSQL purists

Page 12: CQL In Cassandra 1.0 (and beyond)

Why? How about...

● Better stability guarantees● Easier to use (you already know it)● Better code readability / maintainability● Irritates the NoSQL purists● (Still )irritates the SQL purists

Page 13: CQL In Cassandra 1.0 (and beyond)
Page 14: CQL In Cassandra 1.0 (and beyond)

CQL 2.0

Page 15: CQL In Cassandra 1.0 (and beyond)

Wait, 2.0? You call that stable?

Yes yes, but...● We had a few FUBARs in the first pass● Not the norm, honest● It's a mulligan● Look, cats!

Page 16: CQL In Cassandra 1.0 (and beyond)

Changed in 2.0

● SELECT count(...) FROM now returns row, not column count

● Terms / Types● bytea became blob● int became 4-bytes (was arbitrary precision)● date became timestamp

Page 17: CQL In Cassandra 1.0 (and beyond)

Also new (but not breaking)

● Named keys (virtual columns)● Counters● Complete DDL support● Timestamps and TTLs

Page 18: CQL In Cassandra 1.0 (and beyond)

Named Keys

–- An unnamed key uses the KEY keywordCREATE TABLE Standard1 (KEY text PRIMARY KEY)

–- But you can also name one like so...CREATE TABLE Standard1 (username text PRIMARY KEY)

–- The name will also be used in results!SELECT email FROM Standard1 WHERE username = 'jericevans'

Page 19: CQL In Cassandra 1.0 (and beyond)

Counters

–- Counter incrementUPDATE Standard1SET acount = acount + 1 WHERE KEY = key

–- Counter decrementUPDATE Standard1SET acount = acount - 1 WHERE KEY = key

–- 1 not enough? Go nuts.UPDATE Standard1SET acount = acount + 9 WHERE KEY = key

Page 20: CQL In Cassandra 1.0 (and beyond)

Timestamps and TTLs

–- Inserts or updatesUPDATE CFam USING TIMESTAMP 131851901600SET col0=value0, col1=value1 WHERE KEY=key

–- Inserts or updatesUPDATE CFam USING TTL 86400SET col0=value0, col1=value1 WHERE KEY=key

Page 21: CQL In Cassandra 1.0 (and beyond)

Coming Soon(ish)

Page 22: CQL In Cassandra 1.0 (and beyond)

Roadmap

● Prepared statements (CASSANDRA-2475)

● Compound columns (CASSANDRA-2474)

● Custom transport / protocol (CASSANDRA-2478)

● Performance testing (CASSANDRA-2268)

● Schema introspection (CASSANDRA-2477)

● Multiget support (CASSANDRA-3069)

Page 23: CQL In Cassandra 1.0 (and beyond)

Drivers

Page 24: CQL In Cassandra 1.0 (and beyond)

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

Page 26: CQL In Cassandra 1.0 (and beyond)

The End