use of io.confluent.ksql.rest.entity.WarningEntity in project ksql by confluentinc.
the class ClientTest method shouldHandleIfNotExistsWarningResponseFromExecuteStatement.
@Test
public void shouldHandleIfNotExistsWarningResponseFromExecuteStatement() throws Exception {
// Given
KsqlEntity ksqlEntity = new WarningEntity("CREATE STREAM IF NOT EXISTS ", "Cannot add stream `HIGH_VALUE_STOCK_TRADES`: A stream with the same name already exists.");
testEndpoints.setKsqlEndpointResponse(Collections.singletonList(ksqlEntity));
final ExecuteStatementResult result = javaClient.executeStatement("CSAS;").get();
// Then
assertThat(result.queryId(), equalTo(Optional.empty()));
}
use of io.confluent.ksql.rest.entity.WarningEntity 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();
}
}
Aggregations