Elffuss BraidHub

kikocis/java-driver public

Merge pull request #452 from datastax/java913

JAVA-913: Redesign IndexMetadata API.
Changeset8e3e8fb031fae6c7c11677a75759bbfbc069643c5185fcb2a5d976fcc19e68df
AuthorAlexandre Dutra <alexdut@gmail.com> · 2015-09-17 18:22 +02:00
CommitterAlexandre Dutra <alexdut@gmail.com> · 2015-09-17 18:22 +02:00
Parentsd4513b28760b, e5ab27d8c358

Browse the files at this changeset

11 files changed

modified driver-core/src/main/java/com/datastax/driver/core/ColumnMetadata.java +3 −27
@@ -15,7 +15,9 @@
1515 */
1616 package com.datastax.driver.core;
1717
18-import java.util.*;
18+import java.util.Arrays;
19+import java.util.HashMap;
20+import java.util.Map;
1921
2022 /**
2123 * Describes a Column.
@@ -42,10 +44,6 @@
4244 private final DataType type;
4345 private final boolean isStatic;
4446
45- // this is the "reverse" side of the many-to-many relationship
46- // between columns and indexes, and is updated only after the column is created
47- final Map<String, IndexMetadata> indexes = new LinkedHashMap<String, IndexMetadata>();
48-
4947 private ColumnMetadata(TableOrView parent, String name, DataType type, boolean isStatic) {
5048 this.parent = parent;
5149 this.name = name;
@@ -98,28 +96,6 @@
9896 return isStatic;
9997 }
10098
101- /**
102- * Returns metadata on a index on this column.
103- *
104- * @param name the name of the index to retrieve ({@code name} will be
105- * interpreted as a case-insensitive identifier unless enclosed in double-quotes,
106- * see {@link Metadata#quote}).
107- * @return the metadata for the {@code name} index if it exists, or
108- * {@code null} otherwise.
109- */
110- public IndexMetadata getIndex(String name) {
111- return indexes.get(Metadata.handleId(name));
112- }
113-
114- /**
115- * Returns a list containing all the indexes on this column.
116- *
117- * @return a list containing the metadata for the indexes on this column.
118- */
119- public List<IndexMetadata> getIndexes() {
120- return new ArrayList<IndexMetadata>(indexes.values());
121- }
122-
12399 @Override
124100 public String toString() {
125101 String str = Metadata.escapeId(name) + ' ' + type;
modified driver-core/src/main/java/com/datastax/driver/core/IndexMetadata.java +77 −158
@@ -15,65 +15,62 @@
1515 */
1616 package com.datastax.driver.core;
1717
18-import java.util.*;
18+import java.util.Iterator;
19+import java.util.Map;
1920
20-import com.google.common.base.Function;
2121 import com.google.common.base.Objects;
22+import com.google.common.base.Predicate;
2223 import com.google.common.collect.ImmutableMap;
24+import com.google.common.collect.Iterables;
2325
2426 /**
2527 * An immutable representation of secondary index metadata.
2628 */
2729 public class IndexMetadata {
2830
29- public enum IndexType {
31+ public enum Kind {
3032 KEYS,
3133 CUSTOM,
3234 COMPOSITES
3335 }
3436
35- public enum TargetType {
36- COLUMN, ROW
37- }
37+ static final String NAME = "index_name";
3838
39- public static final Function<IndexMetadata, String> INDEX_NAME = new Function<IndexMetadata, String>() {
40- @Override
41- public String apply(IndexMetadata input) {
42- return input.getName();
43- }
44- };
39+ static final String KIND = "kind";
4540
46- public static final String CUSTOM_INDEX_OPTION_NAME = "class_name";
41+ static final String OPTIONS = "options";
4742
4843 /**
49- * The name of the option used to specify that the index is on the collection keys.
44+ * The name of the option used to specify the index target (Cassandra 3.0 onwards).
5045 */
51- public static final String INDEX_KEYS_OPTION_NAME = "index_keys";
46+ public static final String TARGET_OPTION_NAME = "target";
47+
48+ /**
49+ * The name of the option used to specify a custom index class name.
50+ */
51+ public static final String CUSTOM_INDEX_OPTION_NAME = "class_name";
5252
5353 /**
54- * The name of the option used to specify that the index is on the collection values.
54+ * The name of the option used to specify that the index is on the collection (map) keys.
5555 */
56- public static final String INDEX_VALUES_OPTION_NAME = "index_values";
56+ public static final String INDEX_KEYS_OPTION_NAME = "index_keys";
5757
5858 /**
5959 * The name of the option used to specify that the index is on the collection (map) entries.
6060 */
6161 public static final String INDEX_ENTRIES_OPTION_NAME = "index_keys_and_values";
6262
63-
6463 private final TableMetadata table;
6564 private final String name;
66- private final Map<String, ColumnMetadata> columns;
67- private final IndexType indexType;
68- private final TargetType targetType;
65+ private final Kind kind;
66+ private final String target;
6967 private final Map<String, String> options;
7068
71- private IndexMetadata(TableMetadata table, String name, Map<String, ColumnMetadata> columns, IndexType indexType, TargetType targetType, Map<String, String> options) {
69+ private IndexMetadata(TableMetadata table, String name, Kind kind, String target, Map<String, String> options) {
7270 this.table = table;
7371 this.name = name;
74- this.columns = columns;
75- this.indexType = indexType;
76- this.targetType = targetType;
72+ this.kind = kind;
73+ this.target = target;
7774 this.options = options;
7875 }
7976
@@ -81,16 +78,11 @@
8178 * Build an IndexMetadata from a system_schema.indexes row.
8279 */
8380 static IndexMetadata fromRow(TableMetadata table, Row indexRow) {
84- String name = indexRow.getString("index_name");
85- Set<String> targetColumnNames = indexRow.getSet("target_columns", String.class);
86- LinkedHashMap<String, ColumnMetadata> targetColumns = new LinkedHashMap<String, ColumnMetadata>(targetColumnNames.size());
87- for (String targetColumnName : targetColumnNames) {
88- targetColumns.put(targetColumnName, table.getColumn(targetColumnName));
89- }
90- IndexMetadata.IndexType indexType = IndexMetadata.IndexType.valueOf(indexRow.getString("index_type"));
91- IndexMetadata.TargetType targetType = IndexMetadata.TargetType.valueOf(indexRow.getString("target_type"));
92- Map<String, String> options = indexRow.getMap("options", String.class, String.class);
93- return new IndexMetadata(table, name, targetColumns, indexType, targetType, options);
81+ String name = indexRow.getString(NAME);
82+ Kind kind = Kind.valueOf(indexRow.getString(KIND));
83+ Map<String, String> options = indexRow.getMap(OPTIONS, String.class, String.class);
84+ String target = options.get(TARGET_OPTION_NAME);
85+ return new IndexMetadata(table, name, kind, target, options);
9486 }
9587
9688 /**
@@ -98,31 +90,44 @@
9890 * along with indexed column).
9991 */
10092 static IndexMetadata fromLegacy(ColumnMetadata column, ColumnMetadata.Raw raw) {
101- if (raw.indexColumns.isEmpty())
93+ Map<String, String> indexColumns = raw.indexColumns;
94+ if (indexColumns.isEmpty())
10295 return null;
103- String type = raw.indexColumns.get(ColumnMetadata.INDEX_TYPE);
96+ String type = indexColumns.get(ColumnMetadata.INDEX_TYPE);
10497 if (type == null)
10598 return null;
106- String indexName = raw.indexColumns.get(ColumnMetadata.INDEX_NAME);
107- String indexTypeStr = raw.indexColumns.get(ColumnMetadata.INDEX_TYPE);
108- IndexType indexType = indexTypeStr == null ? null : IndexType.valueOf(indexTypeStr);
99+ String indexName = indexColumns.get(ColumnMetadata.INDEX_NAME);
100+ String kindStr = indexColumns.get(ColumnMetadata.INDEX_TYPE);
101+ Kind kind = kindStr == null ? null : Kind.valueOf(kindStr);
109102 // Special case check for the value of the index_options column being a string with value 'null' as this
110103 // column appears to be set this way (JAVA-834).
111- String indexOptionsCol = raw.indexColumns.get(ColumnMetadata.INDEX_OPTIONS);
112- ImmutableMap<String, ColumnMetadata> columns = ImmutableMap.of(column.getName(), column);
104+ String indexOptionsCol = indexColumns.get(ColumnMetadata.INDEX_OPTIONS);
113105 Map<String, String> options;
114106 if (indexOptionsCol == null || indexOptionsCol.isEmpty() || indexOptionsCol.equals("null")) {
115107 options = ImmutableMap.of();
116108 } else {
117109 options = SimpleJSONParser.parseStringMap(indexOptionsCol);
118110 }
119- return new IndexMetadata((TableMetadata)column.getParent(), indexName, columns, indexType, TargetType.COLUMN, options);
111+ String target = targetFromLegacyOptions(column, options);
112+ return new IndexMetadata((TableMetadata)column.getParent(), indexName, kind, target, options);
113+ }
114+
115+ private static String targetFromLegacyOptions(ColumnMetadata column, Map<String, String> options) {
116+ String columnName = Metadata.escapeId(column.getName());
117+ if(options.containsKey(INDEX_KEYS_OPTION_NAME))
118+ return String.format("keys(%s)", columnName);
119+ if(options.containsKey(INDEX_ENTRIES_OPTION_NAME))
120+ return String.format("entries(%s)", columnName);
121+ if(column.getType() instanceof DataType.CollectionType && column.getType().isFrozen())
122+ return String.format("full(%s)", columnName);
123+ // Note: the keyword 'values' is not accepted as a valid index target function until 3.0
124+ return columnName;
120125 }
121126
122127 /**
123- * Returns the metadata of the table this column is part of.
128+ * Returns the metadata of the table this index is part of.
124129 *
125- * @return the {@code TableMetadata} for the table this column is part of.
130+ * @return the table this index is part of.
126131 */
127132 public TableMetadata getTable() {
128133 return table;
@@ -138,47 +143,21 @@
138143 }
139144
140145 /**
141- * Returns metadata on a column of this index.
142- *
143- * @param name the name of the column to retrieve ({@code name} will be
144- * interpreted as a case-insensitive identifier unless enclosed in double-quotes,
145- * see {@link Metadata#quote}).
146- * @return the metadata for the column if it exists, or
147- * {@code null} otherwise.
148- */
149- public ColumnMetadata getColumn(String name) {
150- return columns.get(Metadata.handleId(name));
151- }
152-
153- /**
154- * Returns a list containing all the columns of this index.
155- *
156- * The order of the columns in the list is consistent with
157- * the order of the columns in the index.
158- *
159- * @return a list containing the metadata for the columns of this table.
160- */
161- public List<ColumnMetadata> getColumns() {
162- return new ArrayList<ColumnMetadata>(columns.values());
163- }
164-
165- /**
166- * Returns the index type.
146+ * Returns the index kind.
167147 *
168- * @return the index type.
148+ * @return the index kind.
169149 */
170- public IndexType getIndexType() {
171- return indexType;
150+ public Kind getKind() {
151+ return kind;
172152 }
173153
174154 /**
175- * Returns the index target type.
176- * Note: for legacy indexes, this is always {@link TargetType#COLUMN}.
155+ * Returns the index target.
177156 *
178- * @return the index target type.
157+ * @return the index target.
179158 */
180- public TargetType getTargetType() {
181- return targetType;
159+ public String getTarget() {
160+ return target;
182161 }
183162
184163 /**
@@ -204,56 +183,6 @@
204183 return getOption(CUSTOM_INDEX_OPTION_NAME);
205184 }
206185
207- /**
208- * Return whether this index is a 'KEYS' index on a map, e.g.,
209- * CREATE INDEX ON mytable (KEYS(mymap))
210- *
211- * @return {@code true} if this is a 'KEYS' index on a map.
212- */
213- public boolean isKeys() {
214- return getOption(INDEX_KEYS_OPTION_NAME) != null;
215- }
216-
217- /**
218- * Return whether this index is a 'VALUES' index on a map, e.g.,
219- * CREATE INDEX ON mytable (VALUES(mymap))
220- *
221- * @return {@code true} if this is an 'VALUES' index on a map.
222- */
223- public boolean isValues() {
224- return getOption(INDEX_VALUES_OPTION_NAME) != null;
225- }
226-
227- /**
228- * Return whether this index is a 'ENTRIES' index on a map, e.g.,
229- * CREATE INDEX ON mytable (ENTRIES(mymap))
230- *
231- * @return {@code true} if this is an 'ENTRIES' index on a map.
232- */
233- public boolean isEntries() {
234- return getOption(INDEX_ENTRIES_OPTION_NAME) != null;
235- }
236-
237- /**
238- * Return whether this index is a 'FULL' index on a frozen collection, e.g.,
239- * CREATE INDEX ON mytable (FULL(mymap))
240- *
241- * @return {@code true} if this is a 'FULL' index on a frozen collection.
242- */
243- public boolean isFull() {
244- /*
245- * This check is analogous to the Cassandra counterpart
246- * in IndexTarget.
247- */
248- ColumnMetadata column = columns.values().iterator().next();
249- return
250- !isKeys()
251- && !isValues()
252- && !isEntries()
253- && column.getType() instanceof DataType.CollectionType
254- && column.getType().isFrozen();
255- }
256-
257186 /**
258187 * Return the value for the given option name.
259188 *
@@ -273,14 +202,12 @@
273202 * @return the 'CREATE INDEX' query corresponding to this index.
274203 */
275204 public String asCQLQuery() {
276- TableMetadata table = getTable();
277- String ksName = Metadata.escapeId(table.getKeyspace().getName());
278- String cfName = Metadata.escapeId(table.getName());
279- // TODO indexes on multiple columns
280- String colName = Metadata.escapeId(columns.keySet().iterator().next());
205+ String keyspaceName = Metadata.escapeId(table.getKeyspace().getName());
206+ String tableName = Metadata.escapeId(table.getName());
207+ String indexName = Metadata.escapeId(this.name);
281208 return isCustomIndex()
282- ? String.format("CREATE CUSTOM INDEX %s ON %s.%s (%s) USING '%s' WITH OPTIONS = %s;", name, ksName, cfName, colName, getIndexClassName(), getOptionsAsCql())
283- : String.format("CREATE INDEX %s ON %s.%s (%s);", name, ksName, cfName, getIndexFunction(colName));
209+ ? String.format("CREATE CUSTOM INDEX %s ON %s.%s (%s) USING '%s' %s;", indexName, keyspaceName, tableName, getTarget(), getIndexClassName(), getOptionsAsCql())
210+ : String.format("CREATE INDEX %s ON %s.%s (%s);", indexName, keyspaceName, tableName, getTarget());
284211 }
285212
286213 /**
@@ -290,9 +217,18 @@
290217 * the 'index_options' column of the 'schema_columns' table in the 'system' keyspace.
291218 */
292219 private String getOptionsAsCql() {
220+ Iterable<Map.Entry<String, String>> filtered = Iterables.filter(options.entrySet(), new Predicate<Map.Entry<String, String>>() {
221+ @Override
222+ public boolean apply(Map.Entry<String, String> input) {
223+ return
224+ !input.getKey().equals(TARGET_OPTION_NAME) &&
225+ !input.getKey().equals(CUSTOM_INDEX_OPTION_NAME);
226+ }
227+ });
228+ if(Iterables.isEmpty(filtered)) return "";
293229 StringBuilder builder = new StringBuilder();
294- builder.append("{");
295- Iterator<Map.Entry<String, String>> it = options.entrySet().iterator();
230+ builder.append("WITH OPTIONS = {");
231+ Iterator<Map.Entry<String, String>> it = filtered.iterator();
296232 while (it.hasNext()) {
297233 Map.Entry<String, String> option = it.next();
298234 builder.append(String.format("'%s' : '%s'", option.getKey(), option.getValue()));
@@ -303,24 +239,8 @@
303239 return builder.toString();
304240 }
305241
306- /**
307- * Wraps the column name with the appropriate index function (KEYS, FULL, ENTRIES),
308- * if necessary.
309- *
310- * @return Column name wrapped with the appropriate index function.
311- */
312- private String getIndexFunction(String colName) {
313- if (isKeys())
314- return String.format("KEYS(%s)", colName);
315- else if (isFull())
316- return String.format("FULL(%s)", colName);
317- else if (isEntries())
318- return String.format("ENTRIES(%s)", colName);
319- return colName;
320- }
321-
322242 public int hashCode() {
323- return Objects.hashCode(name, columns, indexType, targetType, options);
243+ return Objects.hashCode(name, kind, target, options);
324244 }
325245
326246 public boolean equals(Object obj) {
@@ -333,9 +253,8 @@
333253 IndexMetadata other = (IndexMetadata)obj;
334254
335255 return Objects.equal(name, other.name)
336- && Objects.equal(columns, other.columns)
337- && Objects.equal(indexType, other.indexType)
338- && Objects.equal(targetType, other.targetType)
256+ && Objects.equal(kind, other.kind)
257+ && Objects.equal(target, other.target)
339258 && Objects.equal(options, other.options);
340259 }
341260
modified driver-core/src/main/java/com/datastax/driver/core/MaterializedViewMetadata.java +2 −2
@@ -72,12 +72,12 @@
7272 int clusteringSize = findCollectionSize(rawCols.values(), ColumnMetadata.Raw.Kind.CLUSTERING_COLUMN);
7373 List<ColumnMetadata> partitionKey = nullInitializedList(partitionKeySize);
7474 List<ColumnMetadata> clusteringColumns = nullInitializedList(clusteringSize);
75- List<TableMetadata.Order> clusteringOrder = nullInitializedList(clusteringSize);
75+ List<Order> clusteringOrder = nullInitializedList(clusteringSize);
7676
7777 // We use a linked hashmap because we will keep this in the order of a 'SELECT * FROM ...'.
7878 LinkedHashMap<String, ColumnMetadata> columns = new LinkedHashMap<String, ColumnMetadata>();
7979
80- TableMetadata.Options options = null;
80+ Options options = null;
8181 try {
8282 options = new Options(row, false, cassandraVersion);
8383 } catch (RuntimeException e) {
modified driver-core/src/main/java/com/datastax/driver/core/SchemaParser.java +1 −0
@@ -387,6 +387,7 @@
387387 Map<String, ColumnMetadata.Raw> cols = colsDefs.get(viewName);
388388 if (cols == null || cols.isEmpty())
389389 continue; // we probably raced, we will update the metadata next time
390+
390391 MaterializedViewMetadata view = MaterializedViewMetadata.build(ksm, viewRow, cols, cassandraVersion);
391392 if(view != null)
392393 ksm.add(view);
modified driver-core/src/main/java/com/datastax/driver/core/TableMetadata.java +6 −34
@@ -50,6 +50,7 @@
5050 private static final String EMPTY_TYPE = "org.apache.cassandra.db.marshal.EmptyType";
5151
5252 private final Map<String, IndexMetadata> indexes;
53+
5354 private final Map<String, MaterializedViewMetadata> views;
5455
5556 private TableMetadata(KeyspaceMetadata keyspace,
@@ -177,8 +178,6 @@
177178 }
178179 }
179180
180- Map<ColumnMetadata, Set<IndexMetadata>> indexedColumns = new LinkedHashMap<ColumnMetadata, Set<IndexMetadata>>();
181-
182181 for (ColumnMetadata.Raw rawCol : rawCols.values()) {
183182 ColumnMetadata col = ColumnMetadata.fromRaw(tm, rawCol);
184183 switch (rawCol.kind) {
@@ -193,15 +192,13 @@
193192 otherColumns.add(col);
194193 break;
195194 }
196- // create legacy secondary indexes (C* < 3.0)
195+
196+ // legacy secondary indexes (C* < 3.0)
197197 IndexMetadata index = IndexMetadata.fromLegacy(col, rawCol);
198- if(index != null) {
198+ if(index != null)
199199 indexes.put(index.getName(), index);
200- addIndexToColumn(index, col, indexedColumns);
201- }
202200 }
203201
204-
205202 for (ColumnMetadata c : partitionKey)
206203 columns.put(c.getName(), c);
207204 for (ColumnMetadata c : clusteringColumns)
@@ -214,36 +211,11 @@
214211 for (Row indexRow : indexRows) {
215212 IndexMetadata index = IndexMetadata.fromRow(tm, indexRow);
216213 indexes.put(index.getName(), index);
217- // update the many-to-many relationship between indexes and columns
218- for (ColumnMetadata column : index.getColumns()) {
219- addIndexToColumn(index, column, indexedColumns);
220- }
221- }
222-
223- // update indexed columns
224- for (Map.Entry<ColumnMetadata, Set<IndexMetadata>> entry : indexedColumns.entrySet()) {
225- ColumnMetadata column = entry.getKey();
226- for (IndexMetadata index : entry.getValue()) {
227- // update the "reverse" side of the many-to-many relationship between indexes and columns
228- column.indexes.put(index.getName(), index);
229214 }
230- }
231215
232216 return tm;
233217 }
234218
235- /**
236- * Associate the given index with the given column and store it in the given map.
237- */
238- private static void addIndexToColumn(IndexMetadata index, ColumnMetadata column, Map<ColumnMetadata, Set<IndexMetadata>> indexedColumns) {
239- Set<IndexMetadata> indexes = indexedColumns.get(column);
240- if(indexes == null) {
241- indexes = new LinkedHashSet<IndexMetadata>();
242- indexedColumns.put(column, indexes);
243- }
244- indexes.add(index);
245- }
246-
247219 /**
248220 * Upon migration from thrift to CQL, we internally create a pair of surrogate clustering/regular columns
249221 * for compact static tables. These columns shouldn't be exposed to the user but are currently returned by C*.
@@ -405,8 +377,8 @@
405377 sb.append('\n').append(index.asCQLQuery());
406378 }
407379
408- for (MaterializedViewMetadata index : views.values()) {
409- sb.append('\n').append(index.asCQLQuery());
380+ for (MaterializedViewMetadata view : views.values()) {
381+ sb.append('\n').append(view.asCQLQuery());
410382 }
411383
412384 return sb.toString();
modified driver-core/src/main/java/com/datastax/driver/core/TableOrView.java +5 −1
@@ -225,7 +225,11 @@
225225 * String}.
226226 */
227227 public String exportAsString() {
228- return asCQLQuery(true);
228+ StringBuilder sb = new StringBuilder();
229+
230+ sb.append(asCQLQuery(true));
231+
232+ return sb.toString();
229233 }
230234
231235 /**
modified driver-core/src/test/java/com/datastax/driver/core/ColumnMetadataAssert.java +0 −10
@@ -70,14 +70,4 @@
7070 return this;
7171 }
7272
73- public ColumnMetadataAssert hasIndex(IndexMetadata index) {
74- assertThat(actual.getIndex(index.getName())).isEqualTo(index);
75- return this;
76- }
77-
78- public ColumnMetadataAssert hasSingleIndex(IndexMetadata index) {
79- assertThat(actual.getIndexes()).containsOnly(index);
80- return this;
81- }
82-
8373 }
modified driver-core/src/test/java/com/datastax/driver/core/IndexMetadataAssert.java +13 −36
@@ -19,6 +19,8 @@
1919
2020 import static org.assertj.core.api.Assertions.assertThat;
2121
22+import com.datastax.driver.core.IndexMetadata.Kind;
23+
2224 public class IndexMetadataAssert extends AbstractAssert<IndexMetadataAssert, IndexMetadata> {
2325
2426 public IndexMetadataAssert(IndexMetadata actual) {
@@ -29,7 +31,12 @@
2931 assertThat(actual.getName()).isEqualTo(name);
3032 return this;
3133 }
32-
34+
35+ public IndexMetadataAssert hasParent(TableMetadata parent) {
36+ assertThat(actual.getTable()).isEqualTo(parent);
37+ return this;
38+ }
39+
3340 public IndexMetadataAssert hasOption(String name, String value) {
3441 assertThat(actual.getOption(name)).isEqualTo(value);
3542 return this;
@@ -39,37 +46,7 @@
3946 assertThat(actual.asCQLQuery()).isEqualTo(cqlQuery);
4047 return this;
4148 }
42-
43- public IndexMetadataAssert isKeys(){
44- assertThat(actual.isKeys()).isTrue();
45- return this;
46- }
47-
48- public IndexMetadataAssert isNotKeys(){
49- assertThat(actual.isKeys()).isFalse();
50- return this;
51- }
52-
53- public IndexMetadataAssert isFull() {
54- assertThat(actual.isFull()).isTrue();
55- return this;
56- }
57-
58- public IndexMetadataAssert isNotFull() {
59- assertThat(actual.isFull()).isFalse();
60- return this;
61- }
62-
63- public IndexMetadataAssert isEntries() {
64- assertThat(actual.isEntries()).isTrue();
65- return this;
66- }
67-
68- public IndexMetadataAssert isNotEntries() {
69- assertThat(actual.isEntries()).isFalse();
70- return this;
71- }
72-
49+
7350 public IndexMetadataAssert isCustomIndex() {
7451 assertThat(actual.isCustomIndex()).isTrue();
7552 return this;
@@ -80,13 +57,13 @@
8057 return this;
8158 }
8259
83- public IndexMetadataAssert hasColumn(ColumnMetadata column) {
84- assertThat(actual.getColumn(column.getName())).isEqualTo(column);
60+ public IndexMetadataAssert hasTarget(String target) {
61+ assertThat(actual.getTarget()).isEqualTo(target);
8562 return this;
8663 }
8764
88- public IndexMetadataAssert hasSingleColumn(ColumnMetadata column) {
89- assertThat(actual.getColumns()).containsOnly(column);
65+ public IndexMetadataAssert hasKind(Kind kind) {
66+ assertThat(actual.getKind()).isEqualTo(kind);
9067 return this;
9168 }
9269 }
modified driver-core/src/test/java/com/datastax/driver/core/IndexMetadataTest.java +210 −112
@@ -20,7 +20,9 @@
2020 import java.util.List;
2121
2222 import com.google.common.collect.ImmutableList;
23+import com.google.common.collect.ImmutableMap;
2324 import com.google.common.primitives.Ints;
25+import org.testng.annotations.BeforeClass;
2426 import org.testng.annotations.Test;
2527
2628 import com.datastax.driver.core.ColumnMetadata.*;
@@ -30,15 +32,17 @@
3032 import static com.datastax.driver.core.Assertions.assertThat;
3133 import static com.datastax.driver.core.ColumnMetadata.*;
3234 import static com.datastax.driver.core.DataType.cint;
35+import static com.datastax.driver.core.DataType.map;
3336 import static com.datastax.driver.core.DataType.text;
37+import static com.datastax.driver.core.IndexMetadata.Kind.*;
3438
3539 @CassandraVersion(major = 1.2)
3640 public class IndexMetadataTest extends CCMBridge.PerClassSingleNodeCluster {
3741
3842 /**
39- * Column definitions for schema_columns table.
43+ * Column definitions for schema_columns table (legacy pre-3.0 layout).
4044 */
41- private static final ColumnDefinitions defs = new ColumnDefinitions(new ColumnDefinitions.Definition[]{
45+ private static final ColumnDefinitions legacyColumnDefs = new ColumnDefinitions(new ColumnDefinitions.Definition[]{
4246 definition(COLUMN_NAME, text()),
4347 definition(COMPONENT_INDEX, cint()),
4448 definition(KIND_V2, text()),
@@ -48,192 +52,277 @@
4852 definition(INDEX_OPTIONS, text())
4953 });
5054
51- static {
52- defs.setCodecRegistry(new CodecRegistry());
55+ /**
56+ * Column definitions for indexes table (post-3.0 layout).
57+ */
58+ private static final ColumnDefinitions indexColumnDefs = new ColumnDefinitions(new ColumnDefinitions.Definition[]{
59+ definition(IndexMetadata.NAME, text()),
60+ definition(IndexMetadata.KIND, text()),
61+ definition(IndexMetadata.OPTIONS, map(text(), text()))
62+ });
63+ public static final TypeCodec.MapCodec<String, String> MAP_CODEC = new TypeCodec.MapCodec<String, String>(TypeCodec.VarcharCodec.instance, TypeCodec.VarcharCodec.instance);
64+
65+ private static ProtocolVersion protocolVersion;
66+ private static CodecRegistry codecRegistry;
67+
68+ @BeforeClass(groups = { "short", "long" })
69+ public void beforeClass() {
70+ super.beforeClass();
71+ protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion();
72+ codecRegistry = cluster.getConfiguration().getCodecRegistry();
73+ legacyColumnDefs.setCodecRegistry(codecRegistry);
74+ indexColumnDefs.setCodecRegistry(codecRegistry);
5375 }
5476
5577 @Override
5678 protected Collection<String> getTableDefinitions() {
57- String createTable = "CREATE TABLE indexing ("
58- + "id int primary key,"
59- + "map_values map<text, int>,"
60- + "map_keys map<text, int>,"
61- + "map_entries map<text, int>,"
62- + "text_column text"
63- +
64- // Frozen collections was introduced only in C* 2.1.3
65- (cassandraVersion.compareTo(VersionNumber.parse("2.1.3")) >= 0
66- ?
67- ", map_full frozen<map<text, int>>,"
68- + "set_full frozen<set<text>>,"
69- + "list_full frozen<list<text>>);"
70- :
71- ")");
72- return ImmutableList.of(createTable);
79+ ImmutableList.Builder<String> builder = ImmutableList.builder();
80+ builder.add("CREATE TABLE indexing ("
81+ + "id int,"
82+ + "id2 int,"
83+ + "map_values map<text, int>,"
84+ + "map_keys map<text, int>,"
85+ + "map_entries map<text, int>,"
86+ + "map_all map<text, int>,"
87+ + "text_column text, "
88+ + "\"MixedCaseColumn\" list<text>,"
89+ +
90+ // Frozen collections was introduced only in C* 2.1.3
91+ (cassandraVersion.compareTo(VersionNumber.parse("2.1.3")) >= 0
92+ ?
93+ ", map_full frozen<map<text, int>>,"
94+ + "set_full frozen<set<text>>,"
95+ + "list_full frozen<list<text>>,"
96+ :
97+ "")
98+ + "PRIMARY KEY (id, id2));"
99+ );
100+
101+ return builder.build();
73102 }
74103
75104 @Test(groups = "short")
76- public void should_not_flag_text_column_index_type() {
105+ public void should_create_metadata_for_simple_index() {
77106 String createValuesIndex = String.format("CREATE INDEX text_column_index ON %s.indexing (text_column);", keyspace);
78107 session.execute(createValuesIndex);
79108 ColumnMetadata column = getColumn("text_column");
80109 IndexMetadata index = getIndex("text_column_index");
81- assertThat(index).hasName("text_column_index")
82- .isNotKeys()
83- .isNotFull()
84- .isNotEntries()
110+ assertThat(index)
111+ .hasName("text_column_index")
112+ .hasParent((TableMetadata)column.getParent())
113+ .isNotCustomIndex()
114+ .hasTarget("text_column")
115+ .hasKind(COMPOSITES)
116+ .asCqlQuery(createValuesIndex);
117+ assertThat((TableMetadata) column.getParent()).hasIndex(index);
118+ }
119+
120+ @Test(groups = "short")
121+ @CassandraVersion(major = 2.1, description = "index names with quoted identifiers and collection indexes not supported until 2.1")
122+ public void should_create_metadata_for_values_index_on_mixed_case_column() {
123+ // 3.0 assumes the 'values' keyword if index on a collection
124+ String createValuesIndex = cassandraVersion.getMajor() > 2 ?
125+ String.format("CREATE INDEX \"MixedCaseIndex\" ON %s.indexing (values(\"MixedCaseColumn\"));", keyspace) :
126+ String.format("CREATE INDEX \"MixedCaseIndex\" ON %s.indexing (\"MixedCaseColumn\");", keyspace);
127+ session.execute(createValuesIndex);
128+ ColumnMetadata column = getColumn("\"MixedCaseColumn\"");
129+ IndexMetadata index = getIndex("\"MixedCaseIndex\"");
130+ assertThat(index)
131+ .hasName("MixedCaseIndex")
132+ .hasParent((TableMetadata)column.getParent())
85133 .isNotCustomIndex()
86- .hasSingleColumn(getColumn("text_column"))
134+ .hasTarget(cassandraVersion.getMajor() > 2 ? "values(\"MixedCaseColumn\")" : "\"MixedCaseColumn\"")
135+ .hasKind(COMPOSITES)
87136 .asCqlQuery(createValuesIndex);
88- assertThat(index).isSameAs(column.getIndex("text_column_index"));
89- assertThat(column).hasSingleIndex(index);
90- assertThat(column).isSameAs(index.getColumn("text_column"));
137+ assertThat((TableMetadata) column.getParent()).hasIndex(index);
91138 }
92139
93140 @Test(groups = "short")
94141 @CassandraVersion(major = 2.1)
95- public void should_not_flag_map_index_type() {
96- String createValuesIndex = String.format("CREATE INDEX map_values_index ON %s.indexing (map_values);", keyspace);
142+ public void should_create_metadata_for_index_on_map_values() {
143+ // 3.0 assumes the 'values' keyword if index on a collection
144+ String createValuesIndex = cassandraVersion.getMajor() > 2 ?
145+ String.format("CREATE INDEX map_values_index ON %s.indexing (values(map_values));", keyspace) :
146+ String.format("CREATE INDEX map_values_index ON %s.indexing (map_values);", keyspace);
97147 session.execute(createValuesIndex);
98148 ColumnMetadata column = getColumn("map_values");
99149 IndexMetadata index = getIndex("map_values_index");
100- assertThat(index).hasName("map_values_index")
101- .isNotKeys()
102- .isNotFull()
103- .isNotEntries()
150+ assertThat(index)
151+ .hasName("map_values_index")
152+ .hasParent((TableMetadata)column.getParent())
104153 .isNotCustomIndex()
105- .hasSingleColumn(getColumn("map_values"))
154+ .hasTarget(cassandraVersion.getMajor() > 2 ? "values(map_values)" : "map_values")
155+ .hasKind(COMPOSITES)
106156 .asCqlQuery(createValuesIndex);
107- assertThat(index).isSameAs(column.getIndex("map_values_index"));
108- assertThat(column).hasSingleIndex(index);
109- assertThat(column).isSameAs(index.getColumn("map_values"));
157+ assertThat((TableMetadata) column.getParent()).hasIndex(index);
110158 }
111159
112160 @Test(groups = "short")
113161 @CassandraVersion(major = 2.1)
114- public void should_flag_map_index_type_as_keys() {
115- String createKeysIndex = String.format("CREATE INDEX map_keys_index ON %s.indexing (KEYS(map_keys));", keyspace);
162+ public void should_create_metadata_for_index_on_map_keys() {
163+ String createKeysIndex = String.format("CREATE INDEX map_keys_index ON %s.indexing (keys(map_keys));", keyspace);
116164 session.execute(createKeysIndex);
117165 ColumnMetadata column = getColumn("map_keys");
118166 IndexMetadata index = getIndex("map_keys_index");
119- assertThat(index).hasName("map_keys_index")
120- .isKeys()
121- .isNotFull()
122- .isNotEntries()
167+ assertThat(index)
168+ .hasName("map_keys_index")
169+ .hasParent((TableMetadata)column.getParent())
123170 .isNotCustomIndex()
124- .hasSingleColumn(getColumn("map_keys"))
171+ .hasTarget("keys(map_keys)")
172+ .hasKind(COMPOSITES)
125173 .asCqlQuery(createKeysIndex);
126- assertThat(index).isSameAs(column.getIndex("map_keys_index"));
127- assertThat(column).hasSingleIndex(index);
128- assertThat(column).isSameAs(index.getColumn("map_keys"));
174+ assertThat((TableMetadata) column.getParent()).hasIndex(index);
129175 }
130176
131177 @Test(groups = "short")
132178 @CassandraVersion(major = 2.1, minor = 3)
133- public void should_flag_map_index_type_as_full() {
134- String createFullIndex = String.format("CREATE INDEX map_full_index ON %s.indexing (FULL(map_full));", keyspace);
179+ public void should_create_metadata_for_full_index_on_map() {
180+ String createFullIndex = String.format("CREATE INDEX map_full_index ON %s.indexing (full(map_full));", keyspace);
135181 session.execute(createFullIndex);
136182 ColumnMetadata column = getColumn("map_full");
137183 IndexMetadata index = getIndex("map_full_index");
138- assertThat(index).hasName("map_full_index")
139- .isNotKeys()
140- .isFull()
141- .isNotEntries()
184+ assertThat(index)
185+ .hasName("map_full_index")
186+ .hasParent((TableMetadata)column.getParent())
142187 .isNotCustomIndex()
143- .hasSingleColumn(getColumn("map_full"))
188+ .hasTarget("full(map_full)")
189+ .hasKind(COMPOSITES)
144190 .asCqlQuery(createFullIndex);
145- assertThat(index).isSameAs(column.getIndex("map_full_index"));
146- assertThat(column).hasSingleIndex(index);
147- assertThat(column).isSameAs(index.getColumn("map_full"));
191+ assertThat((TableMetadata) column.getParent()).hasIndex(index);
148192 }
149193
150194 @Test(groups = "short")
151195 @CassandraVersion(major = 2.1, minor = 3)
152- public void should_flag_set_index_type_as_full() {
153- String createFullIndex = String.format("CREATE INDEX set_full_index ON %s.indexing (FULL(set_full));", keyspace);
196+ public void should_create_metadata_for_full_index_on_set() {
197+ String createFullIndex = String.format("CREATE INDEX set_full_index ON %s.indexing (full(set_full));", keyspace);
154198 session.execute(createFullIndex);
155199 ColumnMetadata column = getColumn("set_full");
156200 IndexMetadata index = getIndex("set_full_index");
157- assertThat(index).hasName("set_full_index")
158- .isNotKeys()
159- .isFull()
160- .isNotEntries()
201+ assertThat(index)
202+ .hasName("set_full_index")
203+ .hasParent((TableMetadata)column.getParent())
161204 .isNotCustomIndex()
162- .hasSingleColumn(getColumn("set_full"))
205+ .hasTarget("full(set_full)")
206+ .hasKind(COMPOSITES)
163207 .asCqlQuery(createFullIndex);
164- assertThat(index).isSameAs(column.getIndex("set_full_index"));
165- assertThat(column).hasSingleIndex(index);
166- assertThat(column).isSameAs(index.getColumn("set_full"));
208+ assertThat((TableMetadata) column.getParent()).hasIndex(index);
167209 }
168210
169211 @Test(groups = "short")
170212 @CassandraVersion(major = 2.1, minor = 3)
171- public void should_flag_list_index_type_as_full() {
172- String createFullIndex = String.format("CREATE INDEX list_full_index ON %s.indexing (FULL(list_full));", keyspace);
213+ public void should_create_metadata_for_full_index_on_list() {
214+ String createFullIndex = String.format("CREATE INDEX list_full_index ON %s.indexing (full(list_full));", keyspace);
173215 session.execute(createFullIndex);
174216 ColumnMetadata column = getColumn("list_full");
175217 IndexMetadata index = getIndex("list_full_index");
176- assertThat(index).hasName("list_full_index")
177- .isNotKeys()
178- .isFull()
179- .isNotEntries()
218+ assertThat(index)
219+ .hasName("list_full_index")
220+ .hasParent((TableMetadata)column.getParent())
180221 .isNotCustomIndex()
181- .hasSingleColumn(getColumn("list_full"))
222+ .hasTarget("full(list_full)")
223+ .hasKind(COMPOSITES)
182224 .asCqlQuery(createFullIndex);
183- assertThat(index).isSameAs(column.getIndex("list_full_index"));
184- assertThat(column).hasSingleIndex(index);
185- assertThat(column).isSameAs(index.getColumn("list_full"));
225+ assertThat((TableMetadata) column.getParent()).hasIndex(index);
186226 }
187227
188228 @Test(groups = "short")
189229 @CassandraVersion(major = 2.2)
190- public void should_flag_map_index_type_as_entries() {
191- String createEntriesIndex = String.format("CREATE INDEX map_entries_index ON %s.indexing (ENTRIES(map_entries));", keyspace);
230+ public void should_create_metadata_for_index_on_map_entries() {
231+ String createEntriesIndex = String.format("CREATE INDEX map_entries_index ON %s.indexing (entries(map_entries));", keyspace);
192232 session.execute(createEntriesIndex);
193233 ColumnMetadata column = getColumn("map_entries");
194234 IndexMetadata index = getIndex("map_entries_index");
195- assertThat(index).hasName("map_entries_index")
196- .isNotKeys()
197- .isNotFull()
198- .isEntries()
235+ assertThat(index)
236+ .hasName("map_entries_index")
237+ .hasParent((TableMetadata)column.getParent())
199238 .isNotCustomIndex()
200- .hasSingleColumn(getColumn("map_entries"))
239+ .hasTarget("entries(map_entries)")
240+ .hasKind(COMPOSITES)
241+ .asCqlQuery(createEntriesIndex);
242+ assertThat((TableMetadata) column.getParent()).hasIndex(index);
243+ }
244+
245+ @Test(groups = "short")
246+ @CassandraVersion(major = 3.0)
247+ public void should_allow_multiple_indexes_on_map_column() {
248+ String createEntriesIndex = String.format("CREATE INDEX map_all_entries_index ON %s.indexing (entries(map_all));", keyspace);
249+ session.execute(createEntriesIndex);
250+ String createKeysIndex = String.format("CREATE INDEX map_all_keys_index ON %s.indexing (keys(map_all));", keyspace);
251+ session.execute(createKeysIndex);
252+ String createValuesIndex = String.format("CREATE INDEX map_all_values_index ON %s.indexing (values(map_all));", keyspace);
253+ session.execute(createValuesIndex);
254+
255+ ColumnMetadata column = getColumn("map_all");
256+ TableMetadata table = (TableMetadata)column.getParent();
257+
258+ assertThat(getIndex("map_all_entries_index"))
259+ .hasParent(table)
201260 .asCqlQuery(createEntriesIndex);
202- assertThat(index).isSameAs(column.getIndex("map_entries_index"));
203- assertThat(column).hasSingleIndex(index);
204- assertThat(column).isSameAs(index.getColumn("map_entries"));
261+
262+ assertThat(getIndex("map_all_keys_index"))
263+ .hasParent(table)
264+ .asCqlQuery(createKeysIndex);
265+
266+ assertThat(getIndex("map_all_values_index"))
267+ .hasParent(table)
268+ .asCqlQuery(createValuesIndex);
205269 }
206270
207271 @Test(
208272 groups = "short",
209- description = "This test case builds a ColumnMetadata object programmatically to test custom indices,"
273+ description = "This test case builds a ColumnMetadata object programmatically to test custom indices with pre-3.0 layout,"
210274 + "otherwise, it would require deploying an actual custom index class into the C* test cluster")
211- public void should_parse_custom_index_options() {
275+ public void should_parse_legacy_custom_index_options() {
212276 TableMetadata table = getTable("indexing");
213- List<ByteBuffer> data = ImmutableList.of(
277+ List<ByteBuffer> columnData = ImmutableList.of(
214278 wrap("text_column"), // column name
215279 wrap(0), // component index
216- wrap("regular"), // kind
280+ wrap("regular"), // column kind
217281 wrap("custom_index"), // index name
218282 wrap("CUSTOM"), // index type
219283 wrap("org.apache.cassandra.db.marshal.UTF8Type"), // validator
220284 wrap("{\"foo\" : \"bar\", \"class_name\" : \"dummy.DummyIndex\"}") // index options
221285 );
222- Row row = ArrayBackedRow.fromData(defs, M3PToken.FACTORY, cluster.getConfiguration().getProtocolOptions().getProtocolVersion(), data);
223- Raw raw = Raw.fromRow(row, VersionNumber.parse("2.1"),
224- cluster.getConfiguration().getProtocolOptions().getProtocolVersion(),
225- cluster.getConfiguration().getCodecRegistry());
226- ColumnMetadata column = ColumnMetadata.fromRaw(table, raw);
227- IndexMetadata index = IndexMetadata.fromLegacy(column, raw);
228- assertThat(index).hasName("custom_index")
229- .isNotKeys()
230- .isNotFull()
231- .isNotEntries()
286+ Row columnRow = ArrayBackedRow.fromData(legacyColumnDefs, M3PToken.FACTORY, protocolVersion, columnData);
287+ Raw columnRaw = Raw.fromRow(columnRow, VersionNumber.parse("2.1"), protocolVersion, codecRegistry);
288+ ColumnMetadata column = ColumnMetadata.fromRaw(table, columnRaw);
289+ IndexMetadata index = IndexMetadata.fromLegacy(column, columnRaw);
290+ assertThat(index)
291+ .isNotNull()
292+ .hasName("custom_index")
232293 .isCustomIndex()
233- .hasSingleColumn(column)
234294 .hasOption("foo", "bar")
295+ .hasKind(CUSTOM)
235296 .asCqlQuery(String.format("CREATE CUSTOM INDEX custom_index ON %s.indexing (text_column) "
236- + "USING 'dummy.DummyIndex' WITH OPTIONS = {'foo' : 'bar', 'class_name' : 'dummy.DummyIndex'};", keyspace));
297+ + "USING 'dummy.DummyIndex' WITH OPTIONS = {'foo' : 'bar'};", keyspace));
298+ }
299+
300+ @Test(
301+ groups = "short",
302+ description = "This test case builds a ColumnMetadata object programmatically to test custom indices with post-3.0 layout,"
303+ + "otherwise, it would require deploying an actual custom index class into the C* test cluster")
304+ public void should_parse_custom_index_options() {
305+ TableMetadata table = getTable("indexing");
306+ List<ByteBuffer> indexData = ImmutableList.of(
307+ wrap("custom_index"), // index name
308+ wrap("CUSTOM"), // kind
309+ MAP_CODEC.serialize(ImmutableMap.of(
310+ "foo", "bar",
311+ IndexMetadata.CUSTOM_INDEX_OPTION_NAME, "dummy.DummyIndex",
312+ IndexMetadata.TARGET_OPTION_NAME, "a, b, keys(c)"
313+ ), protocolVersion) // options
314+ );
315+ Row indexRow = ArrayBackedRow.fromData(indexColumnDefs, M3PToken.FACTORY, protocolVersion, indexData);
316+ IndexMetadata index = IndexMetadata.fromRow(table, indexRow);
317+ assertThat(index)
318+ .isNotNull()
319+ .hasName("custom_index")
320+ .isCustomIndex()
321+ .hasOption("foo", "bar")
322+ .hasTarget("a, b, keys(c)")
323+ .hasKind(CUSTOM)
324+ .asCqlQuery(String.format("CREATE CUSTOM INDEX custom_index ON %s.indexing (a, b, keys(c)) "
325+ + "USING 'dummy.DummyIndex' WITH OPTIONS = {'foo' : 'bar'};", keyspace));
237326 }
238327
239328 /**
@@ -257,19 +346,20 @@
257346 wrap("org.apache.cassandra.db.marshal.BytesType"), // validator
258347 wrap("null") // index options
259348 );
260- Row row = ArrayBackedRow.fromData(defs, M3PToken.FACTORY, cluster.getConfiguration().getProtocolOptions().getProtocolVersion(), data);
349+ Row row = ArrayBackedRow.fromData(legacyColumnDefs, M3PToken.FACTORY, cluster.getConfiguration().getProtocolOptions().getProtocolVersion(), data);
261350 Raw raw = Raw.fromRow(row, VersionNumber.parse("2.1"),
262351 cluster.getConfiguration().getProtocolOptions().getProtocolVersion(),
263352 cluster.getConfiguration().getCodecRegistry());
264353 ColumnMetadata column = ColumnMetadata.fromRaw(table, raw);
265354 IndexMetadata index = IndexMetadata.fromLegacy(column, raw);
266- assertThat(index).hasName("cfs_archive_parent_path")
267- .isNotKeys() // While the index type is KEYS, since it lacks index_options it does not considered.
268- .isNotFull()
269- .isNotEntries()
355+ assertThat(index)
356+ .isNotNull()
357+ .hasName("cfs_archive_parent_path")
270358 .isNotCustomIndex()
271- .hasSingleColumn(column)
359+ .hasTarget("\"b@706172656e745f70617468\"")
360+ .hasKind(KEYS)
272361 .asCqlQuery(String.format("CREATE INDEX cfs_archive_parent_path ON %s.indexing (\"b@706172656e745f70617468\");", keyspace));
362+ assertThat(index.getOption(IndexMetadata.INDEX_KEYS_OPTION_NAME)).isNull(); // While the index type is KEYS, since it lacks index_options it does not get considered.
273363 }
274364
275365 private static ColumnDefinitions.Definition definition(String name, DataType type) {
@@ -285,7 +375,12 @@
285375 }
286376
287377 private ColumnMetadata getColumn(String name) {
288- return getTable("indexing").getColumn(name);
378+ return getColumn(name, true);
379+ }
380+
381+ private ColumnMetadata getColumn(String name, boolean fromTable) {
382+ TableOrView target = fromTable ? getTable("indexing") : getMaterializedView("mv1");
383+ return target.getColumn(name);
289384 }
290385
291386 private IndexMetadata getIndex(String name) {
@@ -296,4 +391,7 @@
296391 return cluster.getMetadata().getKeyspace(keyspace).getTable(name);
297392 }
298393
394+ private MaterializedViewMetadata getMaterializedView(String name) {
395+ return cluster.getMetadata().getKeyspace(keyspace).getMaterializedView(name);
396+ }
299397 }
modified driver-core/src/test/java/com/datastax/driver/core/MaterializedViewMetadataTest.java +2 −2
@@ -46,10 +46,10 @@
4646 keyspace);
4747 String createMV = String.format(
4848 "CREATE MATERIALIZED VIEW %s.monthlyhigh AS "
49- + "SELECT user FROM %s.scores "
49+ + "SELECT game, year, month, score, user, day FROM %s.scores "
5050 + "WHERE game IS NOT NULL AND year IS NOT NULL AND month IS NOT NULL AND score IS NOT NULL AND user IS NOT NULL AND day IS NOT NULL "
5151 + "PRIMARY KEY ((game, year, month), score, user, day) "
52- + "WITH CLUSTERING ORDER BY (score DESC)",
52+ + "WITH CLUSTERING ORDER BY (score DESC, user ASC, day ASC)",
5353 keyspace, keyspace);
5454
5555 // when
modified driver-core/src/test/java/com/datastax/driver/core/TableMetadataAssert.java +5 −0
@@ -49,4 +49,9 @@
4949 assertThat(actual.getView(expected.getName())).isNotNull().isEqualTo(expected);
5050 return this;
5151 }
52+
53+ public TableMetadataAssert hasIndex(IndexMetadata index) {
54+ assertThat(actual.getIndexes()).contains(index);
55+ return this;
56+ }
5257 }