Search in sources :

Example 1 with PersistentQueryMetadataImpl

use of io.confluent.ksql.util.PersistentQueryMetadataImpl 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 PersistentQueryMetadataImpl

use of io.confluent.ksql.util.PersistentQueryMetadataImpl in project ksql by confluentinc.

the class ValidatedCommandFactoryTest method shouldCreateCommandForPlannedQueryInDedicatedRuntime.

@Test
public void shouldCreateCommandForPlannedQueryInDedicatedRuntime() {
    // Given:
    givenPlannedQuery();
    PersistentQueryMetadataImpl queryMetadata = mock(PersistentQueryMetadataImpl.class);
    when(executionContext.execute(any(), any(ConfiguredKsqlPlan.class))).thenReturn(result);
    when(result.getQuery()).thenReturn(Optional.ofNullable(queryMetadata));
    when(config.getBoolean(KsqlConfig.KSQL_SHARED_RUNTIME_ENABLED)).thenReturn(true);
    // When:
    final Command command = commandFactory.create(configuredStatement, executionContext);
    // Then:
    assertThat(command, is(Command.of(ConfiguredKsqlPlan.of(A_PLAN, SessionConfig.of(config, ImmutableMap.of(KsqlConfig.KSQL_SHARED_RUNTIME_ENABLED, false))))));
}
Also used : ConfiguredKsqlPlan(io.confluent.ksql.planner.plan.ConfiguredKsqlPlan) BinPackedPersistentQueryMetadataImpl(io.confluent.ksql.util.BinPackedPersistentQueryMetadataImpl) PersistentQueryMetadataImpl(io.confluent.ksql.util.PersistentQueryMetadataImpl) DdlCommand(io.confluent.ksql.execution.ddl.commands.DdlCommand) DropSourceCommand(io.confluent.ksql.execution.ddl.commands.DropSourceCommand) Test(org.junit.Test)

Example 3 with PersistentQueryMetadataImpl

use of io.confluent.ksql.util.PersistentQueryMetadataImpl in project ksql by confluentinc.

the class QueryDescriptionFactoryTest method setUp.

@Before
public void setUp() {
    when(topology.describe()).thenReturn(topologyDescription);
    when(kafkaStreamsBuilder.build(any(), any())).thenReturn(queryStreams);
    when(queryStreams.metadataForLocalThreads()).thenReturn(Collections.emptySet());
    when(sinkTopic.getKeyFormat()).thenReturn(KeyFormat.nonWindowed(FormatInfo.of(FormatFactory.KAFKA.name()), SerdeFeatures.of()));
    when(sinkDataSource.getKsqlTopic()).thenReturn(sinkTopic);
    when(sinkDataSource.getName()).thenReturn(SourceName.of("sink name"));
    transientQuery = new TransientQueryMetadata(SQL_TEXT, TRANSIENT_SCHEMA, SOURCE_NAMES, "execution plan", queryQueue, QUERY_ID, APPLICATION_ID, topology, kafkaStreamsBuilder, STREAMS_PROPS, PROP_OVERRIDES, closeTimeout, 10, ResultType.STREAM, 0L, 0L, listener);
    transientQuery.initialize();
    transientQueryDescription = QueryDescriptionFactory.forQueryMetadata(transientQuery, Collections.emptyMap());
    persistentQuery = new PersistentQueryMetadataImpl(KsqlConstants.PersistentQueryType.CREATE_AS, SQL_TEXT, PhysicalSchema.from(PERSISTENT_SCHEMA, SerdeFeatures.of(), SerdeFeatures.of()), SOURCE_NAMES, Optional.of(sinkDataSource), "execution plan", QUERY_ID, Optional.empty(), APPLICATION_ID, topology, kafkaStreamsBuilder, new QuerySchemas(), STREAMS_PROPS, PROP_OVERRIDES, closeTimeout, QueryErrorClassifier.DEFAULT_CLASSIFIER, physicalPlan, 10, processingLogger, 0L, 0L, listener, Optional.empty());
    persistentQuery.initialize();
    persistentQueryDescription = QueryDescriptionFactory.forQueryMetadata(persistentQuery, STATUS_MAP);
}
Also used : QuerySchemas(io.confluent.ksql.schema.query.QuerySchemas) PersistentQueryMetadataImpl(io.confluent.ksql.util.PersistentQueryMetadataImpl) TransientQueryMetadata(io.confluent.ksql.util.TransientQueryMetadata) Before(org.junit.Before)

Example 4 with PersistentQueryMetadataImpl

use of io.confluent.ksql.util.PersistentQueryMetadataImpl in project ksql by confluentinc.

the class QueryBuilder method buildPersistentQueryInDedicatedRuntime.

@SuppressWarnings("ParameterNumber")
PersistentQueryMetadata buildPersistentQueryInDedicatedRuntime(final KsqlConfig ksqlConfig, final KsqlConstants.PersistentQueryType persistentQueryType, final String statementText, final QueryId queryId, final Optional<DataSource> sinkDataSource, final Set<DataSource> sources, final ExecutionStep<?> physicalPlan, final String planSummary, final QueryMetadata.Listener listener, final Supplier<List<PersistentQueryMetadata>> allPersistentQueries, final StreamsBuilder streamsBuilder, final MetricCollectors metricCollectors) {
    final String applicationId = QueryApplicationId.build(ksqlConfig, true, queryId);
    final Map<String, Object> streamsProperties = buildStreamsProperties(applicationId, Optional.of(queryId), metricCollectors, config.getConfig(true), processingLogContext);
    final LogicalSchema logicalSchema;
    final KeyFormat keyFormat;
    final ValueFormat valueFormat;
    final KsqlTopic ksqlTopic;
    switch(persistentQueryType) {
        // CREATE_SOURCE does not have a sink, so the schema is obtained from the query source
        case CREATE_SOURCE:
            final DataSource dataSource = Iterables.getOnlyElement(sources);
            logicalSchema = dataSource.getSchema();
            keyFormat = dataSource.getKsqlTopic().getKeyFormat();
            valueFormat = dataSource.getKsqlTopic().getValueFormat();
            ksqlTopic = dataSource.getKsqlTopic();
            break;
        default:
            logicalSchema = sinkDataSource.get().getSchema();
            keyFormat = sinkDataSource.get().getKsqlTopic().getKeyFormat();
            valueFormat = sinkDataSource.get().getKsqlTopic().getValueFormat();
            ksqlTopic = sinkDataSource.get().getKsqlTopic();
            break;
    }
    final PhysicalSchema querySchema = PhysicalSchema.from(logicalSchema, keyFormat.getFeatures(), valueFormat.getFeatures());
    final RuntimeBuildContext runtimeBuildContext = buildContext(applicationId, queryId, streamsBuilder);
    final Object result = buildQueryImplementation(physicalPlan, runtimeBuildContext);
    final Topology topology = streamsBuilder.build(PropertiesUtil.asProperties(streamsProperties));
    final Optional<MaterializationProviderBuilderFactory.MaterializationProviderBuilder> materializationProviderBuilder = getMaterializationInfo(result).map(info -> materializationProviderBuilderFactory.materializationProviderBuilder(info, querySchema, keyFormat, streamsProperties, applicationId, queryId.toString()));
    final Optional<ScalablePushRegistry> scalablePushRegistry = applyScalablePushProcessor(querySchema.logicalSchema(), result, allPersistentQueries, streamsProperties, applicationId, ksqlConfig, ksqlTopic, serviceContext);
    return new PersistentQueryMetadataImpl(persistentQueryType, statementText, querySchema, sources.stream().map(DataSource::getName).collect(Collectors.toSet()), sinkDataSource, planSummary, queryId, materializationProviderBuilder, applicationId, topology, kafkaStreamsBuilder, runtimeBuildContext.getSchemas(), streamsProperties, config.getOverrides(), ksqlConfig.getLong(KSQL_SHUTDOWN_TIMEOUT_MS_CONFIG), getConfiguredQueryErrorClassifier(ksqlConfig, applicationId), physicalPlan, ksqlConfig.getInt(KsqlConfig.KSQL_QUERY_ERROR_MAX_QUEUE_SIZE), getUncaughtExceptionProcessingLogger(queryId), ksqlConfig.getLong(KsqlConfig.KSQL_QUERY_RETRY_BACKOFF_INITIAL_MS), ksqlConfig.getLong(KsqlConfig.KSQL_QUERY_RETRY_BACKOFF_MAX_MS), listener, scalablePushRegistry);
}
Also used : ValueFormat(io.confluent.ksql.serde.ValueFormat) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Topology(org.apache.kafka.streams.Topology) NamedTopology(org.apache.kafka.streams.processor.internals.namedtopology.NamedTopology) KeyFormat(io.confluent.ksql.serde.KeyFormat) DataSource(io.confluent.ksql.metastore.model.DataSource) ScalablePushRegistry(io.confluent.ksql.physical.scalablepush.ScalablePushRegistry) RuntimeBuildContext(io.confluent.ksql.execution.runtime.RuntimeBuildContext) PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema) BinPackedPersistentQueryMetadataImpl(io.confluent.ksql.util.BinPackedPersistentQueryMetadataImpl) SandboxedBinPackedPersistentQueryMetadataImpl(io.confluent.ksql.util.SandboxedBinPackedPersistentQueryMetadataImpl) PersistentQueryMetadataImpl(io.confluent.ksql.util.PersistentQueryMetadataImpl) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic)

Example 5 with PersistentQueryMetadataImpl

use of io.confluent.ksql.util.PersistentQueryMetadataImpl in project ksql by confluentinc.

the class QueryRegistryImplTest method shouldReplaceQueryfromOldRuntimeUsingOldRuntime.

@Test
public void shouldReplaceQueryfromOldRuntimeUsingOldRuntime() {
    // Given:
    sharedRuntimes = false;
    QueryMetadata query = givenCreate(registry, "q1", "source", Optional.of("sink1"), CREATE_AS);
    assertThat("does not use old runtime", query instanceof PersistentQueryMetadataImpl);
    // When:
    sharedRuntimes = true;
    query = givenCreate(registry, "q1", "source", Optional.of("sink1"), CREATE_AS);
    // Expect:
    assertThat("does not use old runtime", query instanceof PersistentQueryMetadataImpl);
    when(ksqlConfig.getBoolean(KsqlConfig.KSQL_SHARED_RUNTIME_ENABLED)).thenReturn(sharedRuntimes);
    query = givenCreate(registry, "q2", "source", Optional.of("sink1"), CREATE_AS);
    assertThat("does not use old runtime", query instanceof BinPackedPersistentQueryMetadataImpl);
}
Also used : TransientQueryMetadata(io.confluent.ksql.util.TransientQueryMetadata) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) QueryMetadata(io.confluent.ksql.util.QueryMetadata) BinPackedPersistentQueryMetadataImpl(io.confluent.ksql.util.BinPackedPersistentQueryMetadataImpl) PersistentQueryMetadataImpl(io.confluent.ksql.util.PersistentQueryMetadataImpl) BinPackedPersistentQueryMetadataImpl(io.confluent.ksql.util.BinPackedPersistentQueryMetadataImpl) Test(org.junit.Test)

Aggregations

PersistentQueryMetadataImpl (io.confluent.ksql.util.PersistentQueryMetadataImpl)5 BinPackedPersistentQueryMetadataImpl (io.confluent.ksql.util.BinPackedPersistentQueryMetadataImpl)3 ConfiguredKsqlPlan (io.confluent.ksql.planner.plan.ConfiguredKsqlPlan)2 TransientQueryMetadata (io.confluent.ksql.util.TransientQueryMetadata)2 Test (org.junit.Test)2 KsqlExecutionContext (io.confluent.ksql.KsqlExecutionContext)1 KsqlPlan (io.confluent.ksql.engine.KsqlPlan)1 DdlCommand (io.confluent.ksql.execution.ddl.commands.DdlCommand)1 DropSourceCommand (io.confluent.ksql.execution.ddl.commands.DropSourceCommand)1 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)1 RuntimeBuildContext (io.confluent.ksql.execution.runtime.RuntimeBuildContext)1 DataSource (io.confluent.ksql.metastore.model.DataSource)1 ScalablePushRegistry (io.confluent.ksql.physical.scalablepush.ScalablePushRegistry)1 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)1 PhysicalSchema (io.confluent.ksql.schema.ksql.PhysicalSchema)1 QuerySchemas (io.confluent.ksql.schema.query.QuerySchemas)1 KeyFormat (io.confluent.ksql.serde.KeyFormat)1 ValueFormat (io.confluent.ksql.serde.ValueFormat)1 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)1 QueryMetadata (io.confluent.ksql.util.QueryMetadata)1