Search in sources :

Example 1 with CreateStreamCommand

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

the class CreateSourceFactory method createStreamCommand.

// This method is called by simple CREATE statements
public CreateStreamCommand createStreamCommand(final CreateStream statement, final KsqlConfig ksqlConfig) {
    final SourceName sourceName = statement.getName();
    final CreateSourceProperties props = statement.getProperties();
    final String topicName = ensureTopicExists(props, serviceContext);
    final LogicalSchema schema = buildSchema(statement.getElements(), ksqlConfig);
    final Optional<TimestampColumn> timestampColumn = buildTimestampColumn(ksqlConfig, props, schema);
    final DataSource dataSource = metaStore.getSource(sourceName);
    if (dataSource != null && !statement.isOrReplace() && !statement.isNotExists()) {
        final String sourceType = dataSource.getDataSourceType().getKsqlType();
        throw new KsqlException(String.format("Cannot add stream '%s': A %s with the same name already exists", sourceName.text(), sourceType.toLowerCase()));
    }
    throwIfCreateOrReplaceOnSourceStreamOrTable(statement, dataSource);
    return new CreateStreamCommand(sourceName, schema, timestampColumn, topicName, buildFormats(statement.getName(), schema, props, ksqlConfig), getWindowInfo(props), Optional.of(statement.isOrReplace()), Optional.of(statement.isSource()));
}
Also used : CreateStreamCommand(io.confluent.ksql.execution.ddl.commands.CreateStreamCommand) SourceName(io.confluent.ksql.name.SourceName) TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) KsqlException(io.confluent.ksql.util.KsqlException) CreateSourceProperties(io.confluent.ksql.parser.properties.with.CreateSourceProperties) DataSource(io.confluent.ksql.metastore.model.DataSource)

Example 2 with CreateStreamCommand

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

the class CreateSourceFactoryTest method shouldAllowNonStringKeyColumn.

@Test
public void shouldAllowNonStringKeyColumn() {
    // Given:
    final CreateStream statement = new CreateStream(SOME_NAME, TableElements.of(tableElement("k", new Type(SqlTypes.INTEGER), KEY_CONSTRAINT)), false, true, withProperties, false);
    // When:
    final CreateStreamCommand cmd = createSourceFactory.createStreamCommand(statement, ksqlConfig);
    // Then:
    assertThat(cmd.getSchema().key(), contains(keyColumn(ColumnName.of("k"), SqlTypes.INTEGER)));
}
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 3 with CreateStreamCommand

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

the class CreateSourceFactoryTest method shouldBuildTimestampColumnForStream.

@Test
public void shouldBuildTimestampColumnForStream() {
    // Given:
    givenProperty(CommonCreateConfigs.TIMESTAMP_NAME_PROPERTY, new StringLiteral(quote(ELEMENT2.getName().text())));
    final CreateStream statement = new CreateStream(SOME_NAME, STREAM_ELEMENTS, false, true, withProperties, false);
    // When:
    final CreateStreamCommand cmd = createSourceFactory.createStreamCommand(statement, ksqlConfig);
    // Then:
    assertThat(cmd.getTimestampColumn(), is(Optional.of(new TimestampColumn(ELEMENT2.getName(), Optional.empty()))));
}
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) TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) Test(org.junit.Test)

Example 4 with CreateStreamCommand

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

the class CreateSourceFactoryTest method shouldCreateCommandForCreateSourceStream.

@Test
public void shouldCreateCommandForCreateSourceStream() {
    // Given:
    final CreateStream ddlStatement = new CreateStream(SOME_NAME, STREAM_ELEMENTS, false, true, withProperties, true);
    // 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(true));
}
Also used : CreateStreamCommand(io.confluent.ksql.execution.ddl.commands.CreateStreamCommand) CreateStream(io.confluent.ksql.parser.tree.CreateStream) Test(org.junit.Test)

Example 5 with CreateStreamCommand

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

the class CreateSourceFactoryTest method shouldHandleValueAvroSchemaNameForStream.

@Test
public void shouldHandleValueAvroSchemaNameForStream() {
    // Given:
    givenCommandFactoriesWithMocks();
    givenProperty("VALUE_FORMAT", new StringLiteral("Avro"));
    givenProperty("value_avro_schema_full_name", new StringLiteral("full.schema.name"));
    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().getValueFormat(), is(FormatInfo.of(AVRO.name(), ImmutableMap.of(ConnectProperties.FULL_SCHEMA_NAME, "full.schema.name"))));
}
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)

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