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);
}
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;
}
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();
}
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;
}
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));
}
Aggregations