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