/** * Specify the keyspace and table to create the index on. * * @param keyspaceName the keyspace name. * @param tableName the table name. * @return a {@link CreateIndexOn} that will allow the specification of the column. */ public CreateIndexOn onTable(String keyspaceName, String tableName) { validateNotEmpty(keyspaceName, "Keyspace name"); validateNotEmpty(tableName, "Table name"); validateNotKeyWord( keyspaceName, String.format( "The keyspace name '%s' is not allowed because it is a reserved keyword", keyspaceName)); validateNotKeyWord( tableName, String.format( "The table name '%s' is not allowed because it is a reserved keyword", tableName)); this.keyspaceName = Optional.fromNullable(keyspaceName); this.tableName = tableName; return new CreateIndexOn(); }
.execute(SchemaBuilder.createIndex("ks_Index").onTable("ks", "CreateIndex").andColumn("b")); session() .execute( SchemaBuilder.createIndex("ks_IndexOnMap") .onTable("ks", "CreateIndex") .andKeysOfColumn("c"));
/** * Specify the keyspace and table to create the index on. * * @param keyspaceName the keyspace name. * @param tableName the table name. * @return a {@link CreateIndexOn} that will allow the specification of the column. */ public CreateIndexOn onTable(String keyspaceName, String tableName) { validateNotEmpty(keyspaceName, "Keyspace name"); validateNotEmpty(tableName, "Table name"); validateNotKeyWord(keyspaceName, String.format("The keyspace name '%s' is not allowed because it is a reserved keyword", keyspaceName)); validateNotKeyWord(tableName, String.format("The table name '%s' is not allowed because it is a reserved keyword", tableName)); this.keyspaceName = Optional.fromNullable(keyspaceName); this.tableName = tableName; return new CreateIndexOn(); }
/** * Specify the keyspace and table to create the index on. * * @param keyspaceName the keyspace name. * @param tableName the table name. * @return a {@link CreateIndexOn} that will allow the specification of the column. */ public CreateIndexOn onTable(String keyspaceName, String tableName) { validateNotEmpty(keyspaceName, "Keyspace name"); validateNotEmpty(tableName, "Table name"); validateNotKeyWord(keyspaceName, String.format("The keyspace name '%s' is not allowed because it is a reserved keyword", keyspaceName)); validateNotKeyWord(tableName, String.format("The table name '%s' is not allowed because it is a reserved keyword", tableName)); this.keyspaceName = Optional.fromNullable(keyspaceName); this.tableName = tableName; return new CreateIndexOn(); }
/** * Specify the keyspace and table to create the index on. * * @param keyspaceName the keyspace name. * @param tableName the table name. * @return a {@link CreateIndexOn} that will allow the specification of the column. */ public CreateIndexOn onTable(String keyspaceName, String tableName) { validateNotEmpty(keyspaceName, "Keyspace name"); validateNotEmpty(tableName, "Table name"); validateNotKeyWord(keyspaceName, String.format("The keyspace name '%s' is not allowed because it is a reserved keyword", keyspaceName)); validateNotKeyWord(tableName, String.format("The table name '%s' is not allowed because it is a reserved keyword", tableName)); this.keyspaceName = Optional.fromNullable(keyspaceName); this.tableName = tableName; return new CreateIndexOn(); }
/** * Specify the table to create the index on. * * @param tableName the table name. * @return a {@link CreateIndexOn} that will allow the specification of the column. */ public CreateIndexOn onTable(String tableName) { validateNotEmpty(tableName, "Table name"); validateNotKeyWord(tableName, String.format("The table name '%s' is not allowed because it is a reserved keyword", tableName)); this.tableName = tableName; return new CreateIndexOn(); }
@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))"); } }
/** * Specify the table to create the index on. * * @param tableName the table name. * @return a {@link CreateIndexOn} that will allow the specification of the column. */ public CreateIndexOn onTable(String tableName) { validateNotEmpty(tableName, "Table name"); validateNotKeyWord(tableName, String.format("The table name '%s' is not allowed because it is a reserved keyword", tableName)); this.tableName = tableName; return new CreateIndexOn(); }
/** * Specify the table to create the index on. * * @param tableName the table name. * @return a {@link CreateIndexOn} that will allow the specification of the column. */ public CreateIndexOn onTable(String tableName) { validateNotEmpty(tableName, "Table name"); validateNotKeyWord(tableName, String.format("The table name '%s' is not allowed because it is a reserved keyword", tableName)); this.tableName = tableName; return new CreateIndexOn(); }
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)"); }
@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); }
/** * Specify the table to create the index on. * * @param tableName the table name. * @return a {@link CreateIndexOn} that will allow the specification of the column. */ public CreateIndexOn onTable(String tableName) { validateNotEmpty(tableName, "Table name"); validateNotKeyWord( tableName, String.format( "The table name '%s' is not allowed because it is a reserved keyword", tableName)); this.tableName = tableName; return new CreateIndexOn(); }
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_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))"); } }
@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)"); }