|
| 1 | +Feature: Schema Metadata |
| 2 | + |
| 3 | + PHP Driver exposes the Cassandra Schema Metadata for keyspaces, tables, and |
| 4 | + columns. |
| 5 | + |
| 6 | + Background: |
| 7 | + Given a running Cassandra cluster |
| 8 | + And the following schema: |
| 9 | + """cql |
| 10 | + CREATE KEYSPACE simplex WITH replication = { |
| 11 | + 'class': 'SimpleStrategy', |
| 12 | + 'replication_factor': 1 |
| 13 | + } AND DURABLE_WRITES = false; |
| 14 | + USE simplex; |
| 15 | + CREATE TABLE values ( |
| 16 | + id int PRIMARY KEY, |
| 17 | + bigint_value bigint, |
| 18 | + decimal_value decimal, |
| 19 | + double_value double, |
| 20 | + float_value float, |
| 21 | + int_value int, |
| 22 | + varint_value varint, |
| 23 | + ascii_value ascii, |
| 24 | + text_value text, |
| 25 | + varchar_value varchar, |
| 26 | + timestamp_value timestamp, |
| 27 | + blob_value blob, |
| 28 | + uuid_value uuid, |
| 29 | + timeuuid_value timeuuid, |
| 30 | + inet_value inet, |
| 31 | + list_value List<text>, |
| 32 | + map_value Map<timestamp, double>, |
| 33 | + set_value Set<float> |
| 34 | + ) WITH |
| 35 | + bloom_filter_fp_chance=0.5 AND |
| 36 | + caching='ALL' AND |
| 37 | + comment='Schema Metadata Feature' AND |
| 38 | + compaction={'class': 'LeveledCompactionStrategy', 'sstable_size_in_mb' : 37} AND |
| 39 | + compression={'sstable_compression': 'DeflateCompressor'} AND |
| 40 | + dclocal_read_repair_chance=0.25 AND |
| 41 | + gc_grace_seconds=3600 AND |
| 42 | + populate_io_cache_on_flush='true' AND |
| 43 | + read_repair_chance=0.75 AND |
| 44 | + replicate_on_write='false'; |
| 45 | + """ |
| 46 | + |
| 47 | + Scenario: Getting keyspace metadata |
| 48 | + Given the following example: |
| 49 | + """php |
| 50 | + <?php |
| 51 | + $cluster = Cassandra::cluster() |
| 52 | + ->withContactPoints('127.0.0.1') |
| 53 | + ->build(); |
| 54 | + $session = $cluster->connect("simplex"); |
| 55 | + |
| 56 | + $schema = $session->schema(); |
| 57 | + $keyspace = $schema->keyspace("simplex"); |
| 58 | +
|
| 59 | + echo "Name: " . $keyspace->name() . "\n"; |
| 60 | + echo "Replication Class: " . $keyspace->replicationClassName() . "\n"; |
| 61 | + foreach ($keyspace->replicationOptions() as $key => $value) { |
| 62 | + echo " " . $key . ":" . $value . "\n"; |
| 63 | + } |
| 64 | + echo "Has Durable Writes: " . ($keyspace->hasDurableWrites() ? "True" : "False" ). "\n"; |
| 65 | + """ |
| 66 | + When it is executed |
| 67 | + Then its output should contain: |
| 68 | + """ |
| 69 | + Name: simplex |
| 70 | + Replication Class: org.apache.cassandra.locator.SimpleStrategy |
| 71 | + replication_factor:1 |
| 72 | + Has Durable Writes: False |
| 73 | + """ |
| 74 | + |
| 75 | + Scenario: Getting table metadata |
| 76 | + Given the following example: |
| 77 | + """php |
| 78 | + <?php |
| 79 | + $cluster = Cassandra::cluster() |
| 80 | + ->withContactPoints('127.0.0.1') |
| 81 | + ->build(); |
| 82 | + $session = $cluster->connect("simplex"); |
| 83 | + |
| 84 | + $schema = $session->schema(); |
| 85 | + $table = $schema->keyspace("simplex")->table("values"); |
| 86 | +
|
| 87 | + echo "Name: " . $table->name() . "\n"; |
| 88 | + echo "Bloom Filter: " . $table->bloomFilterFPChance() . "\n"; |
| 89 | + $patterns = array('/{/', '/"/', '/:/', '/keys/'); |
| 90 | + $table_caching = explode(",", $table->caching()); |
| 91 | + echo "Caching: " . preg_replace($patterns, "", $table_caching[0]) . "\n"; |
| 92 | + echo "Comment: " . $table->comment() . "\n"; |
| 93 | + echo "Compaction Class: " . $table->compactionStrategyClassName() . "\n"; |
| 94 | + foreach ($table->compactionStrategyOptions() as $key => $value) { |
| 95 | + echo " " . $key . ":" . $value . "\n"; |
| 96 | + } |
| 97 | + foreach ($table->compressionParameters() as $key => $value) { |
| 98 | + echo " " . $key . ":" . $value . "\n"; |
| 99 | + } |
| 100 | + echo "DC/Local Read Repair Chance: " . $table->localReadRepairChance() . "\n"; |
| 101 | + echo "Garbage Collection Grace Seconds: " . $table->gcGraceSeconds() . "\n"; |
| 102 | + echo "Read Repair Chance: " . $table->readRepairChance() . "\n"; |
| 103 | + """ |
| 104 | + When it is executed |
| 105 | + Then its output should contain: |
| 106 | + """ |
| 107 | + Name: values |
| 108 | + Bloom Filter: 0.5 |
| 109 | + Caching: ALL |
| 110 | + Comment: Schema Metadata Feature |
| 111 | + Compaction Class: org.apache.cassandra.db.compaction.LeveledCompactionStrategy |
| 112 | + sstable_size_in_mb:37 |
| 113 | + sstable_compression:org.apache.cassandra.io.compress.DeflateCompressor |
| 114 | + DC/Local Read Repair Chance: 0.25 |
| 115 | + Garbage Collection Grace Seconds: 3600 |
| 116 | + Read Repair Chance: 0.75 |
| 117 | + """ |
| 118 | + |
| 119 | + @cassandra-version-less-2.1 |
| 120 | + Scenario: Getting table metadata for io cache and replicate on write |
| 121 | + Given the following example: |
| 122 | + """php |
| 123 | + <?php |
| 124 | + $cluster = Cassandra::cluster() |
| 125 | + ->withContactPoints('127.0.0.1') |
| 126 | + ->build(); |
| 127 | + $session = $cluster->connect("simplex"); |
| 128 | + |
| 129 | + $schema = $session->schema(); |
| 130 | + $table = $schema->keyspace("simplex")->table("values"); |
| 131 | +
|
| 132 | + echo "Populate I/O Cache on Flush: " . ($table->populateIOCacheOnFlush() ? "True" : "False") . "\n"; |
| 133 | + echo "Replicate on Write: " . ($table->replicateOnWrite() ? "True" : "False") . "\n"; |
| 134 | + """ |
| 135 | + When it is executed |
| 136 | + Then its output should contain: |
| 137 | + """ |
| 138 | + Populate I/O Cache on Flush: True |
| 139 | + Replicate on Write: False |
| 140 | + """ |
| 141 | + |
| 142 | + @cassandra-version-only-2.0 |
| 143 | + Scenario: Getting table metadata for index interval |
| 144 | + Given the following example: |
| 145 | + """php |
| 146 | + <?php |
| 147 | + $cluster = Cassandra::cluster() |
| 148 | + ->withContactPoints('127.0.0.1') |
| 149 | + ->build(); |
| 150 | + $session = $cluster->connect("simplex"); |
| 151 | + $cql = "ALTER TABLE values WITH index_interval = '512'"; |
| 152 | + $session->execute(new Cassandra\SimpleStatement($cql)); |
| 153 | + $schema = $session->schema(); |
| 154 | + $table = $schema->keyspace("simplex")->table("values"); |
| 155 | +
|
| 156 | + echo "Index Interval: " . $table->indexInterval() . "\n"; |
| 157 | + """ |
| 158 | + When it is executed |
| 159 | + Then its output should contain: |
| 160 | + """ |
| 161 | + Index Interval: 512 |
| 162 | + """ |
| 163 | + |
| 164 | + @cassandra-version-2.0 |
| 165 | + Scenario: Getting table metadata for default TTL, memtable flush period and |
| 166 | + speculative retry |
| 167 | + Given the following example: |
| 168 | + """php |
| 169 | + <?php |
| 170 | + $cluster = Cassandra::cluster() |
| 171 | + ->withContactPoints('127.0.0.1') |
| 172 | + ->build(); |
| 173 | + $session = $cluster->connect("simplex"); |
| 174 | + $cql = "ALTER TABLE values WITH default_time_to_live = '10000' AND " |
| 175 | + . "memtable_flush_period_in_ms = '100' AND " |
| 176 | + . "speculative_retry = '10ms'"; |
| 177 | + $session->execute(new Cassandra\SimpleStatement($cql)); |
| 178 | + $schema = $session->schema(); |
| 179 | + $table = $schema->keyspace("simplex")->table("values"); |
| 180 | +
|
| 181 | + echo "Default TTL: " . $table->defaultTTL() . "\n"; |
| 182 | + echo "Memtable Flush Period: " . $table->memtableFlushPeriodMs() . "\n"; |
| 183 | + echo "Speculative Retry: " . intval($table->speculativeRetry()) . "\n"; |
| 184 | + """ |
| 185 | + When it is executed |
| 186 | + Then its output should contain: |
| 187 | + """ |
| 188 | + Default TTL: 10000 |
| 189 | + Memtable Flush Period: 100 |
| 190 | + Speculative Retry: 10 |
| 191 | + """ |
| 192 | + |
| 193 | + @cassandra-version-2.1 |
| 194 | + Scenario: Getting table metadata for max and min index intervals |
| 195 | + Given the following example: |
| 196 | + """php |
| 197 | + <?php |
| 198 | + $cluster = Cassandra::cluster() |
| 199 | + ->withContactPoints('127.0.0.1') |
| 200 | + ->build(); |
| 201 | + $session = $cluster->connect("simplex"); |
| 202 | + $cql = "ALTER TABLE values WITH max_index_interval = '16' AND " |
| 203 | + . "min_index_interval = '4'"; |
| 204 | + $session->execute(new Cassandra\SimpleStatement($cql)); |
| 205 | + $schema = $session->schema(); |
| 206 | + $table = $schema->keyspace("simplex")->table("values"); |
| 207 | +
|
| 208 | + echo "Maximum Index Interval: " . $table->maxIndexInterval() . "\n"; |
| 209 | + echo "Minimum Index Interval: " . $table->minIndexInterval() . "\n"; |
| 210 | + """ |
| 211 | + When it is executed |
| 212 | + Then its output should contain: |
| 213 | + """ |
| 214 | + Maximum Index Interval: 16 |
| 215 | + Minimum Index Interval: 4 |
| 216 | + """ |
| 217 | + |
| 218 | + @cassandra-version-2.0 |
| 219 | + Scenario: Getting metadata for column and types |
| 220 | + Given the following example: |
| 221 | + """php |
| 222 | + <?php |
| 223 | + $cluster = Cassandra::cluster() |
| 224 | + ->withContactPoints('127.0.0.1') |
| 225 | + ->build(); |
| 226 | + $session = $cluster->connect("simplex"); |
| 227 | + $schema = $session->schema(); |
| 228 | + $table = $schema->keyspace("simplex")->table("values"); |
| 229 | + foreach ($table->columns() as $column) { |
| 230 | + echo $column->name() . ': ' . $column->type() . "\n"; |
| 231 | + } |
| 232 | + """ |
| 233 | + When it is executed |
| 234 | + Then its output should contain: |
| 235 | + """ |
| 236 | + ascii_value: ascii |
| 237 | + bigint_value: bigint |
| 238 | + blob_value: blob |
| 239 | + decimal_value: decimal |
| 240 | + double_value: double |
| 241 | + float_value: float |
| 242 | + id: int |
| 243 | + inet_value: inet |
| 244 | + int_value: int |
| 245 | + list_value: list<varchar> |
| 246 | + map_value: map<timestamp, double> |
| 247 | + set_value: set<float> |
| 248 | + text_value: varchar |
| 249 | + timestamp_value: timestamp |
| 250 | + timeuuid_value: timeuuid |
| 251 | + uuid_value: uuid |
| 252 | + varchar_value: varchar |
| 253 | + varint_value: varint |
| 254 | + """ |
0 commit comments