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