kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 99740bf2fccd98e0b859e36686877eecaddde1b336e39a338b31fe2c47d087fc |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2015-09-11 13:14 +02:00 |
| Committer | Alexandre Dutra <alexandre.dutra@datastax.com> · 2015-09-11 13:14 +02:00 |
| Parents | a3d96ee58d97 |
5 files changed
modified driver-core/src/main/java/com/datastax/driver/core/ColumnMetadata.java +35 −19
| @@ -16,11 +16,6 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | import java.util.*; |
| 19 | -import java.util.Map.Entry; | |
| 20 | - | |
| 21 | -import com.google.common.base.Function; | |
| 22 | -import com.google.common.collect.ImmutableMap; | |
| 23 | -import com.google.common.collect.Maps; | |
| 24 | 19 | |
| 25 | 20 | /** |
| 26 | 21 | * Describes a Column. |
| @@ -28,9 +23,15 @@ | ||
| 28 | 23 | public class ColumnMetadata { |
| 29 | 24 | |
| 30 | 25 | static final String COLUMN_NAME = "column_name"; |
| 31 | - static final String VALIDATOR = "validator"; | |
| 32 | - static final String COMPONENT_INDEX = "component_index"; | |
| 33 | - static final String KIND = "type"; | |
| 26 | + | |
| 27 | + static final String VALIDATOR = "validator"; // v2 only | |
| 28 | + static final String TYPE = "type"; // replaces validator, v3 onwards | |
| 29 | + | |
| 30 | + static final String COMPONENT_INDEX = "component_index"; // v2 only | |
| 31 | + static final String POSITION = "position"; // replaces component_index, v3 onwards | |
| 32 | + | |
| 33 | + static final String KIND_V2 = "type"; // v2 only | |
| 34 | + static final String KIND_V3 = "kind"; // replaces type, v3 onwards | |
| 34 | 35 | |
| 35 | 36 | static final String INDEX_TYPE = "index_type"; |
| 36 | 37 | static final String INDEX_OPTIONS = "index_options"; |
| @@ -163,35 +164,50 @@ | ||
| 163 | 164 | |
| 164 | 165 | public final String name; |
| 165 | 166 | public Kind kind; |
| 166 | - public final int componentIndex; | |
| 167 | + public final int position; | |
| 167 | 168 | public final DataType dataType; |
| 168 | 169 | public final boolean isReversed; |
| 169 | 170 | |
| 170 | 171 | public final Map<String, String> indexColumns = new HashMap<String, String>(); |
| 171 | 172 | |
| 172 | - Raw(String name, Kind kind, int componentIndex, DataType dataType, boolean isReversed) { | |
| 173 | + Raw(String name, Kind kind, int position, DataType dataType, boolean isReversed) { | |
| 173 | 174 | this.name = name; |
| 174 | 175 | this.kind = kind; |
| 175 | - this.componentIndex = componentIndex; | |
| 176 | + this.position = position; | |
| 176 | 177 | this.dataType = dataType; |
| 177 | 178 | this.isReversed = isReversed; |
| 178 | 179 | } |
| 179 | 180 | |
| 180 | 181 | static Raw fromRow(Row row, VersionNumber version, ProtocolVersion protocolVersion, CodecRegistry codecRegistry) { |
| 181 | 182 | String name = row.getString(COLUMN_NAME); |
| 183 | + | |
| 182 | 184 | Kind kind; |
| 183 | - if(version.getMajor() < 2 || row.isNull(KIND)) { | |
| 185 | + if(version.getMajor() < 2) { | |
| 184 | 186 | kind = Kind.REGULAR; |
| 185 | 187 | } else if (version.getMajor() < 3) { |
| 186 | - kind = Kind.fromStringV2(row.getString(KIND)); | |
| 188 | + kind = row.isNull(KIND_V2) ? Kind.REGULAR : Kind.fromStringV2(row.getString(KIND_V2)); | |
| 189 | + } else { | |
| 190 | + kind = row.isNull(KIND_V3) ? Kind.REGULAR : Kind.fromStringV3(row.getString(KIND_V3)); | |
| 191 | + } | |
| 192 | + | |
| 193 | + int position; | |
| 194 | + if(version.getMajor() >= 3) { | |
| 195 | + position = row.getInt(POSITION); // cannot be null, -1 is used as a special value instead of null to avoid tombstones | |
| 196 | + if(position == -1) position = 0; | |
| 197 | + } else { | |
| 198 | + position = row.isNull(COMPONENT_INDEX) ? 0 : row.getInt(COMPONENT_INDEX); | |
| 199 | + } | |
| 200 | + | |
| 201 | + String dataTypeStr; | |
| 202 | + if(version.getMajor() >= 3) { | |
| 203 | + dataTypeStr = row.getString(TYPE); | |
| 187 | 204 | } else { |
| 188 | - kind = Kind.fromStringV3(row.getString(KIND)); | |
| 205 | + dataTypeStr = row.getString(VALIDATOR); | |
| 189 | 206 | } |
| 190 | - int componentIndex = row.isNull(COMPONENT_INDEX) ? 0 : row.getInt(COMPONENT_INDEX); | |
| 191 | - String validatorStr = row.getString(VALIDATOR); | |
| 192 | - boolean reversed = CassandraTypeParser.isReversed(validatorStr); | |
| 193 | - DataType dataType = CassandraTypeParser.parseOne(validatorStr, protocolVersion, codecRegistry); | |
| 194 | - Raw c = new Raw(name, kind, componentIndex, dataType, reversed); | |
| 207 | + DataType dataType = CassandraTypeParser.parseOne(dataTypeStr, protocolVersion, codecRegistry); | |
| 208 | + boolean reversed = CassandraTypeParser.isReversed(dataTypeStr); | |
| 209 | + | |
| 210 | + Raw c = new Raw(name, kind, position, dataType, reversed); | |
| 195 | 211 | |
| 196 | 212 | // secondary indexes (C* < 3.0.0) |
| 197 | 213 | // from C* 3.0 onwards 2i are defined in a separate table |
modified driver-core/src/main/java/com/datastax/driver/core/TableMetadata.java +6 −6
| @@ -225,11 +225,11 @@ | ||
| 225 | 225 | ColumnMetadata col = ColumnMetadata.fromRaw(tm, rawCol); |
| 226 | 226 | switch (rawCol.kind) { |
| 227 | 227 | case PARTITION_KEY: |
| 228 | - partitionKey.set(rawCol.componentIndex, col); | |
| 228 | + partitionKey.set(rawCol.position, col); | |
| 229 | 229 | break; |
| 230 | 230 | case CLUSTERING_COLUMN: |
| 231 | - clusteringColumns.set(rawCol.componentIndex, col); | |
| 232 | - clusteringOrder.set(rawCol.componentIndex, rawCol.isReversed ? Order.DESC : Order.ASC); | |
| 231 | + clusteringColumns.set(rawCol.position, col); | |
| 232 | + clusteringOrder.set(rawCol.position, rawCol.isReversed ? Order.DESC : Order.ASC); | |
| 233 | 233 | break; |
| 234 | 234 | default: |
| 235 | 235 | otherColumns.add(col); |
| @@ -347,7 +347,7 @@ | ||
| 347 | 347 | int maxId = -1; |
| 348 | 348 | for (ColumnMetadata.Raw col : cols) |
| 349 | 349 | if (col.kind == ColumnMetadata.Raw.Kind.PARTITION_KEY) |
| 350 | - maxId = Math.max(maxId, col.componentIndex); | |
| 350 | + maxId = Math.max(maxId, col.position); | |
| 351 | 351 | return maxId + 1; |
| 352 | 352 | } |
| 353 | 353 | |
| @@ -355,14 +355,14 @@ | ||
| 355 | 355 | Collection<ColumnMetadata.Raw> cols, |
| 356 | 356 | List<String> columnAliases, |
| 357 | 357 | VersionNumber cassandraVersion) { |
| 358 | - // In 2.0 onwards, this is relatively easy, we just find the biggest 'componentIndex' amongst the clustering columns. | |
| 358 | + // In 2.0 onwards, this is relatively easy, we just find the biggest 'position' amongst the clustering columns. | |
| 359 | 359 | // For 1.2 however, this is slightly more subtle: we need to infer it based on whether the comparator is composite or not, and whether we have |
| 360 | 360 | // regular columns or not. |
| 361 | 361 | if (cassandraVersion.getMajor() >= 2) { |
| 362 | 362 | int maxId = -1; |
| 363 | 363 | for (ColumnMetadata.Raw col : cols) |
| 364 | 364 | if (col.kind == ColumnMetadata.Raw.Kind.CLUSTERING_COLUMN) |
| 365 | - maxId = Math.max(maxId, col.componentIndex); | |
| 365 | + maxId = Math.max(maxId, col.position); | |
| 366 | 366 | return maxId + 1; |
| 367 | 367 | } else { |
| 368 | 368 | int size = comparator.types.size(); |
modified driver-core/src/test/java/com/datastax/driver/core/IndexMetadataTest.java +1 −1
| @@ -41,7 +41,7 @@ | ||
| 41 | 41 | private static final ColumnDefinitions defs = new ColumnDefinitions(new ColumnDefinitions.Definition[]{ |
| 42 | 42 | definition(COLUMN_NAME, text()), |
| 43 | 43 | definition(COMPONENT_INDEX, cint()), |
| 44 | - definition(KIND, text()), | |
| 44 | + definition(KIND_V2, text()), | |
| 45 | 45 | definition(INDEX_NAME, text()), |
| 46 | 46 | definition(INDEX_TYPE, text()), |
| 47 | 47 | definition(VALIDATOR, text()), |
modified driver-core/src/test/java/com/datastax/driver/core/TableMetadataTest.java +49 −24
| @@ -174,32 +174,57 @@ | ||
| 174 | 174 | @Test(groups = "short") |
| 175 | 175 | public void should_parse_table_options() { |
| 176 | 176 | VersionNumber version = TestUtils.findHost(cluster, 1).getCassandraVersion(); |
| 177 | + | |
| 178 | + // given | |
| 179 | + String cql; | |
| 180 | + | |
| 181 | + // Cassandra 3.0 + | |
| 177 | 182 | if (version.getMajor() > 2) { |
| 178 | - // TODO adapt test for C* 3.0 | |
| 179 | - throw new SkipException("Needs adjustments to work with Cassandra 3.0"); | |
| 183 | + cql = String.format("CREATE TABLE %s.with_options (\n" | |
| 184 | + + " k text,\n" | |
| 185 | + + " c1 int,\n" | |
| 186 | + + " c2 int,\n" | |
| 187 | + + " i int,\n" | |
| 188 | + + " PRIMARY KEY (k, c1, c2)\n" | |
| 189 | + + ") WITH CLUSTERING ORDER BY (c1 DESC, c2 ASC)\n" | |
| 190 | + + " AND read_repair_chance = 0.5\n" | |
| 191 | + + " AND dclocal_read_repair_chance = 0.6\n" | |
| 192 | + + " AND speculative_retry = '99.9PERCENTILE'\n" | |
| 193 | + // replicate_on_write not supported anymore in 3.0 | |
| 194 | + + " AND gc_grace_seconds = 42\n" | |
| 195 | + + " AND bloom_filter_fp_chance = 0.01\n" | |
| 196 | + // older caching formats not supported anymore in 3.0 | |
| 197 | + + " AND caching = { 'keys' : 'ALL', 'rows_per_partition' : 10 }\n" | |
| 198 | + + " AND comment = 'My awesome table'\n" | |
| 199 | + + " AND compaction = { 'class' : 'org.apache.cassandra.db.compaction.LeveledCompactionStrategy', 'sstable_size_in_mb' : 15 }\n" | |
| 200 | + + " AND compression = { 'sstable_compression' : 'org.apache.cassandra.io.compress.SnappyCompressor', 'chunk_length_kb' : 128 };", | |
| 201 | + keyspace); | |
| 202 | + | |
| 203 | + // older versions | |
| 204 | + } else { | |
| 205 | + cql = String.format("CREATE TABLE %s.with_options (\n" | |
| 206 | + + " k text,\n" | |
| 207 | + + " c1 int,\n" | |
| 208 | + + " c2 int,\n" | |
| 209 | + + " i int,\n" | |
| 210 | + + " PRIMARY KEY (k, c1, c2)\n" | |
| 211 | + + ") WITH CLUSTERING ORDER BY (c1 DESC, c2 ASC)\n" | |
| 212 | + + " AND read_repair_chance = 0.5\n" | |
| 213 | + + " AND dclocal_read_repair_chance = 0.6\n" | |
| 214 | + + " AND replicate_on_write = true\n" | |
| 215 | + + " AND gc_grace_seconds = 42\n" | |
| 216 | + + " AND bloom_filter_fp_chance = 0.01\n" | |
| 217 | + + " AND caching = 'ALL'\n" | |
| 218 | + + " AND comment = 'My awesome table'\n" | |
| 219 | + + " AND compaction = { 'class' : 'org.apache.cassandra.db.compaction.LeveledCompactionStrategy', 'sstable_size_in_mb' : 15 }\n" | |
| 220 | + + " AND compression = { 'sstable_compression' : 'org.apache.cassandra.io.compress.SnappyCompressor', 'chunk_length_kb' : 128 };", | |
| 221 | + keyspace); | |
| 180 | 222 | } |
| 181 | 223 | |
| 182 | - // given | |
| 183 | - String cql = String.format("CREATE TABLE %s.with_options (\n" | |
| 184 | - + " k text,\n" | |
| 185 | - + " c1 int,\n" | |
| 186 | - + " c2 int,\n" | |
| 187 | - + " i int,\n" | |
| 188 | - + " PRIMARY KEY (k, c1, c2)\n" | |
| 189 | - + ") WITH CLUSTERING ORDER BY (c1 DESC, c2 ASC)\n" | |
| 190 | - + " AND read_repair_chance = 0.5\n" | |
| 191 | - + " AND dclocal_read_repair_chance = 0.6\n" | |
| 192 | - + " AND replicate_on_write = true\n" | |
| 193 | - + " AND gc_grace_seconds = 42\n" | |
| 194 | - + " AND bloom_filter_fp_chance = 0.01\n" | |
| 195 | - + " AND caching = 'ALL'\n" | |
| 196 | - + " AND comment = 'My awesome table'\n" | |
| 197 | - + " AND compaction = { 'class' : 'org.apache.cassandra.db.compaction.LeveledCompactionStrategy', 'sstable_size_in_mb' : 15 }\n" | |
| 198 | - + " AND compression = { 'sstable_compression' : 'org.apache.cassandra.io.compress.SnappyCompressor', 'chunk_length_kb' : 128 };", | |
| 199 | - keyspace); | |
| 200 | 224 | // when |
| 201 | 225 | session.execute(cql); |
| 202 | 226 | TableMetadata table = cluster.getMetadata().getKeyspace(keyspace).getTable("with_options"); |
| 227 | + | |
| 203 | 228 | // then |
| 204 | 229 | assertThat(table).isNotNull().hasName("with_options").hasNumberOfColumns(4).isNotCompactStorage(); |
| 205 | 230 | assertThat(table.getColumns().get(0)).isNotNull().hasName("k").isPartitionKey().hasType(text()); |
| @@ -217,13 +242,13 @@ | ||
| 217 | 242 | assertThat(table.getOptions().getBloomFilterFalsePositiveChance()).isEqualTo(0.01); |
| 218 | 243 | assertThat(table.getOptions().getComment()).isEqualTo("My awesome table"); |
| 219 | 244 | assertThat(table.getOptions().getCaching()).contains(entry("keys", "ALL" )); |
| 220 | - assertThat(table.getOptions().getCaching()).contains(entry("rows_per_partition", "ALL")); | |
| 245 | + assertThat(table.getOptions().getCaching()).contains(entry("rows_per_partition", "10")); | |
| 221 | 246 | assertThat(table.getOptions().getCompaction()).contains(entry("class", "org.apache.cassandra.db.compaction.LeveledCompactionStrategy")); |
| 222 | 247 | assertThat(table.getOptions().getCompaction()).contains(entry("sstable_size_in_mb", "15")); |
| 223 | 248 | assertThat(table.getOptions().getCompression()).contains(entry("class", "org.apache.cassandra.io.compress.SnappyCompressor")); // sstable_compression becomes class |
| 224 | 249 | assertThat(table.getOptions().getCompression()).contains(entry("chunk_length_in_kb", "128")); // note the "in" prefix |
| 225 | 250 | assertThat(table.getOptions().getDefaultTimeToLive()).isEqualTo(0); |
| 226 | - assertThat(table.getOptions().getSpeculativeRetry()).isEqualTo("99.0PERCENTILE"); | |
| 251 | + assertThat(table.getOptions().getSpeculativeRetry()).isEqualTo("99.9PERCENTILE"); | |
| 227 | 252 | assertThat(table.getOptions().getIndexInterval()).isNull(); |
| 228 | 253 | assertThat(table.getOptions().getMinIndexInterval()).isEqualTo(128); |
| 229 | 254 | assertThat(table.getOptions().getMaxIndexInterval()).isEqualTo(2048); |
| @@ -235,13 +260,13 @@ | ||
| 235 | 260 | .contains("bloom_filter_fp_chance = 0.01") |
| 236 | 261 | .contains("comment = 'My awesome table'") |
| 237 | 262 | .contains("'keys' : 'ALL'") |
| 238 | - .contains("'rows_per_partition' : 'ALL'") | |
| 263 | + .contains("'rows_per_partition' : 10") | |
| 239 | 264 | .contains("'class' : 'org.apache.cassandra.db.compaction.LeveledCompactionStrategy'") |
| 240 | 265 | .contains("'sstable_size_in_mb' : 15") |
| 241 | 266 | .contains("'class' : 'org.apache.cassandra.io.compress.SnappyCompressor'") // sstable_compression becomes class |
| 242 | 267 | .contains("'chunk_length_in_kb' : 128") // note the "in" prefix |
| 243 | 268 | .contains("default_time_to_live = 0") |
| 244 | - .contains("speculative_retry = '99.0PERCENTILE'") | |
| 269 | + .contains("speculative_retry = '99.9PERCENTILE'") | |
| 245 | 270 | .contains("min_index_interval = 128") |
| 246 | 271 | .contains("max_index_interval = 2048") |
| 247 | 272 | .doesNotContain(" index_interval") |
modified pom.xml +1 −1
| @@ -43,7 +43,7 @@ | ||
| 43 | 43 | |
| 44 | 44 | <properties> |
| 45 | 45 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| 46 | - <cassandra.version>3.0.0-beta1</cassandra.version> | |
| 46 | + <cassandra.version>3.0.0-rc1</cassandra.version> | |
| 47 | 47 | <java.version>1.6</java.version> |
| 48 | 48 | <log4j.version>1.2.17</log4j.version> |
| 49 | 49 | <slf4j-log4j12.version>1.7.6</slf4j-log4j12.version> |