@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 = "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(); }
@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(); }