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