Elffuss BraidHub

kikocis/java-driver public

JAVA-834 Special case check for 'null' string in index_options column.
Changeset7f7e981b93ef35ec868f2b439e750002bff60635473ac78ffdae41371bd470ec
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-07-15 16:09 -05:00
Committerolim7t <omichallat+github@gmail.com> · 2015-07-17 15:41 +02:00
Parents6a5e82da7ff4

Browse the files at this changeset

3 files changed

modified changelog/README.md +5 −0
@@ -1,5 +1,10 @@
11 ## Changelog
22
3+### 2.1.7.1
4+
5+- [bug] Special case check for 'null' string in index_options column (JAVA-834)
6+
7+
38 ### 2.1.7
49
510 - [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 @@
277277 if (type == null)
278278 return null;
279279
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"))
281284 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+ }
282289
283- Map<String, String> indexOptions = SimpleJSONParser.parseStringMap(indexColumns.get(INDEX_OPTIONS));
284- return new IndexMetadata(column, indexColumns.get(INDEX_NAME), indexOptions);
285290 }
286291 }
287292
modified driver-core/src/test/java/com/datastax/driver/core/IndexMetadataTest.java +51 −12
@@ -43,6 +43,19 @@
4343 major = 1.2)
4444 public class IndexMetadataTest extends CCMBridge.PerClassSingleNodeCluster {
4545
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+
4659 @Override
4760 protected Collection<String> getTableDefinitions() {
4861 String createTable = "CREATE TABLE indexing ("
@@ -182,15 +195,6 @@
182195 + "otherwise, it would require deploying an actual custom index class into the C* test cluster")
183196 public void should_parse_custom_index_options() {
184197 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- });
194198 List<ByteBuffer> data = ImmutableList.of(
195199 wrap("text_column"), // column name
196200 wrap(0), // component index
@@ -213,15 +217,50 @@
213217 + "USING 'dummy.DummyIndex' WITH OPTIONS = {'foo' : 'bar', 'class_name' : 'dummy.DummyIndex'};", keyspace));
214218 }
215219
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) {
217256 return new ColumnDefinitions.Definition("ks", "table", name, type);
218257 }
219258
220- private ByteBuffer wrap(String value) {
259+ private static ByteBuffer wrap(String value) {
221260 return ByteBuffer.wrap(value.getBytes());
222261 }
223262
224- private ByteBuffer wrap(int number) {
263+ private static ByteBuffer wrap(int number) {
225264 return ByteBuffer.wrap(Ints.toByteArray(number));
226265 }
227266