This session will explore the new features in Cassandra 3.0, starting with JSON support. Cassandra now allows storing JSON directly to Cassandra rows and vice versa, making it trivial to deploy Cassandra as a component in modern service-oriented architectures.
Cassandra 3.0 also delivers other enhancements to developer productivity: user defined functions let developers deploy custom application logic server side with any language conforming to the Java scripting API, including Javascript. Global indexes allow scaling indexed queries linearly with the size of the cluster, a first for open-source NoSQL databases.
Finally, we will cover the performance improvements in Cassandra 3.0 as well.
19. CQL
CREATE TABLE users (
id uuid PRIMARY KEY,
name text,
state text,
birth_date int
);
CREATE INDEX ON users(state);
SELECT * FROM users
WHERE state=‘Texas’
AND birth_date > 1950;
20. Collections
CREATE TABLE example (
id int PRIMARY KEY,
tupleval tuple<int, text>,
numbers set<int>,
words list<text>
);
INSERT INTO example (id, tupleval, numbers, words)
VALUES (0, (1, 'foo'), {1, 2, 3, 6}, ['the', 'quick', 'brown', 'fox']);
21. User-defined types (UDT)
CREATE TYPE address (number int, street text);
CREATE TABLE users (
id int PRIMARY KEY,
street_address frozen<address>
);
INSERT INTO users (id, street_address)
VALUES (1, {number: 123, street: 'Cassandra Ave'});
35. See also
•The myth of schema-less:
http://rustyrazorblade.com/2014/07/the-myth-of-schema-less/
•Schema-less is (usually) a lie:
https://www.compose.io/articles/schema-less-is-usually-a-lie/
•Schemaless databases don’t exist:
https://vividcortex.com/blog/2015/02/24/schemaless-databases-dont-
exist/
69. User-defined functions
CREATE FUNCTION my_sin (input double)
RETURNS double LANGUAGE java
AS ’
return input == null
? null
: Double.valueOf(Math.sin(input.doubleValue()));
’;
SELECT key, my_sin(value) FROM my_table WHERE key IN (1, 2, 3);
also aggregates
http://www.slideshare.net/RobertStupp/user-definedfunctionscassandrasummiteu2014
[robert stupp user defined functions]
71. Materialized views
CREATE MATERIALIZED VIEW songs_by_album AS
SELECT * FROM songs
WHERE album IS NOT NULL
PRIMARY KEY (album, id);
SELECT * FROM songs_by_album
WHERE album = ‘Tres Hombres’;
72. Indexes
CREATE TABLE songs (
id uuid PRIMARY KEY,
title text,
album text,
artist text
);
CREATE INDEX songs_by_album on songs(album);
insert into songs (id, title, artist, album)
values ('a3e64f8f...', 'La Grange', 'ZZ Top', 'Tres Hombres');
insert into songs (id, title, artist, album)
values ('8a172618...', 'Waitin for the Bus', 'ZZ Top', 'Tres Hombres');
insert into songs (id, title, artist, album)
values ('2b09185b...', 'Outside Woman Blues', 'Back Door Slam', 'Roll Away');
SELECT * FROM songs
WHERE album = ‘Tres Hombres’;
73. Local indexes
client
title artist album
La
Grange
ZZ Top
Tres
Hombre
s
title artist album
Outside...
Back Door
Slam
Roll Away
title artist album
Waitin... ZZ Top
Tres
Hombres