forked from datastax/php-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
duration_collections.feature
74 lines (61 loc) · 2.82 KB
/
duration_collections.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
@cassandra-version-3.10
Feature: Duration
PHP Driver supports the `Duration` datatype in collections
Background:
Given a running Cassandra cluster
Scenario: Use the duration type in collections
Given the following schema:
"""cql
CREATE KEYSPACE simplex WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': 1
};
USE simplex;
CREATE TYPE duration_user_type (duration1 duration, duration2 duration);
CREATE TABLE durations (k text PRIMARY KEY,
duration_list list<duration>,
duration_tuple tuple<duration, duration>,
duration_udt duration_user_type);
"""
And the following example:
"""
<?php
$cluster = Cassandra::cluster()->build();
$session = $cluster->connect("simplex");
# Construct collection arguments
$list = Cassandra\Type::collection(Cassandra\Type::duration())->create(
new Cassandra\Duration(1, 2, 3)
);
$list->add(new Cassandra\Duration(4, 5, 6));
$tuple = Cassandra\Type::tuple(Cassandra\Type::duration(), Cassandra\Type::duration())->create(
new Cassandra\Duration(1, 2, 3), new Cassandra\Duration(4, 5, 6)
);
$udt = Cassandra\Type::userType('duration1', Cassandra\Type::duration(), 'duration2', Cassandra\Type::duration())->create(
'duration1', new Cassandra\Duration(1, 2, 3)
);
$udt->set('duration2', new Cassandra\Duration(4, 5, 6));
# Insert collections containing durations into table
$options = array('arguments' =>
array('key1', $list, $tuple, $udt)
);
$session->execute("INSERT INTO durations
(k, duration_list, duration_tuple, duration_udt) VALUES
(?, ?, ?, ?)", $options);
# Select collections from table and print as WKT
$rows = $session->execute("SELECT * FROM durations WHERE k = 'key1'");
$row = $rows->first();
$rows = $session->execute("SELECT * FROM durations WHERE k = 'key1'");
$row = $rows->first();
echo 'The list contains durations: [' . implode(', ', $row['duration_list']->values()) . ']' . PHP_EOL;
echo 'The tuple contains durations: (' . implode(', ', $row['duration_tuple']->values()) . ')' . PHP_EOL;
$asWkt = array_map(function($k, $v) { return $k . ': ' . $v; },
array_keys($row["duration_udt"]->values()), $row["duration_udt"]->values());
echo 'The udt contains durations: {' . implode(', ', $asWkt) . '}' . PHP_EOL;
"""
When it is executed
Then its output should contain these lines in any order:
"""
The list contains durations: [1mo2d3ns, 4mo5d6ns]
The tuple contains durations: (1mo2d3ns, 4mo5d6ns)
The udt contains durations: {duration1: 1mo2d3ns, duration2: 4mo5d6ns}
"""