kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 833376cd67158e0eedd36d8d15813fb29c1531cf2fbfa68c51d2ea10899a1fea |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2016-01-13 17:31 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-01-15 16:00 +01:00 |
| Parents | d854e0040cd7 |
3 files changed
modified changelog/README.md +2 −0
| @@ -2,6 +2,8 @@ | ||
| 2 | 2 | |
| 3 | 3 | ### 3.0.0 (in progress) |
| 4 | 4 | |
| 5 | +- [bug] JAVA-1034: fix metadata parser for collections of custom types. | |
| 6 | + | |
| 5 | 7 | Merged from 2.1 branch: |
| 6 | 8 | |
| 7 | 9 | - [improvement] JAVA-1030: Log token to replica map computation times. |
modified driver-core/src/main/java/com/datastax/driver/core/DataTypeCqlNameParser.java +5 −2
| @@ -200,8 +200,7 @@ | ||
| 200 | 200 | // left idx positioned on the character stopping the read |
| 201 | 201 | private String readNextIdentifier() { |
| 202 | 202 | int startIdx = idx; |
| 203 | - // if first character is a quote, this is a quoted identifier. | |
| 204 | - if (str.charAt(startIdx) == '"') { | |
| 203 | + if (str.charAt(startIdx) == '"') { // case-sensitive name included in double quotes | |
| 205 | 204 | ++idx; |
| 206 | 205 | // read until closing quote. |
| 207 | 206 | while (!isEOS()) { |
| @@ -216,6 +215,10 @@ | ||
| 216 | 215 | break; |
| 217 | 216 | } |
| 218 | 217 | } |
| 218 | + } else if (str.charAt(startIdx) == '\'') { // custom type name included in single quotes | |
| 219 | + ++idx; | |
| 220 | + // read until closing quote. | |
| 221 | + while (!isEOS() && str.charAt(idx++) != '\'') { /* loop */ } | |
| 219 | 222 | } else { |
| 220 | 223 | while (!isEOS() && (isIdentifierChar(str.charAt(idx)) || str.charAt(idx) == '"')) |
| 221 | 224 | ++idx; |
modified driver-core/src/test/java/com/datastax/driver/core/CustomTypeTest.java +36 −3
| @@ -16,13 +16,14 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | import com.datastax.driver.core.utils.CassandraVersion; |
| 19 | +import com.google.common.collect.Lists; | |
| 19 | 20 | import org.testng.annotations.Test; |
| 20 | 21 | |
| 21 | 22 | import java.nio.ByteBuffer; |
| 22 | 23 | import java.util.ArrayList; |
| 23 | 24 | import java.util.Collection; |
| 24 | -import java.util.Collections; | |
| 25 | 25 | import java.util.List; |
| 26 | +import java.util.Map; | |
| 26 | 27 | |
| 27 | 28 | import static com.datastax.driver.core.Assertions.assertThat; |
| 28 | 29 | import static com.datastax.driver.core.DataType.cint; |
| @@ -45,14 +46,19 @@ | ||
| 45 | 46 | |
| 46 | 47 | @Override |
| 47 | 48 | public Collection<String> createTestFixtures() { |
| 48 | - return Collections.singleton( | |
| 49 | + return Lists.newArrayList( | |
| 49 | 50 | "CREATE TABLE test (" |
| 50 | 51 | + " k int," |
| 51 | 52 | + " c1 'DynamicCompositeType(s => UTF8Type, i => Int32Type)'," |
| 52 | 53 | + " c2 'ReversedType(CompositeType(UTF8Type, Int32Type))'," // reversed translates to CLUSTERING ORDER BY DESC |
| 53 | 54 | + " c3 'Int32Type'," // translates to int |
| 54 | 55 | + " PRIMARY KEY (k, c1, c2)" |
| 55 | - + ") WITH COMPACT STORAGE" | |
| 56 | + + ") WITH COMPACT STORAGE", | |
| 57 | + "CREATE TABLE test_collection(" | |
| 58 | + + " k int PRIMARY KEY," | |
| 59 | + + " c1 list<'DynamicCompositeType(s => UTF8Type, i => Int32Type)'>," | |
| 60 | + + " c2 map<'DynamicCompositeType(s => UTF8Type, i => Int32Type)', 'DynamicCompositeType(s => UTF8Type, i => Int32Type)'>" | |
| 61 | + + ")" | |
| 56 | 62 | ); |
| 57 | 63 | } |
| 58 | 64 | |
| @@ -107,6 +113,33 @@ | ||
| 107 | 113 | assertThat(r.getInt("c3")).isEqualTo(1); |
| 108 | 114 | } |
| 109 | 115 | |
| 116 | + /** | |
| 117 | + * Validates that columns using collections of custom types are properly handled by the driver. | |
| 118 | + * | |
| 119 | + * @jira_ticket JAVA-1034 | |
| 120 | + * @test_category metadata | |
| 121 | + */ | |
| 122 | + @Test(groups = "short") | |
| 123 | + public void should_serialize_and_deserialize_collections_of_custom_types() { | |
| 124 | + TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable("test_collection"); | |
| 125 | + assertThat(table.getColumn("c1")).hasType(DataType.list(CUSTOM_DYNAMIC_COMPOSITE)); | |
| 126 | + assertThat(table.getColumn("c2")).hasType(DataType.map(CUSTOM_DYNAMIC_COMPOSITE, CUSTOM_DYNAMIC_COMPOSITE)); | |
| 127 | + | |
| 128 | + session.execute("INSERT INTO test_collection(k, c1, c2) VALUES (0, [ 's@foo:i@32' ], { 's@foo:i@32': 's@bar:i@42' })"); | |
| 129 | + | |
| 130 | + Row r = session.execute("SELECT * FROM test_collection").one(); | |
| 131 | + | |
| 132 | + assertThat(r.getColumnDefinitions().getType("c1")).isEqualTo(DataType.list(CUSTOM_DYNAMIC_COMPOSITE)); | |
| 133 | + List<ByteBuffer> c1 = r.getList("c1", ByteBuffer.class); | |
| 134 | + assertThat(c1.get(0)).isEqualTo(serializeForDynamicCompositeType("foo", 32)); | |
| 135 | + | |
| 136 | + assertThat(r.getColumnDefinitions().getType("c2")).isEqualTo(DataType.map(CUSTOM_DYNAMIC_COMPOSITE, CUSTOM_DYNAMIC_COMPOSITE)); | |
| 137 | + Map<ByteBuffer, ByteBuffer> c2 = r.getMap("c2", ByteBuffer.class, ByteBuffer.class); | |
| 138 | + Map.Entry<ByteBuffer, ByteBuffer> entry = c2.entrySet().iterator().next(); | |
| 139 | + assertThat(entry.getKey()).isEqualTo(serializeForDynamicCompositeType("foo", 32)); | |
| 140 | + assertThat(entry.getValue()).isEqualTo(serializeForDynamicCompositeType("bar", 42)); | |
| 141 | + } | |
| 142 | + | |
| 110 | 143 | /** |
| 111 | 144 | * Validates that UDTs with fields using custom types are properly handled by the driver in the following ways: |
| 112 | 145 | * <p/> |