@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The renamed column name 'add' is not allowed because it is a reserved keyword") public void should_fail_if_renamed_column_is_a_reserved_keyword() throws Exception { alterTable("test").renameColumn("add"); }
@Test(groups = "unit") public void should_drop_column() throws Exception { // When SchemaStatement statement = alterTable("test").dropColumn("name"); // Then assertThat(statement.getQueryString()).isEqualTo("\n\tALTER TABLE test DROP name"); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The dropped column name 'add' is not allowed because it is a reserved keyword") public void should_fail_if_drop_column_is_a_reserved_keyword() throws Exception { alterTable("test").dropColumn("add").getQueryString(); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The new column name 'add' is not allowed because it is a reserved keyword") public void should_fail_if_new_renamed_column_is_a_reserved_keyword() throws Exception { alterTable("test").renameColumn("col").to("add"); }
@Test(groups = "unit") public void should_rename_column() throws Exception { // When SchemaStatement statement = alterTable("test").renameColumn("name").to("description"); // Then assertThat(statement.getQueryString()) .isEqualTo("\n\tALTER TABLE test RENAME name TO description"); }
@Test(groups = "unit") public void should_alter_column_type_with_keyspace() throws Exception { // When SchemaStatement statement = alterTable("ks", "test").alterColumn("name").type(DataType.ascii()); // Then assertThat(statement.getQueryString()) .isEqualTo("\n\tALTER TABLE ks.test ALTER name TYPE ascii"); }
@Test(groups = "unit") public void should_add_static_column() throws Exception { // When SchemaStatement statement = alterTable("test").addStaticColumn("stat").type(DataType.text()); // Then assertThat(statement.getQueryString()).isEqualTo("\n\tALTER TABLE test ADD stat text static"); } }
@Test(groups = "unit") public void should_alter_column_type_to_UDT() throws Exception { // When SchemaStatement statement = alterTable("ks", "test").alterColumn("address").udtType(frozen("address")); // Then assertThat(statement.getQueryString()) .isEqualTo("\n\tALTER TABLE ks.test ALTER address TYPE frozen<address>"); }
@Test(groups = "unit") public void should_alter_column_type() throws Exception { // When SchemaStatement statement = alterTable("test").alterColumn("name").type(DataType.ascii()); // Then assertThat(statement.getQueryString()).isEqualTo("\n\tALTER TABLE test ALTER name TYPE ascii"); }
@Test(groups = "unit") public void should_add_column() throws Exception { // When SchemaStatement statement = alterTable("test").addColumn("location").type(DataType.ascii()); // Then assertThat(statement.getQueryString()).isEqualTo("\n\tALTER TABLE test ADD location ascii"); }
@Test(groups = "unit") public void should_add_column_with_UDT_type() throws Exception { // When SchemaStatement statement = alterTable("test").addColumn("location").udtType(frozen("address")); // Then assertThat(statement.getQueryString()) .isEqualTo("\n\tALTER TABLE test ADD location frozen<address>"); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The keyspace name 'add' is not allowed because it is a reserved keyword") public void should_fail_if_keyspace_name_is_a_reserved_keyword() throws Exception { alterTable("add", "test").addColumn("test").type(DataType.ascii()); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The table name 'add' is not allowed because it is a reserved keyword") public void should_fail_if_table_name_is_a_reserved_keyword() throws Exception { alterTable("add").addColumn("test").type(DataType.ascii()); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The altered column name 'add' is not allowed because it is a reserved keyword") public void should_fail_if_altered_column_is_a_reserved_keyword() throws Exception { alterTable("test").alterColumn("add").type(DataType.ascii()).getQueryString(); }
@Test( groups = "unit", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The new column name 'add' is not allowed because it is a reserved keyword") public void should_fail_if_added_column_is_a_reserved_keyword() throws Exception { alterTable("test").addColumn("add").type(DataType.ascii()).getQueryString(); }
@Test(groups = "short") public void should_add_and_drop_a_column() { // Create a table, add a column to it with an alter table statement and delete that column session() .execute( SchemaBuilder.createTable("ks", "DropColumn") .ifNotExists() .addPartitionKey("a", DataType.cint())); // Add and then drop a column session() .execute(SchemaBuilder.alterTable("ks", "DropColumn").addColumn("b").type(DataType.cint())); session().execute(SchemaBuilder.alterTable("ks", "DropColumn").dropColumn("b")); // Check that only column a exist ResultSet rows = session() .execute( "SELECT column_name, type, validator " + "FROM system.schema_columns " + "WHERE keyspace_name='ks' AND columnfamily_name='dropcolumn'"); Iterator<Row> iterator = rows.iterator(); verifyNextColumnDefinition( iterator, "a", "partition_key", "org.apache.cassandra.db.marshal.Int32Type"); assertThat(iterator.hasNext()).isFalse(); }
SchemaBuilder.alterTable("TableMetadata") .withOptions() .defaultTimeToLive(1337)
alterTable("test") .withOptions() .bloomFilterFPChance(0.01) alterTable("test").withOptions().caching(KeyCaching.NONE, rows(100));
@Test(groups = "unit") public void should_add_column() throws Exception { // When SchemaStatement statement = alterTable("test").addColumn("location").type(DataType.ascii()); // Then assertThat(statement.getQueryString()).isEqualTo("\n\tALTER TABLE test ADD location ascii"); }
@Test(groups = "unit") public void should_add_static_column() throws Exception { // When SchemaStatement statement = alterTable("test").addStaticColumn("stat").type(DataType.text()); // Then assertThat(statement.getQueryString()).isEqualTo("\n\tALTER TABLE test ADD stat text static"); } }