Presentation Cassandra Datastax
Presentation Cassandra Datastax
YOUR LAPTOP
Browser WebConf
Github
YOUR LAPTOP
Browser Webconf
1. Clone or download repository material
https://github.com/DataStax-Acade
my/cassandra-workshop-online
https://bit.ly/cassandra-cert-FREE
Familiar Language Easy Dev Tools Great Drivers
INSERT INTO mytable
(id,name,address) VALUES
(1,’Bob Smith’,’1 Main
Street’)
SELECT * FROM mytable
WHERE id=1
UPDATE mytable SET
name=’Tom Smith’ WHERE
id=1
DELETE FROM mytable WHERE
id=1
Apache Cassandra™ = NoSQL Distributed Database
1 Installation = 1 NODE
NODE ✔ Capacity: ± 1TB
✔ Throughput: 3000 Tx/sec/core
NODE NODE
DataCenter | Ring
NODE NODE
Communication:
✔ Gossiping
NODE NODE
Country City Population
Partition Key
USA New York 8.000.000
USA Los Angeles 4.000.000 Country City Population
FR Paris 2.230.000
DE Berlin 3.350.000
UK London 9.200.000
AU Sydney 4.900.000
DE Nuremberg 500.000
CA Toronto 6.200.000
CA Montreal 4.200.000
FR Toulouse 1.100.000
JP Tokyo 37.430.000
IN Mumbai 20.200.000
Partition Key
USA New York 8.000.000
USA Los Angeles 4.000.000 Country City Population
FR Paris 2.230.000
DE Berlin 3.350.000
UK London 9.200.000
AU Sydney 4.900.000
DE Nuremberg 500.000
CA Toronto 6.200.000
CA Montreal 4.200.000
FR Toulouse 1.100.000
JP Tokyo 37.430.000
IN Mumbai 20.200.000
Partition Key
USA New York 8.000.000
USA Los Angeles 4.000.000 Country City Population
FR Paris 2.230.000
DE Berlin 3.350.000
UK London 9.200.000
AU Sydney 4.900.000
DE Nuremberg 500.000
CA Toronto 6.200.000
CA Montreal 4.200.000
FR Toulouse 1.100.000
JP Tokyo 37.430.000
IN Mumbai 20.200.000
Partition Key
USA New York 8.000.000
USA Los Angeles 4.000.000 Country City Population
FR Paris 2.230.000
DE Berlin 3.350.000
AU Sydney 4.900.000
DE Nuremberg 500.000
CA Toronto 6.200.000
UK London 9.200.000 CA Montreal 4.200.000
FR Toulouse 1.100.000
JP Tokyo 37.430.000
IN Mumbai 20.200.000
Partition Key
USA New York 8.000.000
USA Los Angeles 4.000.000 Country City Population
FR Paris 2.230.000
DE Berlin 3.350.000
DE Nuremberg 500.000
CA Toronto 6.200.000
UK London 9.200.000 CA Montreal 4.200.000
FR Toulouse 1.100.000
JP Tokyo 37.430.000
IN Mumbai 20.200.000
AU Sydney 4.900.000
Partition Key
USA New York 8.000.000
USA Los Angeles 4.000.000 Country City Population
FR Paris 2.230.000
DE Berlin 3.350.000
DE Nuremberg 500.000
CA Toronto 6.200.000
UK London 9.200.000 CA Montreal 4.200.000
FR Toulouse 1.100.000
JP Tokyo 37.430.000
IN Mumbai 20.200.000
AU Sydney 4.900.000
Partition Key
USA New York 8.000.000
USA Los Angeles 4.000.000 Country City Population
FR Paris 2.230.000
DE Berlin 3.350.000
DE Nuremberg 500.000
UK London 9.200.000
FR Toulouse 1.100.000
JP Tokyo 37.430.000
IN Mumbai 20.200.000
FR Paris 2.230.000
DE Berlin 3.350.000
FR Toulouse 1.100.000
DE Nuremberg 500.000
UK London 9.200.000
JP Tokyo 37.430.000
IN Mumbai 20.200.000
FR Paris 2.230.000
DE Berlin 3.350.000
FR Toulouse 1.100.000
DE Nuremberg 500.000
IN Mumbai 20.200.000
FR Paris 2.230.000
DE Berlin 3.350.000
FR Toulouse 1.100.000
DE Nuremberg 500.000
F-G
X-Z
H-K
U-W
Q-T L-P
CO City Population CO City Population
AU Sydney 4.900.000 59 Sydney 4.900.000
A-E
VIRTUAL NODE
AP
- - - -
- - -
x
- - -
- - -
y - - -
- - -
z - - -
CREATE KEYSPACE users
WITH REPLICATION = {
'class' : 'NetworkTopologyStrategy',
'datacenter1' : 3
};
CREATE TABLE users.users_by_city (
city text,
last_name text,
first_name text,
address text,
email text,
PRIMARY KEY ((city), last_name, first_name));
Data
Models
Application
Application
Models
Data
Entities & Relationships
Queries
R1: Find comments related to target video using its identifier
• Get most recent first
• Implement Paging
↑ ↑
↑ ↑
comments_by_user comments_by_video
UUID UUID
↑ ↑
TIMEUUID TIMEUUID
UUID UUID
TEXT TEXT
CREATE TABLE IF NOT EXISTS comments_by_user (
userid uuid,
commentid timeuuid,
videoid uuid,
comment text,
PRIMARY KEY ((userid), commentid)
) WITH CLUSTERING ORDER BY (commentid DESC);
I’m an ordered LIST
0 1 2 3 4 6
I’m a MAP of
key/value pairs
K1 V1
K2 V2
K3 V3
K4 V4
K5 V5
Insert
Append
Replace an element
Add to map
Insert
•
•
•
•
This format must be
observed
Incrementing a counter:
This can be an
integer value
APPLY BATCH;
N o !
BEGIN BATCH
APPLY BATCH;
•
•
proxies proxies proxies
Loadbalanced url
// Delegate all configuration to file or default
CqlSession cqlSession = CqlSession.builder().build();
// Explicit Settings
CqlSession cqlSession = CqlSession.builder()
//.addContactPoint(new InetSocketAddress("127.0.0.1", 9042))
.withCloudSecureConnectBundle(Paths.get("/tmp/apollo.zip"))
.withContactPoint
.withKeyspace("killrvideo")
.withAuthCredentials("KVUser", "KVPassword")
.build();
@PreDestroy
public void cleanup() {
if (null != cqlSession) {
cqlSession.close();
}
}
cqlSession.execute("SELECT * FROM killrvideo.users");
Statement statement = …
cqlSession.execute(statement);
PreparedStatement ps = cqlSession.prepare("SELECT * from t1 where c1 = ?");
cqlSession.execute(bound);
ResultSet rs = cqlSession.execute(myStatement);
// Plumbery
ExecutionInfo info = rs.getExecutionInfo();
int executionTime = info.getQueryTrace().getDurationMicros();
// Data: NOT ALL DATA RETRIEVED IMMEDIATELY (only when needed .next())
Iterator<Row> iterRow = rs.iterator();
int itemsFirstCall = rs.getAvailableWithoutFetching();
// We know there is a single row (eg: count)
Row singleRow = resultSet.one();
// We know there are not so many results we can get all (fetch all pages)
List<Row> allRows = resultSet.all();
// Browse iterable
for(Row myRow : resultSet.iterator()) {
// .. Parsing rows
}
// Use Lambda
rs.forEach(row -> { row.getColumnDefinitions(); });
// Paging State
ByteBuffer pagingState = page1.getExecutionInfo().getPagingState();
myStatement = myStatement.setPageState(pagingState);
PreparedStatement
& Parameters
Bind
😴 Parameters
BoundStatement
ResultSet
ResultSet
Results
API
Parameters
v
PreparedStatement
& Parameters Bind
Parameters
BoundStatement
CompletionStage
AsyncResultSet
AsyncResultSet
Result
Parameters
v
PreparedStatement
& Parameters Bind
Parameters
Flux ReactiveResultSet BoundStatement
Subscribe
Query
execution
Row
ReactiveRow
Subscriber.onNext
onComplete()
community.datastax.com
Date Time Content Type