forked from datastax/php-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datatypes.feature
202 lines (186 loc) · 5.56 KB
/
datatypes.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
Feature: Datatypes
PHP Driver supports all Cassandra datatypes
Background:
Given a running Cassandra cluster
Scenario: Using Cassandra value types
Given the following schema:
"""cql
CREATE KEYSPACE simplex WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': 1
};
USE simplex;
CREATE TABLE values (
id int PRIMARY KEY,
bigint_value bigint,
decimal_value decimal,
double_value double,
float_value float,
int_value int,
varint_value varint,
timestamp_value timestamp,
blob_value blob,
uuid_value uuid,
timeuuid_value timeuuid,
inet_value inet
);
INSERT INTO values (
id,
bigint_value,
decimal_value,
double_value,
float_value,
int_value,
varint_value,
timestamp_value,
blob_value,
uuid_value,
timeuuid_value,
inet_value
)
VALUES (
0,
-765438000,
1313123123.234234234234234234123,
3.141592653589793,
3.14,
4,
67890656781923123918798273492834712837198237,
1425691864001,
varcharAsBlob('0x000000'),
ab3352d9-4f7f-4007-a35a-e62aa7ab0b19,
maxTimeuuid('2015-03-11 14:47:10+0000'),
'200.199.198.197'
);
"""
And the following example:
"""php
<?php
$cluster = Cassandra::cluster()->build();
$session = $cluster->connect("simplex");
$result = $session->execute("SELECT * FROM values");
$row = $result->first();
foreach ($row as $name => $value) {
if ($name !== "id") {
echo "{$name} => {$value}" .PHP_EOL;
}
}
"""
When it is executed
Then its output should contain these lines in any order:
"""
bigint_value => -765438000
blob_value => 0x3078303030303030
decimal_value => 1313123123.234234234234234234123
double_value => 3.1415926535898
float_value => 3.14000010490417
inet_value => 200.199.198.197
int_value => 4
timestamp_value => 1425691864001
timeuuid_value => 7f0a920f-c7fd-11e4-7f7f-7f7f7f7f7f7f
uuid_value => ab3352d9-4f7f-4007-a35a-e62aa7ab0b19
varint_value => 67890656781923123918798273492834712837198237
"""
@cassandra-version-2.2
@tinyint
@smallint
Scenario: Using Cassandra tinyint and smallint types
Given the following schema:
"""cql
CREATE KEYSPACE simplex WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': 1
};
USE simplex;
CREATE TABLE values (
id int PRIMARY KEY,
tinyint_value tinyint,
smallint_value smallint,
);
"""
And the following example:
"""php
<?php
$cluster = Cassandra::cluster()->build();
$session = $cluster->connect("simplex");
$options = array('arguments' =>
array(1, new Cassandra\Tinyint(127), new Cassandra\Smallint(32767))
);
$session->execute("INSERT INTO values (id, tinyint_value, smallint_value) VALUES (?, ?, ?)", $options);
$result = $session->execute("SELECT * FROM values");
$row = $result->first();
foreach ($row as $name => $value) {
if ($name != "id") {
echo "{$name} => {$value}" .PHP_EOL;
}
}
"""
When it is executed
Then its output should contain:
"""
smallint_value => 32767
tinyint_value => 127
"""
@cassandra-version-2.2
@date
Scenario: Using Cassandra date type
Given the following schema:
"""cql
CREATE KEYSPACE simplex WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': 1
};
USE simplex;
CREATE TABLE date_values (
id int PRIMARY KEY,
date_value date
);
"""
And the following example:
"""php
<?php
$cluster = Cassandra::cluster()->build();
$session = $cluster->connect("simplex");
$options = array('arguments' => array(1, new Cassandra\Date(0)));
$session->execute("INSERT INTO date_values (id, date_value) VALUES (?, ?)", $options);
$result = $session->execute("SELECT * FROM date_values");
$row = $result->first();
echo "date_value => {$row['date_value']->toDateTime()->format('Y-m-d H:i:s')}" . PHP_EOL;
"""
When it is executed
Then its output should contain:
"""
date_value => 1970-01-01 00:00:00
"""
@cassandra-version-2.2
@time
Scenario: Using Cassandra time type
Given the following schema:
"""cql
CREATE KEYSPACE simplex WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': 1
};
USE simplex;
CREATE TABLE time_values (
id int PRIMARY KEY,
time_value time
);
"""
And the following example:
"""php
<?php
$cluster = Cassandra::cluster()->build();
$session = $cluster->connect("simplex");
$datetime = new \DateTime("1970-01-01T00:00:01+0000");
$options = array('arguments' => array(1, Cassandra\Time::fromDateTime($datetime)));
$session->execute("INSERT INTO time_values (id, time_value) VALUES (?, ?)", $options);
$result = $session->execute("SELECT * FROM time_values");
$row = $result->first();
echo "time_value => {$row['time_value']}" . PHP_EOL;
"""
When it is executed
Then its output should contain:
"""
time_value => 1000000000
"""