@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 = "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); }
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 = "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)"); }
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); }
.execute(SchemaBuilder.createIndex("ks_Index").onTable("ks", "CreateIndex").andColumn("b")); session() .execute(