forked from datastax/php-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema_metadata.feature
367 lines (346 loc) · 11.9 KB
/
schema_metadata.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
@skip-ci
Feature: Schema Metadata
PHP Driver exposes the Cassandra Schema Metadata for keyspaces, tables, and
columns.
Background:
Given a running Cassandra cluster
And the following schema:
"""cql
CREATE KEYSPACE simplex WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': 1
} AND DURABLE_WRITES = false;
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,
ascii_value ascii,
text_value text,
varchar_value varchar,
timestamp_value timestamp,
blob_value blob,
uuid_value uuid,
timeuuid_value timeuuid,
inet_value inet,
list_value List<text>,
map_value Map<timestamp, double>,
set_value Set<float>
) WITH
bloom_filter_fp_chance=0.5 AND
caching='ALL' AND
comment='Schema Metadata Feature' AND
compaction={'class': 'LeveledCompactionStrategy', 'sstable_size_in_mb' : 37} AND
compression={'sstable_compression': 'DeflateCompressor'} AND
dclocal_read_repair_chance=0.25 AND
gc_grace_seconds=3600 AND
populate_io_cache_on_flush='true' AND
read_repair_chance=0.75 AND
replicate_on_write='false';
"""
Scenario: Getting keyspace metadata
Given the following example:
"""php
<?php
$cluster = Cassandra::cluster()
->withContactPoints('127.0.0.1')
->build();
$session = $cluster->connect("simplex");
$schema = $session->schema();
$keyspace = $schema->keyspace("simplex");
echo "Name: " . $keyspace->name() . "\n";
echo "Replication Class: " . $keyspace->replicationClassName() . "\n";
foreach ($keyspace->replicationOptions() as $key => $value) {
echo " " . $key . ":" . $value . "\n";
}
echo "Has Durable Writes: " . ($keyspace->hasDurableWrites() ? "True" : "False" ). "\n";
"""
When it is executed
Then its output should contain:
"""
Name: simplex
Replication Class: org.apache.cassandra.locator.SimpleStrategy
replication_factor:1
Has Durable Writes: False
"""
Scenario: Getting table metadata
Given the following example:
"""php
<?php
$cluster = Cassandra::cluster()
->withContactPoints('127.0.0.1')
->build();
$session = $cluster->connect("simplex");
$schema = $session->schema();
$table = $schema->keyspace("simplex")->table("values");
echo "Name: " . $table->name() . "\n";
echo "Bloom Filter: " . $table->bloomFilterFPChance() . "\n";
$patterns = array('/{/', '/"/', '/:/', '/keys/');
$table_caching = explode(",", $table->caching());
echo "Caching: " . preg_replace($patterns, "", $table_caching[0]) . "\n";
echo "Comment: " . $table->comment() . "\n";
echo "Compaction Class: " . $table->compactionStrategyClassName() . "\n";
foreach ($table->compactionStrategyOptions() as $key => $value) {
echo " " . $key . ":" . $value . "\n";
}
foreach ($table->compressionParameters() as $key => $value) {
echo " " . $key . ":" . $value . "\n";
}
echo "DC/Local Read Repair Chance: " . $table->localReadRepairChance() . "\n";
echo "Garbage Collection Grace Seconds: " . $table->gcGraceSeconds() . "\n";
echo "Read Repair Chance: " . $table->readRepairChance() . "\n";
"""
When it is executed
Then its output should contain:
"""
Name: values
Bloom Filter: 0.5
Caching: ALL
Comment: Schema Metadata Feature
Compaction Class: org.apache.cassandra.db.compaction.LeveledCompactionStrategy
sstable_size_in_mb:37
sstable_compression:org.apache.cassandra.io.compress.DeflateCompressor
DC/Local Read Repair Chance: 0.25
Garbage Collection Grace Seconds: 3600
Read Repair Chance: 0.75
"""
@cassandra-version-less-2.1
Scenario: Getting table metadata for io cache and replicate on write
Given the following example:
"""php
<?php
$cluster = Cassandra::cluster()
->withContactPoints('127.0.0.1')
->build();
$session = $cluster->connect("simplex");
$schema = $session->schema();
$table = $schema->keyspace("simplex")->table("values");
echo "Populate I/O Cache on Flush: " . ($table->populateIOCacheOnFlush() ? "True" : "False") . "\n";
echo "Replicate on Write: " . ($table->replicateOnWrite() ? "True" : "False") . "\n";
"""
When it is executed
Then its output should contain:
"""
Populate I/O Cache on Flush: True
Replicate on Write: False
"""
@cassandra-version-only-2.0
Scenario: Getting table metadata for index interval
Given the following example:
"""php
<?php
$cluster = Cassandra::cluster()
->withContactPoints('127.0.0.1')
->build();
$session = $cluster->connect("simplex");
$cql = "ALTER TABLE values WITH index_interval = '512'";
$session->execute($cql);
$schema = $session->schema();
$table = $schema->keyspace("simplex")->table("values");
echo "Index Interval: " . $table->indexInterval() . "\n";
"""
When it is executed
Then its output should contain:
"""
Index Interval: 512
"""
@cassandra-version-2.0
Scenario: Getting table metadata for default TTL, memtable flush period and speculative retry
Given the following example:
"""php
<?php
$cluster = Cassandra::cluster()
->withContactPoints('127.0.0.1')
->build();
$session = $cluster->connect("simplex");
$cql = "ALTER TABLE values WITH default_time_to_live = '10000' AND "
. "memtable_flush_period_in_ms = '100' AND "
. "speculative_retry = '10ms'";
$session->execute($cql);
$schema = $session->schema();
$table = $schema->keyspace("simplex")->table("values");
echo "Default TTL: " . $table->defaultTTL() . "\n";
echo "Memtable Flush Period: " . $table->memtableFlushPeriodMs() . "\n";
echo "Speculative Retry: " . intval($table->speculativeRetry()) . "\n";
"""
When it is executed
Then its output should contain:
"""
Default TTL: 10000
Memtable Flush Period: 100
Speculative Retry: 10
"""
@cassandra-version-2.1
Scenario: Getting table metadata for max and min index intervals
Given the following example:
"""php
<?php
$cluster = Cassandra::cluster()
->withContactPoints('127.0.0.1')
->build();
$session = $cluster->connect("simplex");
$cql = "ALTER TABLE values WITH max_index_interval = '16' AND "
. "min_index_interval = '4'";
$session->execute($cql);
$schema = $session->schema();
$table = $schema->keyspace("simplex")->table("values");
echo "Maximum Index Interval: " . $table->maxIndexInterval() . "\n";
echo "Minimum Index Interval: " . $table->minIndexInterval() . "\n";
"""
When it is executed
Then its output should contain:
"""
Maximum Index Interval: 16
Minimum Index Interval: 4
"""
@cassandra-version-2.0
Scenario: Getting metadata for column and types
Given the following example:
"""php
<?php
$cluster = Cassandra::cluster()
->withContactPoints('127.0.0.1')
->build();
$session = $cluster->connect("simplex");
$schema = $session->schema();
$table = $schema->keyspace("simplex")->table("values");
foreach ($table->columns() as $column) {
echo $column->name() . ': ' . $column->type() . "\n";
}
"""
When it is executed
Then its output should contain these lines in any order:
"""
ascii_value: ascii
bigint_value: bigint
blob_value: blob
decimal_value: decimal
double_value: double
float_value: float
id: int
inet_value: inet
int_value: int
list_value: list<varchar>
map_value: map<timestamp, double>
set_value: set<float>
text_value: varchar
timestamp_value: timestamp
timeuuid_value: timeuuid
uuid_value: uuid
varchar_value: varchar
varint_value: varint
"""
@cassandra-version-2.1
Scenario: Getting metadata for user types
Given the following schema:
"""php
CREATE KEYSPACE simplex WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': 1
};
USE simplex;
CREATE TYPE type1 (a int, b text);
CREATE TYPE type2 (a map<text, int>, b bigint);
CREATE TYPE type3 (a map<text, frozen<set<varint>>>, b list<uuid>);
"""
And the following example:
"""php
<?php
$cluster = Cassandra::cluster()
->withContactPoints('127.0.0.1')
->build();
$session = $cluster->connect("simplex");
$schema = $session->schema();
$keyspace = $schema->keyspace("simplex");
foreach ($keyspace->userTypes() as $name => $type) {
print "Name: $type\n";
print "Type: " . var_export($type, true) . "\n";
}
"""
When it is executed
Then its output should contain:
"""
Name: simplex.type1
Type: Cassandra\Type\UserType::__set_state(array(
'types' =>
array (
'a' =>
Cassandra\Type\Scalar::__set_state(array(
'name' => 'int',
)),
'b' =>
Cassandra\Type\Scalar::__set_state(array(
'name' => 'varchar',
)),
),
))
Name: simplex.type2
Type: Cassandra\Type\UserType::__set_state(array(
'types' =>
array (
'a' =>
Cassandra\Type\Map::__set_state(array(
'keyType' =>
Cassandra\Type\Scalar::__set_state(array(
'name' => 'varchar',
)),
'valueType' =>
Cassandra\Type\Scalar::__set_state(array(
'name' => 'int',
)),
)),
'b' =>
Cassandra\Type\Scalar::__set_state(array(
'name' => 'bigint',
)),
),
))
Name: simplex.type3
Type: Cassandra\Type\UserType::__set_state(array(
'types' =>
array (
'a' =>
Cassandra\Type\Map::__set_state(array(
'keyType' =>
Cassandra\Type\Scalar::__set_state(array(
'name' => 'varchar',
)),
'valueType' =>
Cassandra\Type\Set::__set_state(array(
'valueType' =>
Cassandra\Type\Scalar::__set_state(array(
'name' => 'int',
)),
)),
)),
'b' =>
Cassandra\Type\Collection::__set_state(array(
'valueType' =>
Cassandra\Type\Scalar::__set_state(array(
'name' => 'uuid',
)),
)),
),
))
"""
Scenario: Disable schema metadata
Given the following example:
"""php
<?php
$cluster = Cassandra::cluster()
->withContactPoints('127.0.0.1')
->withSchemaMetadata(false)
->build();
$session = $cluster->connect("simplex");
$schema = $session->schema();
print count($schema->keyspaces()) . "\n";
"""
When it is executed
Then its output should contain these lines in any order:
"""
0
"""