use of io.confluent.ksql.parser.tree.AlterSource 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.parser.tree.AlterSource in project ksql by confluentinc.
the class AlterSourceFactoryTest method shouldThrowInAlterOnSourceStream.
@Test
public void shouldThrowInAlterOnSourceStream() {
// Given:
final AlterSource alterSource = new AlterSource(STREAM_NAME, DataSourceType.KSTREAM, NEW_COLUMNS);
when(ksqlStream.isSource()).thenReturn(true);
// When:
final Exception e = assertThrows(KsqlException.class, () -> alterSourceFactory.create(alterSource));
// Then:
assertThat(e.getMessage(), containsString("Cannot alter stream 'streamname': ALTER operations are not supported on " + "source streams."));
}
use of io.confluent.ksql.parser.tree.AlterSource 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.parser.tree.AlterSource in project ksql by confluentinc.
the class CommandFactoriesTest method shouldCreateCommandForAlterSource.
@Test
public void shouldCreateCommandForAlterSource() {
// Given:
final AlterSource ddlStatement = new AlterSource(SOME_NAME, DataSourceType.KSTREAM, new ArrayList<>());
// When:
final DdlCommand result = commandFactories.create(sqlExpression, ddlStatement, SessionConfig.of(ksqlConfig, emptyMap()));
// Then:
assertThat(result, is(alterSourceCommand));
verify(alterSourceFactory).create(ddlStatement);
}
use of io.confluent.ksql.parser.tree.AlterSource in project ksql by confluentinc.
the class AlterSourceFactoryTest method shouldThrowInAlterOnSourceTable.
@Test
public void shouldThrowInAlterOnSourceTable() {
// Given:
final AlterSource alterSource = new AlterSource(TABLE_NAME, DataSourceType.KTABLE, NEW_COLUMNS);
when(ksqlTable.isSource()).thenReturn(true);
// When:
final Exception e = assertThrows(KsqlException.class, () -> alterSourceFactory.create(alterSource));
// Then:
assertThat(e.getMessage(), containsString("Cannot alter table 'tablename': ALTER operations are not supported on " + "source tables."));
}
Aggregations