/** * Start building a new CREATE INDEX statement. * * @param indexName the name of the table to create. * @return an in-construction CREATE INDEX statement. */ public static CreateIndex createIndex(String indexName) { return new CreateIndex(indexName); }
/** * Specify the column to create the index on. * * @param columnName the column name. * @return the final CREATE INDEX statement. */ public SchemaStatement andColumn(String columnName) { validateNotEmpty(columnName, "Column name"); validateNotKeyWord( columnName, String.format( "The column name '%s' is not allowed because it is a reserved keyword", columnName)); CreateIndex.this.columnName = columnName; return SchemaStatement.fromQueryString(buildInternal()); }
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); }
@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))"); } }
/** * Create an index on the keys of the given map column. * * @param columnName the column name. * @return the final CREATE INDEX statement. */ public SchemaStatement andKeysOfColumn(String columnName) { validateNotEmpty(columnName, "Column name"); validateNotKeyWord( columnName, String.format( "The column name '%s' is not allowed because it is a reserved keyword", columnName)); CreateIndex.this.columnName = columnName; CreateIndex.this.keys = true; return SchemaStatement.fromQueryString(buildInternal()); } }
/** * Start building a new CREATE INDEX statement. * * @param indexName the name of the table to create. * @return an in-construction CREATE INDEX statement. */ public static CreateIndex createIndex(String indexName) { return new CreateIndex(indexName); }
@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)"); }
/** * Specify the column to create the index on. * * @param columnName the column name. * @return the final CREATE INDEX statement. */ public SchemaStatement andColumn(String columnName) { validateNotEmpty(columnName, "Column name"); validateNotKeyWord(columnName, String.format("The column name '%s' is not allowed because it is a reserved keyword", columnName)); CreateIndex.this.columnName = columnName; return SchemaStatement.fromQueryString(buildInternal()); }
/** * Start building a new CREATE INDEX statement. * * @param indexName the name of the table to create. * @return an in-construction CREATE INDEX statement. */ public static CreateIndex createIndex(String indexName) { return new CreateIndex(indexName); }
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); }
/** * Specify the column to create the index on. * * @param columnName the column name. * @return the final CREATE INDEX statement. */ public SchemaStatement andColumn(String columnName) { validateNotEmpty(columnName, "Column name"); validateNotKeyWord(columnName, String.format("The column name '%s' is not allowed because it is a reserved keyword", columnName)); CreateIndex.this.columnName = columnName; return SchemaStatement.fromQueryString(buildInternal()); }
/** * Start building a new CREATE INDEX statement. * * @param indexName the name of the table to create. * @return an in-construction CREATE INDEX statement. */ public static CreateIndex createIndex(String indexName) { return new CreateIndex(indexName); }
@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)"); }
/** * Specify the column to create the index on. * * @param columnName the column name. * @return the final CREATE INDEX statement. */ public SchemaStatement andColumn(String columnName) { validateNotEmpty(columnName, "Column name"); validateNotKeyWord(columnName, String.format("The column name '%s' is not allowed because it is a reserved keyword", columnName)); CreateIndex.this.columnName = columnName; return SchemaStatement.fromQueryString(buildInternal()); }
@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))"); } }
/** * Create an index on the keys of the given map column. * * @param columnName the column name. * @return the final CREATE INDEX statement. */ public SchemaStatement andKeysOfColumn(String columnName) { validateNotEmpty(columnName, "Column name"); validateNotKeyWord(columnName, String.format("The column name '%s' is not allowed because it is a reserved keyword", columnName)); CreateIndex.this.columnName = columnName; CreateIndex.this.keys = true; return SchemaStatement.fromQueryString(buildInternal()); } }