use of io.confluent.ksql.name.SourceName in project ksql by confluentinc.
the class DefaultSchemaInjectorTest method setupCopy.
private static Object setupCopy(final InvocationOnMock inv, final CreateSource source, final CreateSource mock) {
final SourceName name = source.getName();
when(mock.getName()).thenReturn(name);
when(mock.getElements()).thenReturn(inv.getArgument(0));
when(mock.accept(any(), any())).thenCallRealMethod();
when(mock.getProperties()).thenReturn(inv.getArgument(1));
return mock;
}
use of io.confluent.ksql.name.SourceName in project ksql by confluentinc.
the class DistributingExecutor method checkIfNotExistsResponse.
// CHECKSTYLE_RULES.OFF: CyclomaticComplexity
private Optional<StatementExecutorResponse> checkIfNotExistsResponse(final KsqlExecutionContext executionContext, final ConfiguredStatement<?> statement) {
SourceName sourceName = null;
String type = "";
if (statement.getStatement() instanceof CreateStream && ((CreateStream) statement.getStatement()).isNotExists()) {
type = "stream";
sourceName = ((CreateStream) statement.getStatement()).getName();
} else if (statement.getStatement() instanceof CreateTable && ((CreateTable) statement.getStatement()).isNotExists()) {
type = "table";
sourceName = ((CreateTable) statement.getStatement()).getName();
} else if (statement.getStatement() instanceof CreateTableAsSelect && ((CreateTableAsSelect) statement.getStatement()).isNotExists()) {
type = "table";
sourceName = ((CreateTableAsSelect) statement.getStatement()).getName();
} else if (statement.getStatement() instanceof CreateStreamAsSelect && ((CreateStreamAsSelect) statement.getStatement()).isNotExists()) {
type = "stream";
sourceName = ((CreateStreamAsSelect) statement.getStatement()).getName();
}
if (sourceName != null && executionContext.getMetaStore().getSource(sourceName) != null) {
return Optional.of(StatementExecutorResponse.handled(Optional.of(new WarningEntity(statement.getStatementText(), String.format("Cannot add %s %s: A %s with the same name already exists.", type, sourceName, type)))));
} else {
return Optional.empty();
}
}
use of io.confluent.ksql.name.SourceName in project ksql by confluentinc.
the class CreateSourceFactoryTest method shouldThrowInCreateStreamOrReplaceOnSourceStreams.
@Test
public void shouldThrowInCreateStreamOrReplaceOnSourceStreams() {
// Given:
final SourceName existingStreamName = SourceName.of("existingStreamName");
final KsqlStream existingStream = mock(KsqlStream.class);
when(existingStream.getDataSourceType()).thenReturn(DataSourceType.KSTREAM);
when(existingStream.isSource()).thenReturn(true);
when(metaStore.getSource(existingStreamName)).thenReturn(existingStream);
final CreateStream ddlStatement = new CreateStream(existingStreamName, STREAM_ELEMENTS, true, false, withProperties, false);
// When:
final Exception e = assertThrows(KsqlException.class, () -> createSourceFactory.createStreamCommand(ddlStatement, ksqlConfig));
// Then:
assertThat(e.getMessage(), containsString("Cannot add stream 'existingStreamName': CREATE OR REPLACE is not supported on " + "source streams."));
}
use of io.confluent.ksql.name.SourceName in project ksql by confluentinc.
the class CreateSourceFactoryTest method shouldThrowInCreateStreamOrReplaceOnSourceTables.
@Test
public void shouldThrowInCreateStreamOrReplaceOnSourceTables() {
// Given:
final SourceName existingTableName = SourceName.of("existingTableName");
final KsqlTable existingTable = mock(KsqlTable.class);
when(existingTable.getDataSourceType()).thenReturn(DataSourceType.KTABLE);
when(existingTable.isSource()).thenReturn(true);
when(metaStore.getSource(existingTableName)).thenReturn(existingTable);
final CreateTable ddlStatement = new CreateTable(existingTableName, TableElements.of(tableElement("COL1", new Type(BIGINT), PRIMARY_KEY_CONSTRAINT), tableElement("COL2", new Type(SqlTypes.STRING))), true, false, withProperties, false);
// When:
final Exception e = assertThrows(KsqlException.class, () -> createSourceFactory.createTableCommand(ddlStatement, ksqlConfig));
// Then:
assertThat(e.getMessage(), containsString("Cannot add table 'existingTableName': CREATE OR REPLACE is not supported on " + "source tables."));
}
Aggregations