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()));
}
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)));
}
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()))));
}
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));
}
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"))));
}
Aggregations