Search in sources :

Example 6 with CreateStreamCommand

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

the class CreateSourceFactoryTest method shouldHandleTumblingWindowedKeyForStream.

@Test
public void shouldHandleTumblingWindowedKeyForStream() {
    // Given:
    givenProperties(ImmutableMap.of("window_type", new StringLiteral("tumbling"), "window_size", new StringLiteral("1 MINUTE")));
    final CreateStream statement = new CreateStream(SOME_NAME, STREAM_ELEMENTS, false, true, withProperties, false);
    // When:
    final CreateStreamCommand cmd = createSourceFactory.createStreamCommand(statement, ksqlConfig);
    // Then:
    assertThat(cmd.getFormats().getKeyFormat(), is(FormatInfo.of(KAFKA.name())));
    assertThat(cmd.getWindowInfo(), is(Optional.of(WindowInfo.of(TUMBLING, Optional.of(Duration.ofMinutes(1))))));
}
Also used : CreateStreamCommand(io.confluent.ksql.execution.ddl.commands.CreateStreamCommand) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) CreateStream(io.confluent.ksql.parser.tree.CreateStream) Test(org.junit.Test)

Example 7 with CreateStreamCommand

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

the class CreateSourceFactoryTest method shouldBuildSchemaWithImplicitKeyFieldForStream.

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

Example 8 with CreateStreamCommand

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

the class CreateSourceFactoryTest method shouldHandleHoppingWindowedKeyForStream.

@Test
public void shouldHandleHoppingWindowedKeyForStream() {
    // Given:
    givenProperties(ImmutableMap.of("window_type", new StringLiteral("Hopping"), "window_size", new StringLiteral("2 SECONDS")));
    final CreateStream statement = new CreateStream(SOME_NAME, STREAM_ELEMENTS, false, true, withProperties, false);
    // When:
    final CreateStreamCommand cmd = createSourceFactory.createStreamCommand(statement, ksqlConfig);
    // Then:
    assertThat(cmd.getFormats().getKeyFormat(), is(FormatInfo.of(KAFKA.name())));
    assertThat(cmd.getWindowInfo(), is(Optional.of(WindowInfo.of(HOPPING, Optional.of(Duration.ofSeconds(2))))));
}
Also used : CreateStreamCommand(io.confluent.ksql.execution.ddl.commands.CreateStreamCommand) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) CreateStream(io.confluent.ksql.parser.tree.CreateStream) Test(org.junit.Test)

Example 9 with CreateStreamCommand

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

the class CreateSourceFactoryTest method shouldCreateStreamCommandWithSingleValueWrappingFromDefaultConfig.

@Test
public void shouldCreateStreamCommandWithSingleValueWrappingFromDefaultConfig() {
    // Given:
    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()));
}
Also used : CreateStreamCommand(io.confluent.ksql.execution.ddl.commands.CreateStreamCommand) CreateStream(io.confluent.ksql.parser.tree.CreateStream) Test(org.junit.Test)

Example 10 with CreateStreamCommand

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

the class CreateSourceFactoryTest method shouldBuildSerdeFeaturesForStream.

@Test
public void shouldBuildSerdeFeaturesForStream() {
    // Given:
    givenCommandFactoriesWithMocks();
    final CreateStream statement = new CreateStream(SOME_NAME, ONE_KEY_ONE_VALUE, false, true, withProperties, false);
    final LogicalSchema schema = LogicalSchema.builder().keyColumn(ColumnName.of("k"), SqlTypes.INTEGER).valueColumn(ColumnName.of("bob"), SqlTypes.STRING).build();
    when(keyOptionsSupplier.build(any(), any(), any(), any())).thenReturn(SerdeFeatures.of(SerdeFeature.WRAP_SINGLES));
    when(valOptionsSupplier.build(any(), any(), any(), any())).thenReturn(SerdeFeatures.of(SerdeFeature.UNWRAP_SINGLES));
    // When:
    final CreateStreamCommand cmd = createSourceFactory.createStreamCommand(statement, ksqlConfig);
    // Then:
    verify(keyOptionsSupplier).build(schema, FormatFactory.of(SourcePropertiesUtil.getKeyFormat(statement.getProperties(), SOME_NAME)), SerdeFeatures.of(), ksqlConfig);
    verify(valOptionsSupplier).build(schema, FormatFactory.of(SourcePropertiesUtil.getValueFormat(statement.getProperties())), statement.getProperties().getValueSerdeFeatures(), ksqlConfig);
    assertThat(cmd.getFormats().getKeyFeatures(), is(SerdeFeatures.of(SerdeFeature.WRAP_SINGLES)));
    assertThat(cmd.getFormats().getValueFeatures(), is(SerdeFeatures.of(SerdeFeature.UNWRAP_SINGLES)));
}
Also used : CreateStreamCommand(io.confluent.ksql.execution.ddl.commands.CreateStreamCommand) CreateStream(io.confluent.ksql.parser.tree.CreateStream) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) 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