Search in sources :

Example 16 with CommandId

use of io.confluent.ksql.rest.entity.CommandId in project ksql by confluentinc.

the class ClientTest method shouldExecuteSingleStatementWithMultipleSemicolons.

@Test
public void shouldExecuteSingleStatementWithMultipleSemicolons() throws Exception {
    // Given
    final CommandStatusEntity entity = new CommandStatusEntity("CREATE STREAM FOO AS CONCAT(A, 'wow;') FROM `BAR`;  ", new CommandId("STREAM", "FOO", "CREATE"), new CommandStatus(CommandStatus.Status.SUCCESS, "Success"), 0L);
    testEndpoints.setKsqlEndpointResponse(Collections.singletonList(entity));
    final Map<String, Object> properties = ImmutableMap.of("auto.offset.reset", "earliest");
    // When
    final ExecuteStatementResult result = javaClient.executeStatement("CREATE STREAM FOO AS CONCAT(A, `wow;`) FROM `BAR`;  ", properties).get();
    // Then
    assertThat(testEndpoints.getLastSql(), is("CREATE STREAM FOO AS CONCAT(A, `wow;`) FROM `BAR`;  "));
    assertThat(testEndpoints.getLastProperties(), is(new JsonObject().put("auto.offset.reset", "earliest")));
    assertThat(result.queryId(), is(Optional.empty()));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) JsonObject(io.vertx.core.json.JsonObject) CommandId(io.confluent.ksql.rest.entity.CommandId) Matchers.containsString(org.hamcrest.Matchers.containsString) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) BaseApiTest(io.confluent.ksql.api.BaseApiTest) Test(org.junit.Test)

Example 17 with CommandId

use of io.confluent.ksql.rest.entity.CommandId in project ksql by confluentinc.

the class InteractiveStatementExecutorTest method terminateQueries.

private void terminateQueries() {
    final Command terminateCommand1 = new Command("TERMINATE CSAS_USER1PV_1;", emptyMap(), ksqlConfig.getAllConfigPropsWithSecretsObfuscated(), Optional.empty());
    final CommandId terminateCommandId1 = new CommandId(CommandId.Type.STREAM, "_TerminateGen", CommandId.Action.CREATE);
    handleStatement(statementExecutor, terminateCommand1, terminateCommandId1, Optional.empty(), 0);
    assertThat(getCommandStatus(terminateCommandId1).getStatus(), equalTo(CommandStatus.Status.SUCCESS));
    final Command terminateCommand2 = new Command("TERMINATE CTAS_TABLE1_2;", emptyMap(), ksqlConfig.getAllConfigPropsWithSecretsObfuscated(), Optional.empty());
    final CommandId terminateCommandId2 = new CommandId(CommandId.Type.TABLE, "_TerminateGen", CommandId.Action.CREATE);
    handleStatement(statementExecutor, terminateCommand2, terminateCommandId2, Optional.empty(), 0);
    assertThat(getCommandStatus(terminateCommandId2).getStatus(), equalTo(CommandStatus.Status.SUCCESS));
}
Also used : CommandId(io.confluent.ksql.rest.entity.CommandId)

Example 18 with CommandId

use of io.confluent.ksql.rest.entity.CommandId in project ksql by confluentinc.

the class InteractiveStatementExecutorTest method createStreamsAndStartTwoPersistentQueries.

private List<Pair<CommandId, Command>> createStreamsAndStartTwoPersistentQueries() {
    final List<Pair<CommandId, Command>> commands = new ArrayList<>();
    final Command csCommand = commandWithPlan("CREATE STREAM pageview (" + "viewtime bigint," + " pageid varchar, " + "userid varchar) " + "WITH (kafka_topic = 'pageview_topic_json', " + "key_format = 'kafka', " + "value_format = 'json');", ksqlConfig.getAllConfigPropsWithSecretsObfuscated());
    final CommandId csCommandId = new CommandId(CommandId.Type.STREAM, "_CSASStreamGen", CommandId.Action.CREATE);
    handleStatement(csCommand, csCommandId, Optional.empty(), 0);
    commands.add(new Pair<>(csCommandId, csCommand));
    final Command csasCommand = commandWithPlan("CREATE STREAM user1pv AS " + "select * from pageview" + " WHERE userid = 'user1';", ksqlConfig.getAllConfigPropsWithSecretsObfuscated());
    final CommandId csasCommandId = new CommandId(CommandId.Type.STREAM, "_CSASGen", CommandId.Action.CREATE);
    handleStatement(csasCommand, csasCommandId, Optional.empty(), 1);
    commands.add(new Pair<>(csasCommandId, csasCommand));
    final Command ctasCommand = commandWithPlan("CREATE TABLE table1  AS " + "SELECT pageid, count(pageid) " + "FROM pageview " + "WINDOW TUMBLING ( SIZE 10 SECONDS) " + "GROUP BY pageid;", ksqlConfig.getAllConfigPropsWithSecretsObfuscated());
    final CommandId ctasCommandId = new CommandId(CommandId.Type.TABLE, "_CTASGen", CommandId.Action.CREATE);
    handleStatement(ctasCommand, ctasCommandId, Optional.empty(), 2);
    commands.add(new Pair<>(ctasCommandId, ctasCommand));
    assertThat(getCommandStatus(csCommandId).getStatus(), equalTo(CommandStatus.Status.SUCCESS));
    assertThat(getCommandStatus(csasCommandId).getStatus(), equalTo(CommandStatus.Status.SUCCESS));
    assertThat(getCommandStatus(ctasCommandId).getStatus(), equalTo(CommandStatus.Status.SUCCESS));
    return commands;
}
Also used : ArrayList(java.util.ArrayList) CommandId(io.confluent.ksql.rest.entity.CommandId) Pair(io.confluent.ksql.util.Pair)

Example 19 with CommandId

use of io.confluent.ksql.rest.entity.CommandId in project ksql by confluentinc.

the class InteractiveStatementExecutorTest method shouldBuildQueriesWithPersistedConfig.

@Test
public void shouldBuildQueriesWithPersistedConfig() {
    // Given:
    final KsqlConfig originalConfig = new KsqlConfig(Collections.singletonMap(KsqlConfig.KSQL_PERSISTENT_QUERY_NAME_PREFIX_CONFIG, "not-the-default"));
    // get a statement instance
    final String ddlText = "CREATE STREAM pageviews (viewtime bigint, pageid varchar) " + "WITH (kafka_topic='pageview_topic', KEY_FORMAT='kafka', VALUE_FORMAT='json');";
    final String statementText = "CREATE STREAM user1pv AS select * from pageviews WHERE userid = 'user1';";
    final PreparedStatement<?> ddlStatement = statementParser.parseSingleStatement(ddlText);
    final ConfiguredStatement<?> configuredStatement = ConfiguredStatement.of(ddlStatement, SessionConfig.of(originalConfig, emptyMap()));
    ksqlEngine.execute(serviceContext, configuredStatement);
    when(mockQueryMetadata.getQueryId()).thenReturn(mock(QueryId.class));
    final KsqlPlan plan = Mockito.mock(KsqlPlan.class);
    final Command csasCommand = new Command(statementText, emptyMap(), originalConfig.getAllConfigPropsWithSecretsObfuscated(), Optional.of(plan));
    final CommandId csasCommandId = new CommandId(CommandId.Type.STREAM, "_CSASGen", CommandId.Action.CREATE);
    when(mockEngine.execute(eq(serviceContext), eqConfiguredPlan(plan), eq(false))).thenReturn(ExecuteResult.of(mockQueryMetadata));
    // When:
    handleStatement(statementExecutorWithMocks, csasCommand, csasCommandId, Optional.empty(), 1);
    // Then:
    verify(mockQueryMetadata, times(1)).start();
}
Also used : QueryId(io.confluent.ksql.query.QueryId) KsqlConfig(io.confluent.ksql.util.KsqlConfig) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CommandId(io.confluent.ksql.rest.entity.CommandId) KsqlPlan(io.confluent.ksql.engine.KsqlPlan) ConfiguredKsqlPlan(io.confluent.ksql.planner.plan.ConfiguredKsqlPlan) Test(org.junit.Test)

Example 20 with CommandId

use of io.confluent.ksql.rest.entity.CommandId in project ksql by confluentinc.

the class RestoreCommandTopicIntegrationTest method shouldSkipIncompatibleCommands.

@Test
public void shouldSkipIncompatibleCommands() throws Exception {
    // Given
    TEST_HARNESS.ensureTopics("topic3", "topic4");
    makeKsqlRequest("CREATE STREAM TOPIC3 (ID INT) " + "WITH (KAFKA_TOPIC='topic3', VALUE_FORMAT='JSON');");
    makeKsqlRequest("CREATE STREAM TOPIC4 (ID INT) " + "WITH (KAFKA_TOPIC='topic4', VALUE_FORMAT='JSON');");
    makeKsqlRequest("CREATE STREAM stream3 AS SELECT * FROM topic3;");
    final CommandId commandId = new CommandId("TOPIC", "entity", "CREATE");
    final Command command = new Command("statement", Collections.emptyMap(), Collections.emptyMap(), Optional.empty(), Optional.of(Command.VERSION + 1), Command.VERSION + 1);
    writeToBackupFile(commandId, command, backupFile);
    // Delete the command topic again and restore with skip flag
    TEST_HARNESS.deleteTopics(Collections.singletonList(commandTopic));
    REST_APP.stop();
    KsqlRestoreCommandTopic.main(new String[] { "--yes", "-s", "--config-file", propertiesFile.toString(), backupFile.toString() });
    // Re-load the command topic
    REST_APP.start();
    final List<String> streamsNames = showStreams();
    assertThat("Should have TOPIC3", streamsNames.contains("TOPIC3"), is(true));
    assertThat("Should have TOPIC4", streamsNames.contains("TOPIC4"), is(true));
    assertThat("Should have STREAM3", streamsNames.contains("STREAM3"), is(true));
    assertThat("Server should not be in degraded state", isDegradedState(), is(false));
}
Also used : Command(io.confluent.ksql.rest.server.computation.Command) CommandId(io.confluent.ksql.rest.entity.CommandId) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Aggregations

CommandId (io.confluent.ksql.rest.entity.CommandId)29 Test (org.junit.Test)20 CommandStatus (io.confluent.ksql.rest.entity.CommandStatus)13 CommandStatusEntity (io.confluent.ksql.rest.entity.CommandStatusEntity)7 QueryId (io.confluent.ksql.query.QueryId)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 BaseApiTest (io.confluent.ksql.api.BaseApiTest)5 KsqlException (io.confluent.ksql.util.KsqlException)5 Command (io.confluent.ksql.rest.server.computation.Command)4 JsonObject (io.vertx.core.json.JsonObject)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 IntegrationTest (io.confluent.common.utils.IntegrationTest)3 KsqlServerException (io.confluent.ksql.util.KsqlServerException)3 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ExecutionException (java.util.concurrent.ExecutionException)3 TimeoutException (java.util.concurrent.TimeoutException)3 KsqlPlan (io.confluent.ksql.engine.KsqlPlan)2