Skip to content

Commit e0f52f4

Browse files
author
Sylvain Lebresne
committed
Rename clustering key to clustering columns
1 parent 3eb34e6 commit e0f52f4

File tree

4 files changed

+37
-27
lines changed

4 files changed

+37
-27
lines changed

driver-core/CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ CHANGELOG
55
----------
66

77
- [new] Mark compression dependencies optional in maven (JAVA-199)
8+
- [api] Renamed TableMetadata#getClusteringKey to
9+
TableMetadata#getClusteringColumns.
10+
11+
Merged from 1.0 branch:
12+
- [new] OSGi bundle (JAVA-142)
13+
- [bug] Don't retain unused PreparedStatement in memory (JAVA-201)
14+
- [bug] Add missing clustering order info in TableMetadata
15+
816

917
2.0.0-beta2:
1018
------------

driver-core/Upgrade_guide_to_2.0.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ Other API Changes:
124124
UnavailableException#getConsistencyLevel for consistency with the method of
125125
QueryTimeoutException.
126126

127+
9. The TableMetadata#getClusteringKey method has been renamed
128+
TableMetadata#getClusteringColumns to match the "official" vocabulary.
129+
127130

128131
Non-breaking API Changes
129132
------------------------

driver-core/src/main/java/com/datastax/driver/core/ColumnMetadata.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public String toString() {
183183
// Temporary class that is used to make building the schema easier. Not meant to be
184184
// exposed publicly at all.
185185
static class Raw {
186-
public enum Kind { PARTITION_KEY, CLUSTERING_KEY, REGULAR, COMPACT_VALUE }
186+
public enum Kind { PARTITION_KEY, CLUSTERING_COLUMN, REGULAR, COMPACT_VALUE }
187187

188188
public final String name;
189189
public final Kind kind;

driver-core/src/main/java/com/datastax/driver/core/TableMetadata.java

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public int compare(ColumnMetadata c1, ColumnMetadata c2) {
5050
private final KeyspaceMetadata keyspace;
5151
private final String name;
5252
private final List<ColumnMetadata> partitionKey;
53-
private final List<ColumnMetadata> clusteringKey;
53+
private final List<ColumnMetadata> clusteringColumns;
5454
private final Map<String, ColumnMetadata> columns;
5555
private final Options options;
5656
private final List<Order> clusteringOrder;
@@ -74,14 +74,14 @@ public boolean apply(Order o) {
7474
private TableMetadata(KeyspaceMetadata keyspace,
7575
String name,
7676
List<ColumnMetadata> partitionKey,
77-
List<ColumnMetadata> clusteringKey,
77+
List<ColumnMetadata> clusteringColumns,
7878
LinkedHashMap<String, ColumnMetadata> columns,
7979
Options options,
8080
List<Order> clusteringOrder) {
8181
this.keyspace = keyspace;
8282
this.name = name;
8383
this.partitionKey = partitionKey;
84-
this.clusteringKey = clusteringKey;
84+
this.clusteringColumns = clusteringColumns;
8585
this.columns = columns;
8686
this.options = options;
8787
this.clusteringOrder = clusteringOrder;
@@ -99,12 +99,12 @@ static TableMetadata build(KeyspaceMetadata ksm, Row row, Map<String, ColumnMeta
9999
boolean isCompact = isDense || !comparator.isComposite;
100100

101101
List<ColumnMetadata> partitionKey = nullInitializedList(keyValidator.types.size());
102-
List<ColumnMetadata> clusteringKey = nullInitializedList(clusteringSize);
102+
List<ColumnMetadata> clusteringColumns = nullInitializedList(clusteringSize);
103103
List<Order> clusteringOrder = nullInitializedList(clusteringSize);
104104
// We use a linked hashmap because we will keep this in the order of a 'SELECT * FROM ...'.
105105
LinkedHashMap<String, ColumnMetadata> columns = new LinkedHashMap<String, ColumnMetadata>();
106106

107-
TableMetadata tm = new TableMetadata(ksm, name, partitionKey, clusteringKey, columns, new Options(row, isCompact), clusteringOrder);
107+
TableMetadata tm = new TableMetadata(ksm, name, partitionKey, clusteringColumns, columns, new Options(row, isCompact), clusteringOrder);
108108

109109
// We use this temporary set just so non PK columns are added in lexicographical order, which is the one of a
110110
// 'SELECT * FROM ...'
@@ -116,16 +116,16 @@ static TableMetadata build(KeyspaceMetadata ksm, Row row, Map<String, ColumnMeta
116116
case PARTITION_KEY:
117117
partitionKey.set(rawCol.componentIndex, col);
118118
break;
119-
case CLUSTERING_KEY:
120-
clusteringKey.set(rawCol.componentIndex, col);
119+
case CLUSTERING_COLUMN:
120+
clusteringColumns.set(rawCol.componentIndex, col);
121121
clusteringOrder.set(rawCol.componentIndex, rawCol.isReversed ? Order.DESC : Order.ASC);
122122
break;
123123
}
124124
}
125125

126126
for (ColumnMetadata c : partitionKey)
127127
columns.put(c.getName(), c);
128-
for (ColumnMetadata c : clusteringKey)
128+
for (ColumnMetadata c : clusteringColumns)
129129
columns.put(c.getName(), c);
130130
for (ColumnMetadata c : otherColumns)
131131
columns.put(c.getName(), c);
@@ -137,7 +137,7 @@ static TableMetadata build(KeyspaceMetadata ksm, Row row, Map<String, ColumnMeta
137137
private static int findClusteringSize(Collection<ColumnMetadata.Raw> cols) {
138138
int maxId = -1;
139139
for (ColumnMetadata.Raw col : cols)
140-
if (col.kind == ColumnMetadata.Raw.Kind.CLUSTERING_KEY)
140+
if (col.kind == ColumnMetadata.Raw.Kind.CLUSTERING_COLUMN)
141141
maxId = Math.max(maxId, col.componentIndex);
142142
return maxId + 1;
143143
}
@@ -184,7 +184,7 @@ public ColumnMetadata getColumn(String name) {
184184
* The order of the columns in the list is consistent with
185185
* the order of the columns returned by a {@code SELECT * FROM thisTable}:
186186
* the first column is the partition key, next are the clustering
187-
* keys in their defined order, and then the rest of the
187+
* columns in their defined order, and then the rest of the
188188
* columns follow in alphabetic order.
189189
*
190190
* @return a list containing the metadata for the columns of this table.
@@ -203,9 +203,9 @@ public List<ColumnMetadata> getColumns() {
203203
* @return the list of columns composing the primary key for this table.
204204
*/
205205
public List<ColumnMetadata> getPrimaryKey() {
206-
List<ColumnMetadata> pk = new ArrayList<ColumnMetadata>(partitionKey.size() + clusteringKey.size());
206+
List<ColumnMetadata> pk = new ArrayList<ColumnMetadata>(partitionKey.size() + clusteringColumns.size());
207207
pk.addAll(partitionKey);
208-
pk.addAll(clusteringKey);
208+
pk.addAll(clusteringColumns);
209209
return pk;
210210
}
211211

@@ -222,26 +222,26 @@ public List<ColumnMetadata> getPartitionKey() {
222222
}
223223

224224
/**
225-
* Returns the list of columns composing the clustering key for this table.
225+
* Returns the list of clustering columns for this table.
226226
*
227-
* @return the list of columns composing the clustering key for this table.
228-
* If the clustering key is empty, an empty list is returned.
227+
* @return the list of clustering columns for this table.
228+
* If there is no clustering columns, an empty list is returned.
229229
*/
230-
public List<ColumnMetadata> getClusteringKey() {
231-
return Collections.unmodifiableList(clusteringKey);
230+
public List<ColumnMetadata> getClusteringColumns() {
231+
return Collections.unmodifiableList(clusteringColumns);
232232
}
233233

234234
/**
235235
* Returns the clustering order for this table.
236236
* <p>
237-
* The returned contains the cluster order of each clustering key. The
237+
* The returned contains the clustering order of each clustering column. The
238238
* {@code i}th element of the result correspond to the order (ascending or
239-
* descending) of the {@code i}th clustering key (see
240-
* {@link #getClusteringKey}). Note that a table defined without any
239+
* descending) of the {@code i}th clustering column (see
240+
* {@link #getClusteringColumns}). Note that a table defined without any
241241
* particular clustering order is equivalent to one for which all the
242242
* clustering key are in ascending order.
243243
*
244-
* @return a list with the clustering order for each clustering key.
244+
* @return a list with the clustering order for each clustering column.
245245
*/
246246
public List<Order> getClusteringOrder() {
247247
return clusteringOrder;
@@ -346,7 +346,7 @@ private String asCQLQuery(boolean formatted) {
346346
}
347347
sb.append(")");
348348
}
349-
for (ColumnMetadata cm : clusteringKey)
349+
for (ColumnMetadata cm : clusteringColumns)
350350
sb.append(", ").append(escapeId(cm.getName()));
351351
sb.append(")");
352352
newLine(sb, formatted);
@@ -373,12 +373,11 @@ private String asCQLQuery(boolean formatted) {
373373
return sb.toString();
374374
}
375375

376-
private StringBuilder appendClusteringOrder(StringBuilder sb)
377-
{
376+
private StringBuilder appendClusteringOrder(StringBuilder sb) {
378377
sb.append("CLUSTERING ORDER BY (");
379-
for (int i = 0; i < clusteringKey.size(); i++) {
378+
for (int i = 0; i < clusteringColumns.size(); i++) {
380379
if (i > 0) sb.append(", ");
381-
sb.append(clusteringKey.get(i).getName()).append(" ").append(clusteringOrder.get(i));
380+
sb.append(clusteringColumns.get(i).getName()).append(" ").append(clusteringOrder.get(i));
382381
}
383382
return sb.append(")");
384383
}

0 commit comments

Comments
 (0)