Your SlideShare is downloading. ×
Cassandra EU 2012 - CQL: Then, Now and When by Eric Evans
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Cassandra EU 2012 - CQL: Then, Now and When by Eric Evans

2,736
views

Published on

Eric Evans' talk about the latest on CQL given at Cassandra Europe on March 28 2012.

Eric Evans' talk about the latest on CQL given at Cassandra Europe on March 28 2012.

Published in: Technology

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,736
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
53
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. CQL: Then, Now, and When Eric Evans eric@acunu.com Cassandra Europe March 28, 2012Wednesday, March 28, 12
  • 2. Cassandra Query Language (aka CQL) • Query language for Apache Cassandra • SQL for the most part • An alternative query interface • Available since Cassandra 0.8.0Wednesday, March 28, 12
  • 3. Wednesday, March 28, 12
  • 4. Wednesday, March 28, 12
  • 5. Best Troll Ever?Wednesday, March 28, 12
  • 6. Not a troll at all, actually.Wednesday, March 28, 12
  • 7. Status Quo • RPC-based query interface • Low level; very little abstraction • Implemented in Thrift • Compact binary serialization • Loads of supported languages • Generated language codeWednesday, March 28, 12
  • 8. Unstable $@#*! Relax NOT AGAIN! It’ll take you 5 minutes to update your code.Wednesday, March 28, 12
  • 9. Not User FriendlyWednesday, March 28, 12
  • 10. This cannot be unseen! // Your column Column col = new Column(ByteBuffer.wrap(“name”.getBytes())); col.setValue(ByteBuffer.wrap(“value”.getBytes())); col.setTimestamp(System.currentTimeMillis()); // Don’t ask ColumnOrSuperColumn cosc = new ColumnOrSuperColumn(); cosc.setColumn(cosc); // Hang on, here we go... Mutation mutation = new Mutation(); mutation.setColumnOrSuperColumn(cosc); List<Mutation> mutations = new ArrayList<Mutation>(); mutations.add(mutation); Map mutations_map = new HashMap<ByteBuffer, Map<String, List<Mutation>>>(); Map cf_map = new Map<String, List<Mutation>>(); cf_map.set(“Standard1”, mutations); mutations_map.put(ByteBuffer.wrap(“key”.getBytes()), cf_map); cassandra.batch_mutate(mutations_map, consistency_level);Wednesday, March 28, 12
  • 11. This cannot be unseen! // Your column Column col = new Column(ByteBuffer.wrap(“name”.getBytes())); col.setValue(ByteBuffer.wrap(“value”.getBytes())); col.setTimestamp(System.currentTimeMillis()); // Don’t ask ColumnOrSuperColumn cosc = new ColumnOrSuperColumn(); cosc.setColumn(cosc); // Hang on, here we go... Mutation mutation = new Mutation(); mutation.setColumnOrSuperColumn(cosc); List<Mutation> mutations = new ArrayList<Mutation>(); mutations.add(mutation); Map mutations_map = new HashMap<ByteBuffer, Map<String, List<Mutation>>>(); Map cf_map = new Map<String, List<Mutation>>(); cf_map.set(“Standard1”, mutations); mutations_map.put(ByteBuffer.wrap(“key”.getBytes()), cf_map); cassandra.batch_mutate(mutations_map, consistency_level);Wednesday, March 28, 12
  • 12. A query interface should be... Simple Intuitive Invisible Performant(?)Wednesday, March 28, 12
  • 13. Alternatives • REST • RPC (Thrift, Avro, Protobuf, etc) • SQL (bahahaha) • etc, etcWednesday, March 28, 12
  • 14. REST Pros Cons • Ubiquitous • Fails expectations • Frequently requested • Slow • Client uniformityWednesday, March 28, 12
  • 15. RPC Pros Cons • Easy to implement • Poor mental fit • Performant • Heavy dependencyWednesday, March 28, 12
  • 16. SQL Pros Cons • Ubiquitous • People whinging • Widely known • Security(?) • Excellent mental fit • Client uniformityWednesday, March 28, 12
  • 17. SQL Pros Cons • Ubiquitous • People whinging • Widely known • Security(?) • Excellent mental fit • Client uniformityWednesday, March 28, 12
  • 18. Wednesday, March 28, 12
  • 19. Hello... -- Create or update INSERT INTO users (id, given, surname) VALUES (jericevans, Eric, Evans); -- Create or update UPDATE users SET given = Eric, surname = Evans WHERE id = jericevans; SELECT surname, given FROM users WHERE id = jericevans;Wednesday, March 28, 12
  • 20. ...is it me you’re looking for? -- Adding an index CREATE INDEX surnameidx ON users (surname); SELECT id, given FROM users WHERE surname = Evans; -- Limiting the number of rows SELECT id, given FROM users WHERE surname = Evans LIMIT 1000;Wednesday, March 28, 12
  • 21. Querying column ranges -- From column, to column SELECT ‘2012-01-01’..’2012-03-28’ FROM News WHERE topic = cassandra -- Last N columns SELECT FIRST 10 REVERSED * FROM News WHERE topic = cassandraWednesday, March 28, 12
  • 22. Counting -- Get your count on UPDATE inventory SET apples = apples + 1 WHERE id = fruit; UPDATE inventory SET carrots = carrots - 1 WHERE id = vegetable;Wednesday, March 28, 12
  • 23. Batching writes BEGIN BATCH INSERT INTO msgs (owner, subject, body) VALUES(jericevans, ‘Hi’, ‘Howdy’); UPDATE subjects SET subject = now WHERE owner = jericevans APPLY BATCHWednesday, March 28, 12
  • 24. A query interface should be... Simple Intuitive Invisible Performant(?)Wednesday, March 28, 12
  • 25. Drivers • Not a replacement for high-level, idiomatic libraries • Avoids duplicating efforts, (error handling, pooling, etc) • Consistently scoped, JDBC, etc • Consistently hosted, licensed • Discoverable • More work needed...Wednesday, March 28, 12
  • 26. Current lineup • JDBC (Java) • DB-API 2 (Python) • PDO (PHP) • Ruby • Node.JSWednesday, March 28, 12
  • 27. And what about interface stability?Wednesday, March 28, 12
  • 28. CQL 1.0 0. 8. 0Wednesday, March 28, 12
  • 29. CQL 2.0 0. 1. 8. 0. 0 0 • types made more consistent w/ SQL • count() returns rows, not columnsWednesday, March 28, 12
  • 30. Wednesday, March 28, 12
  • 31. CQL 3.0 0. 1. 1. 8. 0. 1. 0 0 0Wednesday, March 28, 12
  • 32. CQL 3.0 -- A materialized timeline of tweets CREATE COLUMNFAMILY timeline ( username text, posted_at timestamp, body text, posted_by text, PRIMARY KEY (username, posted_at) );Wednesday, March 28, 12
  • 33. CQL 3.0 INSERT INTO timeline (username, posted_at, body, posted_by) VALUES (scotty, ‘2012-03-23 14:36’ ‘stupid klingons...’, jtkirk); INSERT INTO timeline (username, posted_at, body, posted_by) VALUES (scotty, ‘2012-03-23 16:12’ ‘@jtkirk green?’, spock); INSERT INTO timeline (username, posted_at, body, posted_by) VALUES (scotty, ‘2012-03-23 17:42’ ‘@spock yes, green’, jtkirk); INSERT INTO timeline (username, posted_at, body, posted_by) VALUES (scotty, ‘2012-03-25 08:14’ ‘get off my lawn!’, bones);Wednesday, March 28, 12
  • 34. In Cassandra’s eyes eye (23/03 14:36, body): (23/03 14:36, posted_by): (23/03 16:12, body): scotty ... stupid klingons... jtkirk @jtkirk green?Wednesday, March 28, 12
  • 35. -- Tweets in Scotty’s timeline, by date SELECT * FROM timeline WHERE username = scotty AND posted_at > ‘2012-03-22’;Wednesday, March 28, 12
  • 36. Is it a row, or a table? Yes. username posted_at body posted_by scotty 23/03 14:36 stupid klingons... jtkirk scotty 23/03 16:12 @jtkirk green? spock scotty 23/03 17:42 @spock yes, green jtkirk scotty 25/03 08:14 get off my lawn! bonesWednesday, March 28, 12
  • 37. Also... • Column names are strictly UTF-8 • Column names are case-insensitive (unless quoted) • Old slice notation is gone (<start>..<end>) • Static column families are actually static (schema-enforced)Wednesday, March 28, 12
  • 38. $@#*! NOT AGAIN!Wednesday, March 28, 12
  • 39. CQL 2.0 + 3.0 “beta” You are here 0. 1. 1. 8. 0. 1. 0 0 0Wednesday, March 28, 12
  • 40. Wednesday, March 28, 12
  • 41. CQL 3.0 You will be here 0. 1. 1. 1. 8. 0. 1. 2. 0 0 0 0Wednesday, March 28, 12
  • 42. A query interface should be... Simple Intuitive Invisible Performant(?)Wednesday, March 28, 12
  • 43. Performance insertsWednesday, March 28, 12
  • 44. Performance inserts w/ indexWednesday, March 28, 12
  • 45. Performance counter incrementsWednesday, March 28, 12
  • 46. Performance readsWednesday, March 28, 12
  • 47. Wednesday, March 28, 12
  • 48. A query interface should be... Simple Intuitive Invisible PerformantWednesday, March 28, 12
  • 49. Help Wanted • Writing tests • Documentation • Feedback • DriversWednesday, March 28, 12
  • 50. Wednesday, March 28, 12