use of io.confluent.ksql.planner.plan.ConfiguredKsqlPlan in project ksql by confluentinc.
the class ValidatedCommandFactory method createForPlannedQuery.
private static Command createForPlannedQuery(final ConfiguredStatement<? extends Statement> statement, final ServiceContext serviceContext, final KsqlExecutionContext context) {
final KsqlPlan plan = context.plan(serviceContext, statement);
ConfiguredKsqlPlan configuredPlan = ConfiguredKsqlPlan.of(plan, statement.getSessionConfig());
final KsqlExecutionContext.ExecuteResult result = context.execute(serviceContext, configuredPlan);
if (result.getQuery().isPresent() && result.getQuery().get() instanceof PersistentQueryMetadataImpl && configuredPlan.getConfig().getConfig(false).getBoolean(KsqlConfig.KSQL_SHARED_RUNTIME_ENABLED)) {
configuredPlan = ConfiguredKsqlPlan.of(plan, statement.getSessionConfig().copyWith(ImmutableMap.of(KsqlConfig.KSQL_SHARED_RUNTIME_ENABLED, false)));
}
return Command.of(configuredPlan);
}
use of io.confluent.ksql.planner.plan.ConfiguredKsqlPlan in project ksql by confluentinc.
the class TestExecutorUtil method execute.
/**
* @param srClient if supplied, then schemas can be inferred from the schema registry.
* @return a list of persistent queries that should be run by the test executor, if a query was
* replaced via a CREATE OR REPLACE statement it will only appear once in the output list
*/
@SuppressWarnings("OptionalGetWithoutIsPresent")
private static List<PersistentQueryAndSources> execute(final KsqlEngine engine, final TestCase testCase, final KsqlConfig ksqlConfig, final ServiceContext serviceContext, final Optional<SchemaRegistryClient> srClient, final StubKafkaService stubKafkaService, final TestExecutionListener listener) {
final Map<QueryId, PersistentQueryAndSources> queries = new LinkedHashMap<>();
int idx = 0;
final Iterator<PlannedStatement> plans = planTestCase(engine, testCase, ksqlConfig, serviceContext, srClient, stubKafkaService);
try {
while (plans.hasNext()) {
++idx;
final PlannedStatement planned = plans.next();
if (planned.insertValues.isPresent()) {
final ConfiguredStatement<InsertValues> insertValues = planned.insertValues.get();
final SessionProperties sessionProperties = new SessionProperties(insertValues.getSessionConfig().getOverrides(), new KsqlHostInfo("host", 50), buildUrl(), false);
StubInsertValuesExecutor.of(stubKafkaService).execute(insertValues, sessionProperties, engine, engine.getServiceContext());
continue;
}
final ConfiguredKsqlPlan plan = planned.plan.orElseThrow(IllegalStateException::new);
listener.acceptPlan(plan);
final ExecuteResultAndSources result = executePlan(engine, plan);
if (!result.getSources().isPresent()) {
continue;
}
final PersistentQueryMetadata query = (PersistentQueryMetadata) result.getExecuteResult().getQuery().get();
listener.acceptQuery(query);
queries.put(query.getQueryId(), new PersistentQueryAndSources(query, result.getSources().get()));
}
return ImmutableList.copyOf(queries.values());
} catch (final KsqlStatementException e) {
if (testCase.expectedException().isPresent() && plans.hasNext()) {
throw new AssertionError("Only the last statement in a negative test should fail. " + "Yet in this case statement " + idx + " failed.", e);
}
throw e;
}
}
use of io.confluent.ksql.planner.plan.ConfiguredKsqlPlan in project ksql by confluentinc.
the class TestExecutorUtilTest method shouldPlanTestCase.
@Test
public void shouldPlanTestCase() {
// Given:
final TestCase testCase = loadTestCase(PROJECT_AND_FILTER);
// When:
final Iterator<PlannedStatement> plans = TestExecutorUtil.planTestCase(ksqlEngine, testCase, ksqlConfig, serviceContext, Optional.of(serviceContext.getSchemaRegistryClient()), stubKafkaService);
// Then:
final List<ConfiguredKsqlPlan> asList = new LinkedList<>();
while (plans.hasNext()) {
final PlannedStatement planned = plans.next();
final ConfiguredKsqlPlan plan = planned.plan.orElseThrow(() -> new AssertionError("Should be plan"));
ksqlEngine.execute(ksqlEngine.getServiceContext(), plan);
asList.add(plan);
}
assertThat(asList.size(), is(2));
assertThat(asList.get(0).getPlan().getStatementText(), startsWith("CREATE STREAM TEST"));
assertThat(asList.get(1).getPlan().getStatementText(), startsWith("CREATE STREAM S1 AS SELECT"));
}
use of io.confluent.ksql.planner.plan.ConfiguredKsqlPlan in project ksql by confluentinc.
the class InteractiveStatementExecutor method executePlan.
private void executePlan(final Command command, final CommandId commandId, final Optional<CommandStatusFuture> commandStatusFuture, final KsqlPlan plan, final Mode mode, final long offset, final boolean restoreInProgress) {
final KsqlConfig mergedConfig = buildMergedConfig(command);
final ConfiguredKsqlPlan configured = ConfiguredKsqlPlan.of(plan, SessionConfig.of(mergedConfig, command.getOverwriteProperties()));
putStatus(commandId, commandStatusFuture, new CommandStatus(CommandStatus.Status.EXECUTING, "Executing statement"));
final ExecuteResult result = ksqlEngine.execute(serviceContext, configured, restoreInProgress);
queryIdGenerator.setNextId(offset + 1);
if (result.getQuery().isPresent()) {
if (mode == Mode.EXECUTE) {
result.getQuery().get().start();
}
}
final String successMessage = getSuccessMessage(result);
final Optional<QueryId> queryId = result.getQuery().map(QueryMetadata::getQueryId);
final CommandStatus successStatus = new CommandStatus(CommandStatus.Status.SUCCESS, successMessage, queryId);
putFinalStatus(commandId, commandStatusFuture, successStatus);
}
Aggregations