forked from he4rt/scylladb-php-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatch_statements.feature
83 lines (73 loc) · 2.86 KB
/
batch_statements.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
@cassandra-version-2.0
Feature: Batch statements
PHP Driver supports batch statements. There are three types of batch statements:
* `Cassandra::BATCH_LOGGED` - this is the default batch type. This batch
guarantees that either all or none of its statements will be executed.
This behavior is achieved by writing a batch log on the coordinator, which
slows down the execution somewhat.
* `Cassandra::BATCH_UNLOGGED` - this batch will not be verified when executed,
which makes it faster than a `LOGGED` batch, but means that some of its statements
might fail, while others - succeed.
* `Cassandra::BATCH_COUNTER` - this batch is used for counter updates, which
are, unlike other writes, not idempotent.
Background:
Given a running Cassandra cluster
And the following schema:
"""cql
CREATE KEYSPACE simplex WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': 1
};
USE simplex;
CREATE TABLE playlists (
id uuid,
title text,
album text,
artist text,
song_id uuid,
PRIMARY KEY (id, title, album, artist)
);
"""
Scenario: Batch statements can contain simple and prepared statements
Given the following example:
"""php
<?php
$cluster = Cassandra::cluster()->build();
$session = $cluster->connect("simplex");
$insertQuery = "INSERT INTO playlists (id, song_id, artist, title, album) " .
"VALUES (62c36092-82a1-3a00-93d1-46196ee77204, ?, ?, ?, ?)";
$prepared = $session->prepare($insertQuery);
$batch = new Cassandra\BatchStatement(Cassandra::BATCH_LOGGED);
$batch->add($prepared, array(
'song_id' => new Cassandra\Uuid('756716f7-2e54-4715-9f00-91dcbea6cf50'),
'title' => 'La Petite Tonkinoise',
'album' => 'Bye Bye Blackbird',
'artist' => 'Joséphine Baker'
));
$batch->add($insertQuery, array(
new Cassandra\Uuid('f6071e72-48ec-4fcb-bf3e-379c8a696488'),
'Willi Ostermann', 'Die Mösch', 'In Gold'
));
$batch->add($prepared, array(
new Cassandra\Uuid('fbdf82ed-0063-4796-9c7c-a3d4f47b4b25'),
'Mick Jager', 'Memo From Turner', 'Performance'
));
$session->execute($batch);
$result = $session->execute("SELECT * FROM simplex.playlists");
foreach ($result as $row) {
echo $row['artist'] . ": " . $row['title'] . " / " . $row['album'] . "\n";
}
"""
When it is executed
Then its output should contain:
"""
Joséphine Baker: La Petite Tonkinoise / Bye Bye Blackbird
"""
And its output should contain:
"""
Willi Ostermann: Die Mösch / In Gold
"""
And its output should contain:
"""
Mick Jager: Memo From Turner / Performance
"""