Search in sources :

Example 1 with KsqlPlan

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);
}
Also used : ConfiguredKsqlPlan(io.confluent.ksql.planner.plan.ConfiguredKsqlPlan) PersistentQueryMetadataImpl(io.confluent.ksql.util.PersistentQueryMetadataImpl) KsqlPlan(io.confluent.ksql.engine.KsqlPlan) ConfiguredKsqlPlan(io.confluent.ksql.planner.plan.ConfiguredKsqlPlan) KsqlExecutionContext(io.confluent.ksql.KsqlExecutionContext)

Example 2 with KsqlPlan

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);
}
Also used : KsqlPlan(io.confluent.ksql.engine.KsqlPlan) ConfiguredKsqlPlan(io.confluent.ksql.planner.plan.ConfiguredKsqlPlan)

Example 3 with KsqlPlan

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();
}
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 4 with KsqlPlan

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));
}
Also used : SessionConfig(io.confluent.ksql.config.SessionConfig) KsqlPlan(io.confluent.ksql.engine.KsqlPlan) ConfiguredKsqlPlan(io.confluent.ksql.planner.plan.ConfiguredKsqlPlan)

Aggregations

KsqlPlan (io.confluent.ksql.engine.KsqlPlan)4 ConfiguredKsqlPlan (io.confluent.ksql.planner.plan.ConfiguredKsqlPlan)4 KsqlExecutionContext (io.confluent.ksql.KsqlExecutionContext)1 SessionConfig (io.confluent.ksql.config.SessionConfig)1 QueryId (io.confluent.ksql.query.QueryId)1 CommandId (io.confluent.ksql.rest.entity.CommandId)1 KsqlConfig (io.confluent.ksql.util.KsqlConfig)1 PersistentQueryMetadataImpl (io.confluent.ksql.util.PersistentQueryMetadataImpl)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1