1Feature: Secondary Index Metadata
2
3  PHP Driver exposes the Cassandra Schema Metadata for secondary indexes.
4
5  Background:
6    Given a running Cassandra cluster
7    And the following schema:
8      """cql
9      CREATE KEYSPACE simplex WITH replication = {
10        'class': 'SimpleStrategy',
11        'replication_factor': 1
12      } AND DURABLE_WRITES = false;
13      USE simplex;
14      CREATE TABLE users (id int PRIMARY KEY, name text);
15      CREATE INDEX IF NOT EXISTS name_index ON users(name);
16      """
17
18  Scenario: Getting a index metadata
19    Given the following example:
20      """php
21      <?php
22      $cluster = Cassandra::cluster()
23                        ->withContactPoints('127.0.0.1')
24                        ->build();
25      $session = $cluster->connect("simplex");
26      $schema = $session->schema();
27      $index = $schema->keyspace("simplex")->table("users")->index("name_index");
28
29      echo "Name: " . $index->name() . "\n";
30      echo "Kind: " . $index->kind() . "\n";
31      echo "Target: " . $index->target() . "\n";
32      echo "IsCustom: " . ($index->isCustom() ? "true" : "false") . "\n";
33      """
34    When it is executed
35    Then its output should contain:
36      """
37      Name: name_index
38      Kind: composites
39      Target: name
40      IsCustom: false
41      """
42
43  @cassandra-version-3.0
44  Scenario: Getting a index metadata w/ options
45    Given the following example:
46      """php
47      <?php
48      $cluster  = Cassandra::cluster()
49                         ->withContactPoints('127.0.0.1')
50                         ->build();
51      $session  = $cluster->connect("simplex");
52
53      $schema   = $session->schema();
54
55      $index = $schema->keyspace("simplex")->table("users")->index("name_index");
56
57      echo "Name: " . $index->name() . "\n";
58      echo "Kind: " . $index->kind() . "\n";
59      echo "Target: " . $index->target() . "\n";
60      echo "IsCustom: " . ($index->isCustom() ? "true" : "false") . "\n";
61      echo "Options: " . var_export($index->options(), true) . "\n";
62      """
63    When it is executed
64    Then its output should contain:
65      """
66      Name: name_index
67      Kind: composites
68      Target: name
69      IsCustom: false
70      Options: array (
71        'target' => 'name',
72      )
73      """
74
75  @cassandra-version-3.0
76  Scenario: Getting a custom index metadata
77    Given additional schema:
78      """
79      CREATE CUSTOM INDEX name_custom_index ON users (name) USING 'org.apache.cassandra.index.internal.composites.ClusteringColumnIndex';
80      """
81    And the following example:
82      """php
83      <?php
84      $cluster  = Cassandra::cluster()
85                         ->withContactPoints('127.0.0.1')
86                         ->build();
87      $session  = $cluster->connect("simplex");
88
89      $schema   = $session->schema();
90
91      $index = $schema->keyspace("simplex")->table("users")->index("name_custom_index");
92
93      echo "Name: " . $index->name() . "\n";
94      echo "Kind: " . $index->kind() . "\n";
95      echo "Target: " . $index->target() . "\n";
96      echo "IsCustom: " . ($index->isCustom() ? "true" : "false") . "\n";
97      echo "ClassName: " . $index->className() . "\n";
98      echo "Options: " . var_export($index->options(), true) . "\n";
99      """
100    When it is executed
101    Then its output should contain:
102      """
103      Name: name_custom_index
104      Kind: custom
105      Target: name
106      IsCustom: true
107      ClassName: org.apache.cassandra.index.internal.composites.ClusteringColumnIndex
108      Options: array (
109        'class_name' => 'org.apache.cassandra.index.internal.composites.ClusteringColumnIndex',
110        'target' => 'name',
111      )
112      """
113