Search in sources :

Example 16 with TransientQueryMetadata

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

the class QueryBuilder method buildTransientQuery.

@SuppressWarnings("ParameterNumber")
TransientQueryMetadata buildTransientQuery(final String statementText, final QueryId queryId, final Set<SourceName> sources, final ExecutionStep<?> physicalPlan, final String planSummary, final LogicalSchema schema, final OptionalInt limit, final Optional<WindowInfo> windowInfo, final boolean excludeTombstones, final QueryMetadata.Listener listener, final StreamsBuilder streamsBuilder, final Optional<ImmutableMap<TopicPartition, Long>> endOffsets, final MetricCollectors metricCollectors) {
    final KsqlConfig ksqlConfig = config.getConfig(true);
    final String applicationId = QueryApplicationId.build(ksqlConfig, false, queryId);
    final RuntimeBuildContext runtimeBuildContext = buildContext(applicationId, queryId, streamsBuilder);
    final Map<String, Object> streamsProperties = buildStreamsProperties(applicationId, Optional.of(queryId), metricCollectors, config.getConfig(true), processingLogContext);
    final Object buildResult = buildQueryImplementation(physicalPlan, runtimeBuildContext);
    final TransientQueryQueue queue = buildTransientQueryQueue(buildResult, limit, excludeTombstones, endOffsets);
    final Topology topology = streamsBuilder.build(PropertiesUtil.asProperties(streamsProperties));
    final TransientQueryMetadata.ResultType resultType = buildResult instanceof KTableHolder ? windowInfo.isPresent() ? ResultType.WINDOWED_TABLE : ResultType.TABLE : ResultType.STREAM;
    return new TransientQueryMetadata(statementText, schema, sources, planSummary, queue, queryId, applicationId, topology, kafkaStreamsBuilder, streamsProperties, config.getOverrides(), ksqlConfig.getLong(KSQL_SHUTDOWN_TIMEOUT_MS_CONFIG), ksqlConfig.getInt(KsqlConfig.KSQL_QUERY_ERROR_MAX_QUEUE_SIZE), resultType, ksqlConfig.getLong(KsqlConfig.KSQL_QUERY_RETRY_BACKOFF_INITIAL_MS), ksqlConfig.getLong(KsqlConfig.KSQL_QUERY_RETRY_BACKOFF_MAX_MS), listener);
}
Also used : RuntimeBuildContext(io.confluent.ksql.execution.runtime.RuntimeBuildContext) KTableHolder(io.confluent.ksql.execution.plan.KTableHolder) KsqlConfig(io.confluent.ksql.util.KsqlConfig) Topology(org.apache.kafka.streams.Topology) NamedTopology(org.apache.kafka.streams.processor.internals.namedtopology.NamedTopology) TransientQueryMetadata(io.confluent.ksql.util.TransientQueryMetadata)

Example 17 with TransientQueryMetadata

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

the class QueryRegistryImpl method createStreamPullQuery.

// CHECKSTYLE_RULES.OFF: ParameterNumberCheck
@Override
public TransientQueryMetadata createStreamPullQuery(final SessionConfig config, final ServiceContext serviceContext, final ProcessingLogContext processingLogContext, final MetaStore metaStore, final String statementText, final QueryId queryId, final Set<SourceName> sources, final ExecutionStep<?> physicalPlan, final String planSummary, final LogicalSchema schema, final OptionalInt limit, final Optional<WindowInfo> windowInfo, final boolean excludeTombstones, final ImmutableMap<TopicPartition, Long> endOffsets) {
    // CHECKSTYLE_RULES.ON: ParameterNumberCheck
    final QueryBuilder queryBuilder = queryBuilderFactory.create(config, processingLogContext, serviceContext, metaStore, streams, !sandbox);
    final TransientQueryMetadata query = queryBuilder.buildTransientQuery(statementText, queryId, sources, physicalPlan, planSummary, schema, limit, windowInfo, excludeTombstones, new ListenerImpl(), new StreamsBuilder(), Optional.of(endOffsets), metricCollectors);
    query.initialize();
    // We don't register it as a transient query, so it won't show up in `show queries;`,
    // nor will it count against the push query limit.
    notifyCreate(serviceContext, metaStore, query);
    return query;
}
Also used : StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) SandboxedTransientQueryMetadata(io.confluent.ksql.util.SandboxedTransientQueryMetadata) TransientQueryMetadata(io.confluent.ksql.util.TransientQueryMetadata)

Example 18 with TransientQueryMetadata

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

the class QueryRegistryImpl method close.

@Override
public void close(final boolean closePersistent) {
    for (final QueryMetadata queryMetadata : getAllLiveQueries()) {
        // only persistent queries can be stopped - transient queries must be closed (destroyed)
        if (closePersistent || queryMetadata instanceof TransientQueryMetadata) {
            queryMetadata.close();
        } else {
            // stop will not unregister the query, since it's possible for a query to be stopped
            // but still managed by the registry. So we explicitly unregister here.
            ((PersistentQueryMetadata) queryMetadata).stop();
            unregisterQuery(queryMetadata);
        }
    }
    closeRuntimes();
}
Also used : SandboxedTransientQueryMetadata(io.confluent.ksql.util.SandboxedTransientQueryMetadata) TransientQueryMetadata(io.confluent.ksql.util.TransientQueryMetadata) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) QueryMetadata(io.confluent.ksql.util.QueryMetadata) SandboxedTransientQueryMetadata(io.confluent.ksql.util.SandboxedTransientQueryMetadata) TransientQueryMetadata(io.confluent.ksql.util.TransientQueryMetadata) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata)

Example 19 with TransientQueryMetadata

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

the class QueryRegistryImplTest method givenCreateTransient.

private TransientQueryMetadata givenCreateTransient(final QueryRegistry registry, final String id) {
    final QueryId queryId = new QueryId(id);
    final TransientQueryMetadata query = mock(TransientQueryMetadata.class);
    when(query.getQueryId()).thenReturn(queryId);
    when(queryBuilder.buildTransientQuery(any(), any(), any(), any(), any(), any(), any(), any(), anyBoolean(), any(), any(), any(), any())).thenReturn(query);
    when(query.isInitialized()).thenReturn(true);
    registry.createTransientQuery(config, serviceContext, logContext, metaStore, "sql", queryId, ImmutableSet.of(SourceName.of("some-source")), mock(ExecutionStep.class), "plan-summary", mock(LogicalSchema.class), OptionalInt.of(123), Optional.empty(), false);
    return query;
}
Also used : ExecutionStep(io.confluent.ksql.execution.plan.ExecutionStep) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) TransientQueryMetadata(io.confluent.ksql.util.TransientQueryMetadata)

Example 20 with TransientQueryMetadata

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

the class EndToEndIntegrationTest method shouldSelectAllFromUsers.

@Test
public void shouldSelectAllFromUsers() throws Exception {
    final TransientQueryMetadata queryMetadata = executeStatement("SELECT * from %s EMIT CHANGES;", USER_TABLE);
    final Set<String> expectedUsers = USER_DATA_PROVIDER.data().keySet().stream().map(s -> (String) s.get(0)).collect(Collectors.toSet());
    final List<GenericRow> rows = verifyAvailableRows(queryMetadata, expectedUsers.size());
    final Set<Object> actualUsers = rows.stream().filter(Objects::nonNull).peek(row -> assertThat(row.values(), hasSize(4))).map(row -> row.get(0)).collect(Collectors.toSet());
    assertThat(CONSUMED_COUNT.get(), greaterThan(0));
    assertThat(actualUsers, is(expectedUsers));
}
Also used : Arrays(java.util.Arrays) Matchers.either(org.hamcrest.Matchers.either) KeyValue(io.confluent.ksql.util.KeyValue) BlockingRowQueue(io.confluent.ksql.query.BlockingRowQueue) AssertEventually.assertThatEventually(io.confluent.ksql.test.util.AssertEventually.assertThatEventually) LoggerFactory(org.slf4j.LoggerFactory) ConsumerRecords(org.apache.kafka.clients.consumer.ConsumerRecords) TransientQueryMetadata(io.confluent.ksql.util.TransientQueryMetadata) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) After(org.junit.After) QueryId(io.confluent.ksql.query.QueryId) ClassRule(org.junit.ClassRule) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) Parameterized(org.junit.runners.Parameterized) ZooKeeperClientException(kafka.zookeeper.ZooKeeperClientException) QueryMetadata(io.confluent.ksql.util.QueryMetadata) Configurable(org.apache.kafka.common.Configurable) KSQL_FUNCTIONS_PROPERTY_PREFIX(io.confluent.ksql.util.KsqlConfig.KSQL_FUNCTIONS_PROPERTY_PREFIX) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Set(java.util.Set) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) KsqlConfig(io.confluent.ksql.util.KsqlConfig) TopicListing(org.apache.kafka.clients.admin.TopicListing) RecordMetadata(org.apache.kafka.clients.producer.RecordMetadata) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Matchers.startsWith(org.hamcrest.Matchers.startsWith) Objects(java.util.Objects) List(java.util.List) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) UserDataProvider(io.confluent.ksql.util.UserDataProvider) KsqlConstants(io.confluent.ksql.util.KsqlConstants) ConsumerInterceptor(org.apache.kafka.clients.consumer.ConsumerInterceptor) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) StreamsConfig(org.apache.kafka.streams.StreamsConfig) PageViewDataProvider(io.confluent.ksql.util.PageViewDataProvider) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) JSON(io.confluent.ksql.serde.FormatFactory.JSON) ProducerInterceptor(org.apache.kafka.clients.producer.ProducerInterceptor) RunWith(org.junit.runner.RunWith) IntegrationTest(org.apache.kafka.test.IntegrationTest) AvroSchema(io.confluent.kafka.schemaregistry.avro.AvroSchema) ArrayList(java.util.ArrayList) KeyValueMetadata(io.confluent.ksql.util.KeyValueMetadata) Timeout(org.junit.rules.Timeout) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) Before(org.junit.Before) UdfDescription(io.confluent.ksql.function.udf.UdfDescription) Logger(org.slf4j.Logger) Udf(io.confluent.ksql.function.udf.Udf) KAFKA(io.confluent.ksql.serde.FormatFactory.KAFKA) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) RuleChain(org.junit.rules.RuleChain) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Rule(org.junit.Rule) GenericRow(io.confluent.ksql.GenericRow) Format(io.confluent.ksql.serde.Format) ListTopicsResult(org.apache.kafka.clients.admin.ListTopicsResult) GenericRow(io.confluent.ksql.GenericRow) TransientQueryMetadata(io.confluent.ksql.util.TransientQueryMetadata) IntegrationTest(org.apache.kafka.test.IntegrationTest) Test(org.junit.Test)

Aggregations

TransientQueryMetadata (io.confluent.ksql.util.TransientQueryMetadata)22 Test (org.junit.Test)10 QueryId (io.confluent.ksql.query.QueryId)5 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)5 QueryMetadata (io.confluent.ksql.util.QueryMetadata)5 GenericRow (io.confluent.ksql.GenericRow)4 KsqlConfig (io.confluent.ksql.util.KsqlConfig)4 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)4 IntegrationTest (org.apache.kafka.test.IntegrationTest)4 Before (org.junit.Before)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Query (io.confluent.ksql.parser.tree.Query)3 BlockingRowQueue (io.confluent.ksql.query.BlockingRowQueue)3 KeyValue (io.confluent.ksql.util.KeyValue)3 KeyValueMetadata (io.confluent.ksql.util.KeyValueMetadata)3 Collection (java.util.Collection)3 List (java.util.List)3 Map (java.util.Map)3 Objects (java.util.Objects)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2