Search in sources :

Example 1 with ExecutionStep

use of io.confluent.ksql.execution.plan.ExecutionStep in project ksql by confluentinc.

the class QueryRegistryImplTest method givenCreate.

private PersistentQueryMetadata givenCreate(final QueryRegistry registry, final String id, final String source, final Optional<String> sink, KsqlConstants.PersistentQueryType persistentQueryType) {
    final QueryId queryId = new QueryId(id);
    final PersistentQueryMetadata query = mock(PersistentQueryMetadataImpl.class);
    final PersistentQueryMetadata newQuery = mock(BinPackedPersistentQueryMetadataImpl.class);
    final DataSource sinkSource = mock(DataSource.class);
    final ExecutionStep physicalPlan = mock(ExecutionStep.class);
    sink.ifPresent(s -> {
        when(sinkSource.getName()).thenReturn(SourceName.of(s));
        when(query.getSinkName()).thenReturn(Optional.of(SourceName.of(s)));
        when(newQuery.getSinkName()).thenReturn(Optional.of(SourceName.of(s)));
    });
    when(newQuery.getOverriddenProperties()).thenReturn(new HashMap<>());
    when(newQuery.getQueryId()).thenReturn(queryId);
    when(newQuery.getSink()).thenReturn(Optional.of(sinkSource));
    when(newQuery.getSourceNames()).thenReturn(ImmutableSet.of(SourceName.of(source)));
    when(newQuery.getPersistentQueryType()).thenReturn(persistentQueryType);
    when(newQuery.getPhysicalPlan()).thenReturn(physicalPlan);
    final SharedKafkaStreamsRuntime runtime = mock(SharedKafkaStreamsRuntimeImpl.class);
    try {
        Field sharedRuntime = BinPackedPersistentQueryMetadataImpl.class.getDeclaredField("sharedKafkaStreamsRuntime");
        sharedRuntime.setAccessible(true);
        sharedRuntime.set(newQuery, runtime);
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    when(runtime.getNewQueryErrorQueue()).thenReturn(mock(QueryMetadataImpl.TimeBoundedQueue.class));
    when(query.getQueryId()).thenReturn(queryId);
    when(query.getSink()).thenReturn(Optional.of(sinkSource));
    when(query.getSourceNames()).thenReturn(ImmutableSet.of(SourceName.of(source)));
    when(query.getPersistentQueryType()).thenReturn(persistentQueryType);
    when(query.getPhysicalPlan()).thenReturn(physicalPlan);
    when(queryBuilder.buildPersistentQueryInSharedRuntime(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(newQuery);
    when(queryBuilder.buildPersistentQueryInDedicatedRuntime(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(query);
    when(config.getConfig(true)).thenReturn(ksqlConfig);
    return registry.createOrReplacePersistentQuery(config, serviceContext, logContext, metaStore, "sql", queryId, Optional.of(sinkSource), ImmutableSet.of(toSource(source)), mock(ExecutionStep.class), "plan-summary", persistentQueryType, sharedRuntimes ? Optional.of("applicationId") : Optional.empty());
}
Also used : ExecutionStep(io.confluent.ksql.execution.plan.ExecutionStep) Field(java.lang.reflect.Field) SharedKafkaStreamsRuntime(io.confluent.ksql.util.SharedKafkaStreamsRuntime) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) DataSource(io.confluent.ksql.metastore.model.DataSource)

Example 2 with ExecutionStep

use of io.confluent.ksql.execution.plan.ExecutionStep in project ksql by confluentinc.

the class PlanSummary method summarize.

private StepSummary summarize(final ExecutionStep<?> step, final String indent) {
    final StringBuilder stringBuilder = new StringBuilder();
    final List<StepSummary> sourceSummaries = step.getSources().stream().map(s -> summarize(s, indent + "\t")).collect(Collectors.toList());
    final String opName = OP_NAME.get(step.getClass());
    if (opName == null) {
        throw new UnsupportedOperationException("Unsupported step type: " + step.getClass() + ", please add a step type");
    }
    final LogicalSchema schema = getSchema(step, sourceSummaries);
    stringBuilder.append(indent).append(" > [ ").append(opName).append(" ] | Schema: ").append(schema.toString(FORMAT_OPTIONS)).append(" | Logger: ").append(QueryLoggerUtil.queryLoggerName(queryId, step.getProperties().getQueryContext())).append("\n");
    for (final StepSummary sourceSummary : sourceSummaries) {
        stringBuilder.append("\t").append(indent).append(sourceSummary.summary);
    }
    return new StepSummary(schema, stringBuilder.toString());
}
Also used : FormatOptions(io.confluent.ksql.schema.utils.FormatOptions) StreamWindowedAggregate(io.confluent.ksql.execution.plan.StreamWindowedAggregate) TableSuppress(io.confluent.ksql.execution.plan.TableSuppress) StreamFilter(io.confluent.ksql.execution.plan.StreamFilter) StreamGroupByKey(io.confluent.ksql.execution.plan.StreamGroupByKey) TableTableJoin(io.confluent.ksql.execution.plan.TableTableJoin) StreamGroupByV1(io.confluent.ksql.execution.plan.StreamGroupByV1) StepSchemaResolver(io.confluent.ksql.execution.streams.StepSchemaResolver) StreamSelect(io.confluent.ksql.execution.plan.StreamSelect) SourceStep(io.confluent.ksql.execution.plan.SourceStep) TableSource(io.confluent.ksql.execution.plan.TableSource) TableGroupByV1(io.confluent.ksql.execution.plan.TableGroupByV1) Map(java.util.Map) MetaStore(io.confluent.ksql.metastore.MetaStore) QueryId(io.confluent.ksql.query.QueryId) TableGroupBy(io.confluent.ksql.execution.plan.TableGroupBy) StreamSelectKeyV1(io.confluent.ksql.execution.plan.StreamSelectKeyV1) StreamTableJoin(io.confluent.ksql.execution.plan.StreamTableJoin) TableSelect(io.confluent.ksql.execution.plan.TableSelect) ExecutionStep(io.confluent.ksql.execution.plan.ExecutionStep) ImmutableMap(com.google.common.collect.ImmutableMap) QueryLoggerUtil(io.confluent.ksql.execution.context.QueryLoggerUtil) TableAggregate(io.confluent.ksql.execution.plan.TableAggregate) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Collectors(java.util.stream.Collectors) StreamSource(io.confluent.ksql.execution.plan.StreamSource) ForeignKeyTableTableJoin(io.confluent.ksql.execution.plan.ForeignKeyTableTableJoin) Objects(java.util.Objects) TableFilter(io.confluent.ksql.execution.plan.TableFilter) List(java.util.List) WindowedStreamSource(io.confluent.ksql.execution.plan.WindowedStreamSource) StreamStreamJoin(io.confluent.ksql.execution.plan.StreamStreamJoin) TableSourceV1(io.confluent.ksql.execution.plan.TableSourceV1) WindowedTableSource(io.confluent.ksql.execution.plan.WindowedTableSource) StreamSink(io.confluent.ksql.execution.plan.StreamSink) StreamSelectKey(io.confluent.ksql.execution.plan.StreamSelectKey) TableSink(io.confluent.ksql.execution.plan.TableSink) VisibleForTesting(com.google.common.annotations.VisibleForTesting) StreamAggregate(io.confluent.ksql.execution.plan.StreamAggregate) StreamFlatMap(io.confluent.ksql.execution.plan.StreamFlatMap) StreamGroupBy(io.confluent.ksql.execution.plan.StreamGroupBy) TableSelectKey(io.confluent.ksql.execution.plan.TableSelectKey) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema)

Example 3 with ExecutionStep

use of io.confluent.ksql.execution.plan.ExecutionStep in project ksql by confluentinc.

the class SchemaKTableTest method buildSourceStep.

private ExecutionStep buildSourceStep(final LogicalSchema schema, final KTable kTable) {
    final ExecutionStep sourceStep = mock(ExecutionStep.class);
    when(sourceStep.build(any(), eq(planInfo))).thenReturn(KTableHolder.materialized(kTable, schema, executionKeyFactory, materializationBuilder));
    return sourceStep;
}
Also used : ExecutionStep(io.confluent.ksql.execution.plan.ExecutionStep)

Example 4 with ExecutionStep

use of io.confluent.ksql.execution.plan.ExecutionStep in project ksql by confluentinc.

the class SchemaKSourceFactory method buildTable.

private static SchemaKTable<?> buildTable(final PlanBuildContext buildContext, final DataSource dataSource, final Stacker contextStacker) {
    final KeyFormat keyFormat = dataSource.getKsqlTopic().getKeyFormat();
    if (keyFormat.isWindowed()) {
        throw new IllegalArgumentException("windowed");
    }
    final SourceStep<KTableHolder<GenericKey>> step;
    final int pseudoColumnVersionToUse = determinePseudoColumnVersionToUse(buildContext);
    // If the old query has a v1 table step, continue to use it.
    // See https://github.com/confluentinc/ksql/pull/7990
    boolean useOldExecutionStepVersion = false;
    if (buildContext.getPlanInfo().isPresent()) {
        final Set<ExecutionStep<?>> sourceSteps = buildContext.getPlanInfo().get().getSources();
        useOldExecutionStepVersion = sourceSteps.stream().anyMatch(executionStep -> executionStep instanceof TableSourceV1);
    }
    if (useOldExecutionStepVersion && pseudoColumnVersionToUse != SystemColumns.LEGACY_PSEUDOCOLUMN_VERSION_NUMBER) {
        throw new IllegalStateException("TableSourceV2 was released in conjunction with pseudocolumn" + "version 1. Something has gone very wrong");
    }
    if (buildContext.getKsqlConfig().getBoolean(KsqlConfig.KSQL_ROWPARTITION_ROWOFFSET_ENABLED) && !useOldExecutionStepVersion) {
        step = ExecutionStepFactory.tableSource(contextStacker, dataSource.getSchema(), dataSource.getKafkaTopicName(), Formats.from(dataSource.getKsqlTopic()), dataSource.getTimestampColumn(), InternalFormats.of(keyFormat, Formats.from(dataSource.getKsqlTopic()).getValueFormat()), pseudoColumnVersionToUse);
    } else {
        step = ExecutionStepFactory.tableSourceV1(contextStacker, dataSource.getSchema(), dataSource.getKafkaTopicName(), Formats.from(dataSource.getKsqlTopic()), dataSource.getTimestampColumn(), pseudoColumnVersionToUse);
    }
    return schemaKTable(buildContext, resolveSchema(buildContext, step, dataSource), dataSource.getKsqlTopic().getKeyFormat(), step);
}
Also used : ExecutionStep(io.confluent.ksql.execution.plan.ExecutionStep) DataSource(io.confluent.ksql.metastore.model.DataSource) ExecutionStep(io.confluent.ksql.execution.plan.ExecutionStep) SystemColumns(io.confluent.ksql.schema.ksql.SystemColumns) PlanBuildContext(io.confluent.ksql.planner.plan.PlanBuildContext) KeyFormat(io.confluent.ksql.serde.KeyFormat) QueryContext(io.confluent.ksql.execution.context.QueryContext) Set(java.util.Set) KsqlConfig(io.confluent.ksql.util.KsqlConfig) Formats(io.confluent.ksql.execution.plan.Formats) InternalFormats(io.confluent.ksql.serde.InternalFormats) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) StreamSource(io.confluent.ksql.execution.plan.StreamSource) StepSchemaResolver(io.confluent.ksql.execution.streams.StepSchemaResolver) WindowInfo(io.confluent.ksql.serde.WindowInfo) KStreamHolder(io.confluent.ksql.execution.plan.KStreamHolder) KTableHolder(io.confluent.ksql.execution.plan.KTableHolder) SourceStep(io.confluent.ksql.execution.plan.SourceStep) WindowedStreamSource(io.confluent.ksql.execution.plan.WindowedStreamSource) TableSourceV1(io.confluent.ksql.execution.plan.TableSourceV1) Windowed(org.apache.kafka.streams.kstream.Windowed) Stacker(io.confluent.ksql.execution.context.QueryContext.Stacker) GenericKey(io.confluent.ksql.GenericKey) ExecutionStepFactory(io.confluent.ksql.execution.streams.ExecutionStepFactory) TableSourceV1(io.confluent.ksql.execution.plan.TableSourceV1) KTableHolder(io.confluent.ksql.execution.plan.KTableHolder) KeyFormat(io.confluent.ksql.serde.KeyFormat)

Aggregations

ExecutionStep (io.confluent.ksql.execution.plan.ExecutionStep)4 SourceStep (io.confluent.ksql.execution.plan.SourceStep)2 StreamSource (io.confluent.ksql.execution.plan.StreamSource)2 TableSourceV1 (io.confluent.ksql.execution.plan.TableSourceV1)2 WindowedStreamSource (io.confluent.ksql.execution.plan.WindowedStreamSource)2 StepSchemaResolver (io.confluent.ksql.execution.streams.StepSchemaResolver)2 DataSource (io.confluent.ksql.metastore.model.DataSource)2 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 GenericKey (io.confluent.ksql.GenericKey)1 QueryContext (io.confluent.ksql.execution.context.QueryContext)1 Stacker (io.confluent.ksql.execution.context.QueryContext.Stacker)1 QueryLoggerUtil (io.confluent.ksql.execution.context.QueryLoggerUtil)1 ForeignKeyTableTableJoin (io.confluent.ksql.execution.plan.ForeignKeyTableTableJoin)1 Formats (io.confluent.ksql.execution.plan.Formats)1 KStreamHolder (io.confluent.ksql.execution.plan.KStreamHolder)1 KTableHolder (io.confluent.ksql.execution.plan.KTableHolder)1 StreamAggregate (io.confluent.ksql.execution.plan.StreamAggregate)1 StreamFilter (io.confluent.ksql.execution.plan.StreamFilter)1