Search in sources :

Example 1 with WarningEntity

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()));
}
Also used : WarningEntity(io.confluent.ksql.rest.entity.WarningEntity) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) BaseApiTest(io.confluent.ksql.api.BaseApiTest) Test(org.junit.Test)

Example 2 with WarningEntity

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();
    }
}
Also used : CreateTableAsSelect(io.confluent.ksql.parser.tree.CreateTableAsSelect) CreateTable(io.confluent.ksql.parser.tree.CreateTable) SourceName(io.confluent.ksql.name.SourceName) CreateStream(io.confluent.ksql.parser.tree.CreateStream) CreateStreamAsSelect(io.confluent.ksql.parser.tree.CreateStreamAsSelect) WarningEntity(io.confluent.ksql.rest.entity.WarningEntity)

Aggregations

WarningEntity (io.confluent.ksql.rest.entity.WarningEntity)2 BaseApiTest (io.confluent.ksql.api.BaseApiTest)1 SourceName (io.confluent.ksql.name.SourceName)1 CreateStream (io.confluent.ksql.parser.tree.CreateStream)1 CreateStreamAsSelect (io.confluent.ksql.parser.tree.CreateStreamAsSelect)1 CreateTable (io.confluent.ksql.parser.tree.CreateTable)1 CreateTableAsSelect (io.confluent.ksql.parser.tree.CreateTableAsSelect)1 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)1 Test (org.junit.Test)1