/** * Add a new ADD column clause to this ALTER TABLE statement, to add a static column. * * @param columnName the name of the column to be added. * @return a new {@link Alter.AddColumn} instance. */ public AddColumn addStaticColumn(String columnName) { validateNotEmpty(columnName, "Added static column"); validateNotKeyWord( columnName, String.format( "The new static column name '%s' is not allowed because it is a reserved keyword", columnName)); return new AddColumn(this, columnName, true); }
@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_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>"); }
/** * Add a new ADD column clause to this ALTER TABLE statement. * * @param columnName the name of the column to be added. * @return a new {@link Alter.AddColumn} instance. */ public AddColumn addColumn(String columnName) { validateNotEmpty(columnName, "Added column"); validateNotKeyWord(columnName, String.format("The new column name '%s' is not allowed because it is a reserved keyword", columnName)); return new AddColumn(this, columnName, false); }
/** * Add a new ADD column clause to this ALTER TABLE statement. * * @param columnName the name of the column to be added. * @return a new {@link Alter.AddColumn} instance. */ public AddColumn addColumn(String columnName) { validateNotEmpty(columnName, "Added column"); validateNotKeyWord(columnName, String.format("The new column name '%s' is not allowed because it is a reserved keyword", columnName)); return new AddColumn(this, columnName, false); }
/** * Add a new ADD column clause to this ALTER TABLE statement, to add a static column. * * @param columnName the name of the column to be added. * @return a new {@link Alter.AddColumn} instance. */ public AddColumn addStaticColumn(String columnName) { validateNotEmpty(columnName, "Added static column"); validateNotKeyWord(columnName, String.format("The new static column name '%s' is not allowed because it is a reserved keyword", columnName)); return new AddColumn(this, columnName, true); }
@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") 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 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 = "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()); }
/** * Add a new ADD column clause to this ALTER TABLE statement, to add a static column. * * @param columnName the name of the column to be added. * @return a new {@link Alter.AddColumn} instance. */ public AddColumn addStaticColumn(String columnName) { validateNotEmpty(columnName, "Added static column"); validateNotKeyWord(columnName, String.format("The new static column name '%s' is not allowed because it is a reserved keyword", columnName)); return new AddColumn(this, columnName, true); }
@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_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"); }
/** * Add a new ADD column clause to this ALTER TABLE statement, to add a static column. * * @param columnName the name of the column to be added. * @return a new {@link Alter.AddColumn} instance. */ public AddColumn addStaticColumn(String columnName) { validateNotEmpty(columnName, "Added static column"); validateNotKeyWord(columnName, String.format("The new static column name '%s' is not allowed because it is a reserved keyword", columnName)); return new AddColumn(this, columnName, true); }
/** * Add a new ADD column clause to this ALTER TABLE statement. * * @param columnName the name of the column to be added. * @return a new {@link Alter.AddColumn} instance. */ public AddColumn addColumn(String columnName) { validateNotEmpty(columnName, "Added column"); validateNotKeyWord(columnName, String.format("The new column name '%s' is not allowed because it is a reserved keyword", columnName)); return new AddColumn(this, columnName, false); }
/** * Add a new ADD column clause to this ALTER TABLE statement. * * @param columnName the name of the column to be added. * @return a new {@link Alter.AddColumn} instance. */ public AddColumn addColumn(String columnName) { validateNotEmpty(columnName, "Added column"); validateNotKeyWord( columnName, String.format( "The new column name '%s' is not allowed because it is a reserved keyword", columnName)); return new AddColumn(this, columnName, false); }
@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"); } }
@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 = "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()); }