This document discusses Apache Cassandra and its features and use cases. It provides an overview of Cassandra's key characteristics like massive scalability, extreme availability, and rich data modeling. Example use cases mentioned include messaging, collections/playlists, fraud detection, recommendations, and IoT sensor data. New features introduced in Cassandra in 2016 are also summarized, such as delete by range, materialized views, atomic UDT updates, a new SASI index, and support for GROUP BY queries.
4. @doanduyhai
Caractéristiques principales
4
• massivement scalable (1000+ nœuds sur un seul cluster)
• disponibilité extrême (même en cas de perte de N-1 nœuds, N=RF)
• gestion du multi-data center/multi-cloud provider
• data modèle riche
• éco-système étendu (Apache Spark™, Apache Mesos™, Apache Zeppelin™)
21. @doanduyhai
DDL
21
• CREATE/ALTER/DROP KEYSPACE
• CREATE/ALTER/DROP TABLE
• CREATE/ALTER/DROP TYPE <custom_data_type>
• CREATE/ALTER/DROP USER
• CREATE/ALTER/DROP ROLE
• GRANT/REVOKE <privileges> ON <table> TO <role_name>
22. @doanduyhai
DML
22
INSERT INTO users(login, name, age) VALUES('jdoe', 'John DOE', 33);
UPDATE users SET age = 34 WHERE login = 'jdoe';
DELETE age FROM users WHERE login = 'jdoe';
SELECT age FROM users WHERE login = 'jdoe';
23. @doanduyhai
Collections
23
CREATE TABLE xxx(
…,
li list<text>,
se set<text>,
ma map<int, text>,
…
);
UPDATE xxx SET li = li + [append] …
UPDATE xxx SET se = se + {append}
UPDATE xxx SET ma[key] = value …
24. @doanduyhai
User Defined Type (UDT)
24
CREATE TYPE address (
number int,
street text,
zipcode text,
city text,
country text
);
27. @doanduyhai
User Defined Functions/Aggregates
27
CREATE FUNCTION toUpperCase(input text)
RETURNS NULL ON NULL INPUT
RETURNS int
LANGUAGE java
AS $$ return input.toUpperCase(); $$;
SELECT toUpperCase(firstname) FROM users WHERE …
SELECT max(salary) FROM users WHERE ...
31. @doanduyhai
Vues matérialisées
31
CREATE MATERIALIZED VIEW rich_users
AS SELECT * FROM user
WHERE id IS NOT NULL AND salary > 100000
PRIMARY KEY((salary), id);
CREATE MATERIALIZED VIEW rich_french_users
AS SELECT * FROM user
WHERE id IS NOT NULL AND country = ‘France’ AND salary > 100000
PRIMARY KEY((country), id);
Cassandra 3.10
Cassandra 3.0
32. @doanduyhai
Mise à jour atomique UDT (1er niveau)
32
UPDATE users
SET address.street = 12
WHERE id = xxx;
Cassandra 3.6
33. @doanduyhai
Nouveau index SASI
33
CREATE CUSTOM INDEX albums_title_idx
ON music.albums(title)
USING 'org.apache.cassandra.index.sasi.SASIIndex’
WITH OPTIONS = {
'mode': 'CONTAINS',
'analyzer_class':
'org.apache.cassandra.index.sasi.analyzer.StandardAnalyzer',
'tokenization_enable_stemming': 'true',
'analyzed': 'true',
'tokenization_normalize_lowercase': 'true’
};
Cassandra 3.5