Search in sources :

Example 21 with CreateStreamCommand

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

the class CreateSourceFactoryTest method shouldCreateStreamCommandWithSingleValueWrappingFromConfig.

@Test
public void shouldCreateStreamCommandWithSingleValueWrappingFromConfig() {
    // Given:
    ksqlConfig = new KsqlConfig(ImmutableMap.of(KsqlConfig.KSQL_WRAP_SINGLE_VALUES, false));
    final CreateStream statement = new CreateStream(SOME_NAME, ONE_KEY_ONE_VALUE, false, true, withProperties, false);
    // When:
    final CreateStreamCommand cmd = createSourceFactory.createStreamCommand(statement, ksqlConfig);
    // Then:
    assertThat(cmd.getFormats().getValueFeatures(), is(SerdeFeatures.of(SerdeFeature.UNWRAP_SINGLES)));
}
Also used : CreateStreamCommand(io.confluent.ksql.execution.ddl.commands.CreateStreamCommand) KsqlConfig(io.confluent.ksql.util.KsqlConfig) CreateStream(io.confluent.ksql.parser.tree.CreateStream) Test(org.junit.Test)

Example 22 with CreateStreamCommand

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

the class CreateSourceFactoryTest method shouldBuildSchemaWithExplicitKeyFieldForStream.

@Test
public void shouldBuildSchemaWithExplicitKeyFieldForStream() {
    // Given:
    final CreateStream statement = new CreateStream(SOME_NAME, TableElements.of(tableElement("k", new Type(SqlTypes.STRING), KEY_CONSTRAINT), ELEMENT1, ELEMENT2), false, true, withProperties, false);
    // When:
    final CreateStreamCommand result = createSourceFactory.createStreamCommand(statement, ksqlConfig);
    // Then:
    assertThat(result.getSchema(), is(LogicalSchema.builder().keyColumn(ColumnName.of("k"), SqlTypes.STRING).valueColumn(ColumnName.of("bob"), SqlTypes.STRING).valueColumn(ColumnName.of("hojjat"), BIGINT).build()));
}
Also used : DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) Type(io.confluent.ksql.execution.expression.tree.Type) CreateStreamCommand(io.confluent.ksql.execution.ddl.commands.CreateStreamCommand) CreateStream(io.confluent.ksql.parser.tree.CreateStream) Test(org.junit.Test)

Example 23 with CreateStreamCommand

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

the class CreateSourceFactoryTest method shouldCreateCommandForCreateStream.

@Test
public void shouldCreateCommandForCreateStream() {
    // Given:
    final CreateStream ddlStatement = new CreateStream(SOME_NAME, STREAM_ELEMENTS, false, true, withProperties, false);
    // When:
    final CreateStreamCommand result = createSourceFactory.createStreamCommand(ddlStatement, ksqlConfig);
    // Then:
    assertThat(result.getSourceName(), is(SOME_NAME));
    assertThat(result.getTopicName(), is(TOPIC_NAME));
    assertThat(result.getIsSource(), is(false));
}
Also used : CreateStreamCommand(io.confluent.ksql.execution.ddl.commands.CreateStreamCommand) CreateStream(io.confluent.ksql.parser.tree.CreateStream) Test(org.junit.Test)

Example 24 with CreateStreamCommand

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

the class DdlCommandExecTest method shouldAddSourceStream.

@Test
public void shouldAddSourceStream() {
    // Given:
    final CreateStreamCommand cmd = buildCreateStream(SourceName.of("t1"), SCHEMA, false, true);
    // When:
    cmdExec.execute(SQL_TEXT, cmd, true, NO_QUERY_SOURCES);
    // Then:
    final KsqlStream ksqlTable = (KsqlStream) metaStore.getSource(SourceName.of("t1"));
    assertThat(ksqlTable.isSource(), is(true));
}
Also used : KsqlStream(io.confluent.ksql.metastore.model.KsqlStream) CreateStreamCommand(io.confluent.ksql.execution.ddl.commands.CreateStreamCommand) Test(org.junit.Test)

Example 25 with CreateStreamCommand

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

the class DdlCommandExecTest method shouldThrowOnDropStreamWhenConstraintExist.

@Test
public void shouldThrowOnDropStreamWhenConstraintExist() {
    // Given:
    final CreateStreamCommand stream1 = buildCreateStream(SourceName.of("s1"), SCHEMA, false, false);
    final CreateStreamCommand stream2 = buildCreateStream(SourceName.of("s2"), SCHEMA, false, false);
    final CreateStreamCommand stream3 = buildCreateStream(SourceName.of("s3"), SCHEMA, false, false);
    cmdExec.execute(SQL_TEXT, stream1, true, Collections.emptySet());
    cmdExec.execute(SQL_TEXT, stream2, true, Collections.singleton(SourceName.of("s1")));
    cmdExec.execute(SQL_TEXT, stream3, true, Collections.singleton(SourceName.of("s1")));
    // When:
    final DropSourceCommand dropStream = buildDropSourceCommand(SourceName.of("s1"));
    final Exception e = assertThrows(KsqlReferentialIntegrityException.class, () -> cmdExec.execute(SQL_TEXT, dropStream, false, Collections.emptySet()));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot drop s1."));
    assertThat(e.getMessage(), containsString("The following streams and/or tables read from this source: [s2, s3]."));
    assertThat(e.getMessage(), containsString("You need to drop them before dropping s1."));
}
Also used : CreateStreamCommand(io.confluent.ksql.execution.ddl.commands.CreateStreamCommand) DropSourceCommand(io.confluent.ksql.execution.ddl.commands.DropSourceCommand) KsqlReferentialIntegrityException(io.confluent.ksql.util.KsqlReferentialIntegrityException) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Aggregations

CreateStreamCommand (io.confluent.ksql.execution.ddl.commands.CreateStreamCommand)26 Test (org.junit.Test)25 CreateStream (io.confluent.ksql.parser.tree.CreateStream)18 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)6 DropSourceCommand (io.confluent.ksql.execution.ddl.commands.DropSourceCommand)3 Type (io.confluent.ksql.execution.expression.tree.Type)3 TimestampColumn (io.confluent.ksql.execution.timestamp.TimestampColumn)3 DataSourceType (io.confluent.ksql.metastore.model.DataSource.DataSourceType)3 KsqlStream (io.confluent.ksql.metastore.model.KsqlStream)2 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)2 KsqlConfig (io.confluent.ksql.util.KsqlConfig)2 KsqlException (io.confluent.ksql.util.KsqlException)2 DdlCommandResult (io.confluent.ksql.execution.ddl.commands.DdlCommandResult)1 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)1 BooleanLiteral (io.confluent.ksql.execution.expression.tree.BooleanLiteral)1 DataSource (io.confluent.ksql.metastore.model.DataSource)1 SourceName (io.confluent.ksql.name.SourceName)1 CreateSourceProperties (io.confluent.ksql.parser.properties.with.CreateSourceProperties)1 KsqlStructuredDataOutputNode (io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode)1 CommandId (io.confluent.ksql.rest.entity.CommandId)1