kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 787c0e2ddd145e9acd06209f5d47c2ffdc91b6ff420a3f625377e5f024770f5f |
|---|---|
| Author | Olivier Michallat <olim7t@users.noreply.github.com> · 2015-07-17 15:49 +02:00 |
| Committer | Olivier Michallat <olim7t@users.noreply.github.com> · 2015-07-17 15:49 +02:00 |
| Parents | 8298aa6ec275, 7f7e981b93ef |
3 files changed
modified changelog/README.md +5 −0
| @@ -1,5 +1,10 @@ | ||
| 1 | 1 | ## Changelog |
| 2 | 2 | |
| 3 | +### 2.1.7.1 | |
| 4 | + | |
| 5 | +- [bug] Special case check for 'null' string in index_options column (JAVA-834) | |
| 6 | + | |
| 7 | + | |
| 3 | 8 | ### 2.1.7 |
| 4 | 9 | |
| 5 | 10 | - [improvement] Improve QueryBuilder API for SELECT DISTINCT (JAVA-475) |
modified driver-core/src/main/java/com/datastax/driver/core/ColumnMetadata.java +8 −3
| @@ -277,11 +277,16 @@ | ||
| 277 | 277 | if (type == null) |
| 278 | 278 | return null; |
| 279 | 279 | |
| 280 | - if (!indexColumns.containsKey(INDEX_OPTIONS)) | |
| 280 | + // Special case check for the value of the index_options column being a string with value 'null' as this | |
| 281 | + // column appears to be set this way (JAVA-834). | |
| 282 | + String indexOptionsCol = indexColumns.get(INDEX_OPTIONS); | |
| 283 | + if (indexOptionsCol == null || indexOptionsCol.isEmpty() || indexOptionsCol.equals("null")) | |
| 281 | 284 | return new IndexMetadata(column, indexColumns.get(INDEX_NAME)); |
| 285 | + else { | |
| 286 | + Map<String, String> indexOptions = SimpleJSONParser.parseStringMap(indexOptionsCol); | |
| 287 | + return new IndexMetadata(column, indexColumns.get(INDEX_NAME), indexOptions); | |
| 288 | + } | |
| 282 | 289 | |
| 283 | - Map<String, String> indexOptions = SimpleJSONParser.parseStringMap(indexColumns.get(INDEX_OPTIONS)); | |
| 284 | - return new IndexMetadata(column, indexColumns.get(INDEX_NAME), indexOptions); | |
| 285 | 290 | } |
| 286 | 291 | } |
| 287 | 292 |
modified driver-core/src/test/java/com/datastax/driver/core/IndexMetadataTest.java +51 −12
| @@ -43,6 +43,19 @@ | ||
| 43 | 43 | major = 1.2) |
| 44 | 44 | public class IndexMetadataTest extends CCMBridge.PerClassSingleNodeCluster { |
| 45 | 45 | |
| 46 | + /** | |
| 47 | + * Column definitions for schema_columns table. | |
| 48 | + */ | |
| 49 | + private static final ColumnDefinitions defs = new ColumnDefinitions(new ColumnDefinitions.Definition[] { | |
| 50 | + definition(COLUMN_NAME, text()), | |
| 51 | + definition(COMPONENT_INDEX, cint()), | |
| 52 | + definition(KIND, text()), | |
| 53 | + definition(INDEX_NAME, text()), | |
| 54 | + definition(INDEX_TYPE, text()), | |
| 55 | + definition(VALIDATOR, text()), | |
| 56 | + definition(INDEX_OPTIONS, text()) | |
| 57 | + }); | |
| 58 | + | |
| 46 | 59 | @Override |
| 47 | 60 | protected Collection<String> getTableDefinitions() { |
| 48 | 61 | String createTable = "CREATE TABLE indexing (" |
| @@ -182,15 +195,6 @@ | ||
| 182 | 195 | + "otherwise, it would require deploying an actual custom index class into the C* test cluster") |
| 183 | 196 | public void should_parse_custom_index_options() { |
| 184 | 197 | TableMetadata table = getTable("indexing"); |
| 185 | - ColumnDefinitions defs = new ColumnDefinitions(new ColumnDefinitions.Definition[] { | |
| 186 | - definition(COLUMN_NAME, text()), | |
| 187 | - definition(COMPONENT_INDEX, cint()), | |
| 188 | - definition(KIND, text()), | |
| 189 | - definition(INDEX_NAME, text()), | |
| 190 | - definition(INDEX_TYPE, text()), | |
| 191 | - definition(VALIDATOR, text()), | |
| 192 | - definition(INDEX_OPTIONS, text()) | |
| 193 | - }); | |
| 194 | 198 | List<ByteBuffer> data = ImmutableList.of( |
| 195 | 199 | wrap("text_column"), // column name |
| 196 | 200 | wrap(0), // component index |
| @@ -213,15 +217,50 @@ | ||
| 213 | 217 | + "USING 'dummy.DummyIndex' WITH OPTIONS = {'foo' : 'bar', 'class_name' : 'dummy.DummyIndex'};", keyspace)); |
| 214 | 218 | } |
| 215 | 219 | |
| 216 | - private ColumnDefinitions.Definition definition(String name, DataType type) { | |
| 220 | + /** | |
| 221 | + * Validates a special case where a 'KEYS' index was created using thrift. In this particular case the index lacks | |
| 222 | + * index_options, however the index_options value is a 'null' string rather then a null value. | |
| 223 | + * | |
| 224 | + * @test_category metadata | |
| 225 | + * @expected_result Index properly parsed and is present. | |
| 226 | + * @jira_ticket JAVA-834 | |
| 227 | + * @since 2.0.11, 2.1.7 | |
| 228 | + */ | |
| 229 | + @Test(groups = "short") | |
| 230 | + public void should_parse_with_null_string_index_options() { | |
| 231 | + TableMetadata table = getTable("indexing"); | |
| 232 | + | |
| 233 | + List<ByteBuffer> data = ImmutableList.of( | |
| 234 | + wrap("b@706172656e745f70617468"), // column name 'parent_path' | |
| 235 | + ByteBuffer.allocate(0), // component index (null) | |
| 236 | + wrap("regular"), // kind | |
| 237 | + wrap("cfs_archive_parent_path"), // index name | |
| 238 | + wrap("KEYS"), // index type | |
| 239 | + wrap("org.apache.cassandra.db.marshal.BytesType"), // validator | |
| 240 | + wrap("null") // index options | |
| 241 | + ); | |
| 242 | + Row row = ArrayBackedRow.fromData(defs, M3PToken.FACTORY, ProtocolVersion.V3, data); | |
| 243 | + ColumnMetadata column = ColumnMetadata.fromRaw(table, Raw.fromRow(row, VersionNumber.parse("2.1"))); | |
| 244 | + IndexMetadata index = column.getIndex(); | |
| 245 | + | |
| 246 | + assertThat(index).hasName("cfs_archive_parent_path") | |
| 247 | + .isNotKeys() // While the index type is KEYS, since it lacks index_options it does not considered. | |
| 248 | + .isNotFull() | |
| 249 | + .isNotEntries() | |
| 250 | + .isNotCustomIndex() | |
| 251 | + .asCqlQuery(String.format("CREATE INDEX cfs_archive_parent_path ON %s.indexing (\"b@706172656e745f70617468\");", keyspace)); | |
| 252 | + } | |
| 253 | + | |
| 254 | + | |
| 255 | + private static ColumnDefinitions.Definition definition(String name, DataType type) { | |
| 217 | 256 | return new ColumnDefinitions.Definition("ks", "table", name, type); |
| 218 | 257 | } |
| 219 | 258 | |
| 220 | - private ByteBuffer wrap(String value) { | |
| 259 | + private static ByteBuffer wrap(String value) { | |
| 221 | 260 | return ByteBuffer.wrap(value.getBytes()); |
| 222 | 261 | } |
| 223 | 262 | |
| 224 | - private ByteBuffer wrap(int number) { | |
| 263 | + private static ByteBuffer wrap(int number) { | |
| 225 | 264 | return ByteBuffer.wrap(Ints.toByteArray(number)); |
| 226 | 265 | } |
| 227 | 266 |