@Test(groups = "unit") public void should_create_index() throws Exception { // Given //When SchemaStatement statement = createIndex("myIndex").ifNotExists().onTable("ks", "test").andColumn("col"); // Then assertThat(statement.getQueryString()) .isEqualTo("\n\tCREATE INDEX IF NOT EXISTS myIndex ON ks.test(col)"); }
@Test(groups = "unit") public void should_create_index_on_keys_of_map_column() throws Exception { // Given //When SchemaStatement statement = createIndex("myIndex").ifNotExists().onTable("ks", "test").andKeysOfColumn("col"); // Then assertThat(statement.getQueryString()) .isEqualTo("\n\tCREATE INDEX IF NOT EXISTS myIndex ON ks.test(KEYS(col))"); } }
protected void createIndex(CassandraSessionPool.Session session, String indexLabel, HugeKeys column) { String indexName = joinTableName(this.table(), indexLabel); SchemaStatement index = SchemaBuilder.createIndex(indexName) .ifNotExists() .onTable(this.table()) .andColumn(formatKey(column)); LOG.debug("Create index: {}", index); session.execute(index); }
@Test(groups = "short") public void should_drop_an_index() { // Create a table session() .execute( SchemaBuilder.createTable("ks", "DropIndex") .addPartitionKey("a", DataType.cint()) .addClusteringColumn("b", DataType.cint())); // Create an index // Note: we have to pick a lower-case name because Cassandra uses the CamelCase index name at // creation // but a lowercase index name at deletion // See : https://issues.apache.org/jira/browse/CASSANDRA-8365 session() .execute(SchemaBuilder.createIndex("ks_index").onTable("ks", "DropIndex").andColumn("b")); // Verify that the PK index and the secondary indexes both exist assertThat(numberOfIndexedColumns()).isEqualTo(1); // Delete the index session().execute(SchemaBuilder.dropIndex("ks", "ks_index")); // Verify that only the PK index exists assertThat(numberOfIndexedColumns()).isEqualTo(0); }
.execute(SchemaBuilder.createIndex("ks_Index").onTable("ks", "CreateIndex").andColumn("b")); session() .execute( SchemaBuilder.createIndex("ks_IndexOnMap") .onTable("ks", "CreateIndex") .andKeysOfColumn("c"));
SchemaBuilder.createIndex("cyclist_by_country") .onTable("cyclist_mv") .andColumn("country")); SchemaBuilder.createIndex("ryear").onTable("rank_by_year_and_name").andColumn("race_year")); SchemaBuilder.createIndex("rrank").onTable("rank_by_year_and_name").andColumn("rank"));
@Test(groups = "unit") public void should_create_index() throws Exception { // Given //When SchemaStatement statement = createIndex("myIndex").ifNotExists().onTable("ks", "test").andColumn("col"); // Then assertThat(statement.getQueryString()) .isEqualTo("\n\tCREATE INDEX IF NOT EXISTS myIndex ON ks.test(col)"); }
@Test(groups = "unit") public void should_create_index_on_keys_of_map_column() throws Exception { // Given //When SchemaStatement statement = createIndex("myIndex").ifNotExists().onTable("ks", "test").andKeysOfColumn("col"); // Then assertThat(statement.getQueryString()) .isEqualTo("\n\tCREATE INDEX IF NOT EXISTS myIndex ON ks.test(KEYS(col))"); } }
protected void createIndex(CassandraSessionPool.Session session, String indexLabel, HugeKeys column) { String indexName = joinTableName(this.table(), indexLabel); SchemaStatement index = SchemaBuilder.createIndex(indexName) .ifNotExists() .onTable(this.table()) .andColumn(formatKey(column)); LOG.debug("Create index: {}", index); session.execute(index); }
SchemaBuilder.createIndex("cyclist_by_country") .onTable("cyclist_mv") .andColumn("country")); SchemaBuilder.createIndex("ryear").onTable("rank_by_year_and_name").andColumn("race_year")); SchemaBuilder.createIndex("rrank").onTable("rank_by_year_and_name").andColumn("rank"));