Search in sources :

Example 6 with AlterSourceCommand

use of io.confluent.ksql.execution.ddl.commands.AlterSourceCommand in project ksql by confluentinc.

the class DdlCommandExecTest method shouldThrowOnMismatchedDatasourceType.

@Test
public void shouldThrowOnMismatchedDatasourceType() {
    // Given:
    alterSource = new AlterSourceCommand(EXISTING_STREAM, DataSourceType.KTABLE.getKsqlType(), NEW_COLUMNS);
    // When:
    final KsqlException e = assertThrows(KsqlException.class, () -> cmdExec.execute(SQL_TEXT, alterSource, false, NO_QUERY_SOURCES));
    // Then:
    assertThat(e.getMessage(), is("Incompatible data source type is STREAM, but statement was ALTER TABLE"));
}
Also used : AlterSourceCommand(io.confluent.ksql.execution.ddl.commands.AlterSourceCommand) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 7 with AlterSourceCommand

use of io.confluent.ksql.execution.ddl.commands.AlterSourceCommand in project ksql by confluentinc.

the class DdlCommandExecTest method shouldAlterTable.

@Test
public void shouldAlterTable() {
    // Given:
    alterSource = new AlterSourceCommand(EXISTING_TABLE, DataSourceType.KTABLE.getKsqlType(), NEW_COLUMNS);
    // When:
    final DdlCommandResult result = cmdExec.execute(SQL_TEXT, alterSource, false, NO_QUERY_SOURCES);
    // Then:
    assertThat(result.isSuccess(), is(true));
    assertThat(metaStore.getSource(EXISTING_TABLE).getSchema().columns().size(), is(8));
    assertThat(metaStore.getSource(EXISTING_TABLE).getSqlExpression(), is("sqlexpression\nsome ksql"));
}
Also used : DdlCommandResult(io.confluent.ksql.execution.ddl.commands.DdlCommandResult) AlterSourceCommand(io.confluent.ksql.execution.ddl.commands.AlterSourceCommand) Test(org.junit.Test)

Example 8 with AlterSourceCommand

use of io.confluent.ksql.execution.ddl.commands.AlterSourceCommand in project ksql by confluentinc.

the class DdlCommandExecTest method shouldAlterStream.

@Test
public void shouldAlterStream() {
    // Given:
    alterSource = new AlterSourceCommand(EXISTING_STREAM, DataSourceType.KSTREAM.getKsqlType(), NEW_COLUMNS);
    // When:
    final DdlCommandResult result = cmdExec.execute(SQL_TEXT, alterSource, false, NO_QUERY_SOURCES);
    // Then:
    assertThat(result.isSuccess(), is(true));
    assertThat(metaStore.getSource(EXISTING_STREAM).getSchema().columns().size(), is(10));
    assertThat(metaStore.getSource(EXISTING_STREAM).getSqlExpression(), is("sqlexpression\nsome ksql"));
}
Also used : DdlCommandResult(io.confluent.ksql.execution.ddl.commands.DdlCommandResult) AlterSourceCommand(io.confluent.ksql.execution.ddl.commands.AlterSourceCommand) Test(org.junit.Test)

Example 9 with AlterSourceCommand

use of io.confluent.ksql.execution.ddl.commands.AlterSourceCommand in project ksql by confluentinc.

the class AlterSourceFactoryTest method shouldCreateCommandForAlterStream.

@Test
public void shouldCreateCommandForAlterStream() {
    // Given:
    final AlterSource alterSource = new AlterSource(STREAM_NAME, DataSourceType.KSTREAM, NEW_COLUMNS);
    // When:
    final AlterSourceCommand result = alterSourceFactory.create(alterSource);
    // Then:
    assertEquals(result.getKsqlType(), DataSourceType.KSTREAM.getKsqlType());
    assertEquals(result.getSourceName(), STREAM_NAME);
    assertEquals(result.getNewColumns().size(), 1);
}
Also used : AlterSource(io.confluent.ksql.parser.tree.AlterSource) AlterSourceCommand(io.confluent.ksql.execution.ddl.commands.AlterSourceCommand) Test(org.junit.Test)

Aggregations

AlterSourceCommand (io.confluent.ksql.execution.ddl.commands.AlterSourceCommand)9 Test (org.junit.Test)8 KsqlException (io.confluent.ksql.util.KsqlException)5 AlterSource (io.confluent.ksql.parser.tree.AlterSource)3 DdlCommandResult (io.confluent.ksql.execution.ddl.commands.DdlCommandResult)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 MetaStore (io.confluent.ksql.metastore.MetaStore)1 DataSource (io.confluent.ksql.metastore.model.DataSource)1 ColumnName (io.confluent.ksql.name.ColumnName)1 Column (io.confluent.ksql.schema.ksql.Column)1 Namespace (io.confluent.ksql.schema.ksql.Column.Namespace)1 List (java.util.List)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Collectors (java.util.stream.Collectors)1