use of io.confluent.ksql.engine.KsqlPlan 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.engine.KsqlPlan in project ksql by confluentinc.
the class ValidatedCommandFactoryTest method givenNonDeserializableCommand.
private void givenNonDeserializableCommand() {
configuredStatement = configuredStatement("CREATE STREAM", plannedQuery);
final KsqlPlan planThatFailsToDeserialize = KsqlPlan.ddlPlanCurrent("some sql", new UnDeserializableCommand());
when(executionContext.plan(any(), any())).thenReturn(planThatFailsToDeserialize);
when(executionContext.getServiceContext()).thenReturn(serviceContext);
}
use of io.confluent.ksql.engine.KsqlPlan 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.engine.KsqlPlan in project ksql by confluentinc.
the class InteractiveStatementExecutorTest method commandWithPlan.
private Command commandWithPlan(final String sql, final Map<String, String> originalProperties) {
final PreparedStatement<?> prepared = statementParser.parseSingleStatement(sql);
final SessionConfig sessionConfig = SessionConfig.of(ksqlConfig, emptyMap());
final ConfiguredStatement<?> configured = ConfiguredStatement.of(prepared, sessionConfig);
final KsqlPlan plan = ksqlEngine.plan(serviceContext, configured);
return new Command(sql, Collections.emptyMap(), originalProperties, Optional.of(plan));
}
Aggregations