use of io.confluent.ksql.execution.ddl.commands.AlterSourceCommand in project ksql by confluentinc.
the class AlterSourceFactory method create.
public AlterSourceCommand create(final AlterSource statement) {
final DataSource dataSource = metaStore.getSource(statement.getName());
final String dataSourceType = statement.getDataSourceType().getKsqlType();
if (dataSource != null && dataSource.isSource()) {
throw new KsqlException(String.format("Cannot alter %s '%s': ALTER operations are not supported on source %s.", dataSourceType.toLowerCase(), statement.getName().text(), dataSourceType.toLowerCase() + "s"));
}
final List<Column> newColumns = statement.getAlterOptions().stream().map(alterOption -> Column.of(ColumnName.of(alterOption.getColumnName()), alterOption.getType().getSqlType(), Namespace.VALUE, 0)).collect(Collectors.toList());
return new AlterSourceCommand(statement.getName(), dataSourceType, newColumns);
}
use of io.confluent.ksql.execution.ddl.commands.AlterSourceCommand in project ksql by confluentinc.
the class AlterSourceFactoryTest method shouldCreateCommandForAlterTable.
@Test
public void shouldCreateCommandForAlterTable() {
// Given:
final AlterSource alterSource = new AlterSource(TABLE_NAME, DataSourceType.KTABLE, NEW_COLUMNS);
// When:
final AlterSourceCommand result = alterSourceFactory.create(alterSource);
// Then:
assertEquals(result.getKsqlType(), DataSourceType.KTABLE.getKsqlType());
assertEquals(result.getSourceName(), TABLE_NAME);
assertEquals(result.getNewColumns().size(), 1);
}
use of io.confluent.ksql.execution.ddl.commands.AlterSourceCommand in project ksql by confluentinc.
the class DdlCommandExecTest method shouldThrowOnAlterMissingSource.
@Test
public void shouldThrowOnAlterMissingSource() {
// Given:
alterSource = new AlterSourceCommand(STREAM_NAME, DataSourceType.KSTREAM.getKsqlType(), NEW_COLUMNS);
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> cmdExec.execute(SQL_TEXT, alterSource, false, NO_QUERY_SOURCES));
// Then:
assertThat(e.getMessage(), is("Source s1 does not exist."));
}
use of io.confluent.ksql.execution.ddl.commands.AlterSourceCommand in project ksql by confluentinc.
the class DdlCommandExecTest method shouldThrowOnAddExistingColumn.
@Test
public void shouldThrowOnAddExistingColumn() {
// Given:
givenCreateStream();
cmdExec.execute(SQL_TEXT, createStream, false, NO_QUERY_SOURCES);
alterSource = new AlterSourceCommand(STREAM_NAME, DataSourceType.KSTREAM.getKsqlType(), SCHEMA2.columns());
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> cmdExec.execute(SQL_TEXT, alterSource, false, NO_QUERY_SOURCES));
// Then:
assertThat(e.getMessage(), is("Cannot add column `F1` to schema. A column with the same name already exists."));
}
use of io.confluent.ksql.execution.ddl.commands.AlterSourceCommand in project ksql by confluentinc.
the class DdlCommandExecTest method shouldThrowOnAlterCAS.
@Test
public void shouldThrowOnAlterCAS() {
// Given:
givenCreateStream();
cmdExec.execute(SQL_TEXT, createStream, true, NO_QUERY_SOURCES);
alterSource = new AlterSourceCommand(STREAM_NAME, DataSourceType.KSTREAM.getKsqlType(), NEW_COLUMNS);
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> cmdExec.execute(SQL_TEXT, alterSource, false, NO_QUERY_SOURCES));
// Then:
assertThat(e.getMessage(), is("ALTER command is not supported for CREATE ... AS statements."));
}
Aggregations