.addClusteringColumn("d", DataType.cint()) .withOptions() .compactStorage());
.addColumn("name", DataType.text()) .withOptions() .clusteringOrder("col1", Direction.ASC) .clusteringOrder("col2", Direction.DESC) .compactStorage() .bloomFilterFPChance(0.01) .caching(Caching.ROWS_ONLY) .comment("This is a comment") .compactionOptions(leveledStrategy().ssTableSizeInMB(160)) .compressionOptions(lz4()) .dcLocalReadRepairChance(0.21) .defaultTimeToLive(100) .gcGraceSeconds(9999) .minIndexInterval(64) .maxIndexInterval(512) .memtableFlushPeriodInMillis(12) .populateIOCacheOnFlush(true) .readRepairChance(0.05) .replicateOnWrite(true) .speculativeRetry(always()) .cdc(true);
.addColumn("a", ks.getUserType("atype").copy(true)) .withOptions() .compactionOptions(SchemaBuilder.leveledStrategy().ssTableSizeInMB(95))); } else { .addColumn("a", DataType.cint()) .withOptions() .compactionOptions(SchemaBuilder.leveledStrategy().ssTableSizeInMB(95)));
.addColumn("name", DataType.text()) .withOptions() .clusteringOrder("col1", Direction.ASC) .clusteringOrder("col2", Direction.DESC) .compactStorage() .bloomFilterFPChance(0.01) .caching(Caching.ROWS_ONLY) .comment("This is a comment") .compactionOptions(leveledStrategy().ssTableSizeInMB(160)) .compressionOptions(lz4()) .dcLocalReadRepairChance(0.21) .defaultTimeToLive(100) .gcGraceSeconds(9999) .minIndexInterval(64) .maxIndexInterval(512) .memtableFlushPeriodInMillis(12) .populateIOCacheOnFlush(true) .readRepairChance(0.05) .replicateOnWrite(true) .speculativeRetry(always()) .cdc(true);
.withOptions() .clusteringOrder(PLACEMENT_COLUMN, SchemaBuilder.Direction.ASC) .clusteringOrder(RANGE_TOKEN_COLUMN, SchemaBuilder.Direction.ASC) .clusteringOrder(IS_START_TOKEN_COLUMN, SchemaBuilder.Direction.ASC) .compactStorage() .defaultTimeToLive(TTL));
.withOptions() .clusteringOrder(PLACEMENT_COLUMN, SchemaBuilder.Direction.ASC) .clusteringOrder(RANGE_TOKEN_COLUMN, SchemaBuilder.Direction.ASC) .clusteringOrder(IS_START_TOKEN_COLUMN, SchemaBuilder.Direction.ASC) .compactStorage() .defaultTimeToLive(TTL));
.addColumn(VALUE, DataType.blob()) .withOptions() .bloomFilterFPChance(falsePositive(tableMetadata.hasNegativeLookups(), appendHeavyReadLight)) .caching(SchemaBuilder.Caching.KEYS_ONLY) .compactionOptions(getCompaction(appendHeavyReadLight)) .compactStorage() .compressionOptions(getCompression(tableMetadata.getExplicitCompressionBlockSizeKB())) .dcLocalReadRepairChance(0.1) .gcGraceSeconds(config.gcGraceSeconds()) .minIndexInterval(128) .maxIndexInterval(2048) .populateIOCacheOnFlush(tableMetadata.getCachePriority() == CachePriority.HOTTEST) .speculativeRetry(SchemaBuilder.noSpeculativeRetry()) .clusteringOrder(COLUMN, SchemaBuilder.Direction.ASC) .clusteringOrder(TIMESTAMP, SchemaBuilder.Direction.ASC) .buildInternal();
@Test(groups = "unit") public void should_create_table_with_clustering_order() throws Exception { // When SchemaStatement statement = createTable("test") .addPartitionKey("id", DataType.bigint()) .addClusteringColumn("col1", DataType.uuid()) .addClusteringColumn("col2", DataType.uuid()) .addColumn("name", DataType.text()) .withOptions() .clusteringOrder("col1", Direction.ASC) .clusteringOrder("col2", Direction.DESC); // Then assertThat(statement.getQueryString()) .isEqualTo( "\n\tCREATE TABLE test(\n\t\t" + "id bigint,\n\t\t" + "col1 uuid,\n\t\t" + "col2 uuid,\n\t\t" + "name text,\n\t\t" + "PRIMARY KEY(id, col1, col2))\n\t" + "WITH CLUSTERING ORDER BY(col1 ASC, col2 DESC)"); }
@Test(groups = "unit") public void should_create_table_with_compact_storage() throws Exception { // When SchemaStatement statement = createTable("test") .addPartitionKey("id", DataType.bigint()) .addClusteringColumn("col1", DataType.uuid()) .addClusteringColumn("col2", DataType.uuid()) .addColumn("name", DataType.text()) .withOptions() .compactStorage(); // Then assertThat(statement.getQueryString()) .isEqualTo( "\n\tCREATE TABLE test(\n\t\t" + "id bigint,\n\t\t" + "col1 uuid,\n\t\t" + "col2 uuid,\n\t\t" + "name text,\n\t\t" + "PRIMARY KEY(id, col1, col2))\n\t" + "WITH COMPACT STORAGE"); }
private static void initializeTable(final Session session, final String keyspaceName, final String tableName, final Configuration configuration, final boolean allowCompactStorage) { final Options createTable = createTable(keyspaceName, tableName) .ifNotExists() .addPartitionKey(KEY_COLUMN_NAME, DataType.blob()) .addClusteringColumn(COLUMN_COLUMN_NAME, DataType.blob()) .addColumn(VALUE_COLUMN_NAME, DataType.blob()) .withOptions() .compressionOptions(compressionOptions(configuration)) .compactionOptions(compactionOptions(configuration)); // COMPACT STORAGE is allowed on Cassandra 2 or earlier // when COMPACT STORAGE is allowed, the default is to enable it final boolean useCompactStorage = (allowCompactStorage && configuration.has(CF_COMPACT_STORAGE)) ? configuration.get(CF_COMPACT_STORAGE) : allowCompactStorage; session.execute(useCompactStorage ? createTable.compactStorage() : createTable); }
@Test( groups = "unit", expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "Cannot create table 'test' with compact storage and static columns '\\[stat\\]'") public void should_fail_creating_table_with_static_columns_and_compact_storage() throws Exception { createTable("test") .addPartitionKey("pk", DataType.bigint()) .addClusteringColumn("cluster", DataType.uuid()) .addStaticColumn("stat", DataType.text()) .withOptions() .compactStorage() .getQueryString(); } }
@Test(groups = "unit", expectedExceptions = IllegalStateException.class) public void should_fail_when_both_caching_versions() throws Exception { createTable("test") .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .withOptions() .caching(Caching.KEYS_ONLY) .caching(KeyCaching.ALL, allRows()) .getQueryString(); }
/** * Add options for this CREATE TABLE statement. * * @return the options of this CREATE TABLE statement. */ public Options withOptions() { return new Options(this); }
/** * Add options for this CREATE TABLE statement. * * @return the options of this CREATE TABLE statement. */ public Options withOptions() { return new Options(this); }
@Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) public void should_fail_when_clustering_order_column_does_not_match_declared_clustering_keys() throws Exception { createTable("test") .addPartitionKey("id", DataType.bigint()) .addClusteringColumn("col1", DataType.uuid()) .addClusteringColumn("col2", DataType.uuid()) .addColumn("name", DataType.text()) .withOptions() .clusteringOrder("col3", Direction.ASC); }
/** * Add options for this CREATE TABLE statement. * * @return the options of this CREATE TABLE statement. */ public Options withOptions() { return new Options(this); }
@Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) public void should_fail_when_blank_clustering_order_column_provided() throws Exception { createTable("test") .addPartitionKey("id", DataType.bigint()) .addClusteringColumn("col1", DataType.uuid()) .addClusteringColumn("col2", DataType.uuid()) .addColumn("name", DataType.text()) .withOptions() .clusteringOrder("", Direction.DESC); }
@Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) public void should_fail_when_negative_rows_per_partition() throws Exception { createTable("test") .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .withOptions() .caching(KeyCaching.ALL, rows(-3)); }
.addColumn("a", ks.getUserType("atype").copy(true)) .withOptions() .compactionOptions(SchemaBuilder.leveledStrategy().ssTableSizeInMB(95))); } else { .addColumn("a", DataType.cint()) .withOptions() .compactionOptions(SchemaBuilder.leveledStrategy().ssTableSizeInMB(95)));