Search in sources :

Example 1 with WindowInfo

use of io.confluent.ksql.serde.WindowInfo in project ksql by confluentinc.

the class LogicalPlanner method getWindowInfo.

private Optional<WindowInfo> getWindowInfo() {
    final KsqlTopic srcTopic = analysis.getFrom().getDataSource().getKsqlTopic();
    final Optional<WindowInfo> explicitWindowInfo = analysis.getWindowExpression().map(WindowExpression::getKsqlWindowExpression).map(KsqlWindowExpression::getWindowInfo);
    return explicitWindowInfo.isPresent() ? explicitWindowInfo : srcTopic.getKeyFormat().getWindowInfo();
}
Also used : KsqlWindowExpression(io.confluent.ksql.execution.windows.KsqlWindowExpression) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) WindowInfo(io.confluent.ksql.serde.WindowInfo)

Example 2 with WindowInfo

use of io.confluent.ksql.serde.WindowInfo in project ksql by confluentinc.

the class SchemaKSourceFactory method buildWindowedStream.

private static SchemaKStream<?> buildWindowedStream(final PlanBuildContext buildContext, final DataSource dataSource, final Stacker contextStacker) {
    final WindowInfo windowInfo = dataSource.getKsqlTopic().getKeyFormat().getWindowInfo().orElseThrow(IllegalArgumentException::new);
    final int pseudoColumnVersionToUse = determinePseudoColumnVersionToUse(buildContext);
    final WindowedStreamSource step = ExecutionStepFactory.streamSourceWindowed(contextStacker, dataSource.getSchema(), dataSource.getKafkaTopicName(), Formats.from(dataSource.getKsqlTopic()), windowInfo, dataSource.getTimestampColumn(), pseudoColumnVersionToUse);
    return schemaKStream(buildContext, resolveSchema(buildContext, step, dataSource), dataSource.getKsqlTopic().getKeyFormat(), step);
}
Also used : WindowedStreamSource(io.confluent.ksql.execution.plan.WindowedStreamSource) WindowInfo(io.confluent.ksql.serde.WindowInfo)

Example 3 with WindowInfo

use of io.confluent.ksql.serde.WindowInfo in project ksql by confluentinc.

the class SourceBuilderV1 method buildWindowedTable.

KTableHolder<Windowed<GenericKey>> buildWindowedTable(final RuntimeBuildContext buildContext, final SourceStep<KTableHolder<Windowed<GenericKey>>> source, final ConsumedFactory consumedFactory, final MaterializedFactory materializedFactory, final PlanInfo planInfo) {
    final PhysicalSchema physicalSchema = getPhysicalSchema(source);
    final Serde<GenericRow> valueSerde = getValueSerde(buildContext, source, physicalSchema);
    final WindowInfo windowInfo;
    if (source instanceof WindowedTableSource) {
        windowInfo = ((WindowedTableSource) source).getWindowInfo();
    } else {
        throw new IllegalArgumentException("Expected a version of WindowedTableSource");
    }
    final Serde<Windowed<GenericKey>> keySerde = SourceBuilderUtils.getWindowedKeySerde(source, physicalSchema, buildContext, windowInfo);
    final Consumed<Windowed<GenericKey>, GenericRow> consumed = buildSourceConsumed(source, keySerde, valueSerde, AutoOffsetReset.EARLIEST, buildContext, consumedFactory);
    final String stateStoreName = tableChangeLogOpName(source.getProperties());
    final Materialized<Windowed<GenericKey>, GenericRow, KeyValueStore<Bytes, byte[]>> materialized = materializedFactory.create(keySerde, valueSerde, stateStoreName);
    final KTable<Windowed<GenericKey>, GenericRow> ktable = buildKTable(source, buildContext, consumed, windowedKeyGenerator(source.getSourceSchema()), materialized, valueSerde, stateStoreName, planInfo);
    return KTableHolder.materialized(ktable, buildSchema(source, true), ExecutionKeyFactory.windowed(buildContext, windowInfo), MaterializationInfo.builder(stateStoreName, physicalSchema.logicalSchema()));
}
Also used : KeyValueStore(org.apache.kafka.streams.state.KeyValueStore) WindowInfo(io.confluent.ksql.serde.WindowInfo) GenericRow(io.confluent.ksql.GenericRow) Windowed(org.apache.kafka.streams.kstream.Windowed) PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema) SourceBuilderUtils.getPhysicalSchema(io.confluent.ksql.execution.streams.SourceBuilderUtils.getPhysicalSchema) WindowedTableSource(io.confluent.ksql.execution.plan.WindowedTableSource)

Example 4 with WindowInfo

use of io.confluent.ksql.serde.WindowInfo in project ksql by confluentinc.

the class SourceBuilderV1 method buildWindowedStream.

public KStreamHolder<Windowed<GenericKey>> buildWindowedStream(final RuntimeBuildContext buildContext, final WindowedStreamSource source, final ConsumedFactory consumedFactory) {
    final PhysicalSchema physicalSchema = getPhysicalSchema(source);
    final Serde<GenericRow> valueSerde = getValueSerde(buildContext, source, physicalSchema);
    final WindowInfo windowInfo = source.getWindowInfo();
    final Serde<Windowed<GenericKey>> keySerde = getWindowedKeySerde(source, physicalSchema, buildContext, windowInfo);
    final Consumed<Windowed<GenericKey>, GenericRow> consumed = buildSourceConsumed(source, keySerde, valueSerde, AutoOffsetReset.LATEST, buildContext, consumedFactory);
    final KStream<Windowed<GenericKey>, GenericRow> kstream = buildKStream(source, buildContext, consumed, windowedKeyGenerator(source.getSourceSchema()));
    return new KStreamHolder<>(kstream, buildSchema(source, true), ExecutionKeyFactory.windowed(buildContext, windowInfo));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) Windowed(org.apache.kafka.streams.kstream.Windowed) KStreamHolder(io.confluent.ksql.execution.plan.KStreamHolder) PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema) SourceBuilderUtils.getPhysicalSchema(io.confluent.ksql.execution.streams.SourceBuilderUtils.getPhysicalSchema) WindowInfo(io.confluent.ksql.serde.WindowInfo)

Example 5 with WindowInfo

use of io.confluent.ksql.serde.WindowInfo in project ksql by confluentinc.

the class SchemaKStream method throwOnJoinKeyFormatsMismatch.

void throwOnJoinKeyFormatsMismatch(final SchemaKStream<?> right) {
    final FormatInfo leftFmt = this.keyFormat.getFormatInfo();
    final FormatInfo rightFmt = right.keyFormat.getFormatInfo();
    if (!leftFmt.equals(rightFmt)) {
        throw new IllegalArgumentException("Key format mismatch in join. " + "left: " + leftFmt + ", right: " + rightFmt);
    }
    final SerdeFeatures leftFeats = this.keyFormat.getFeatures();
    final SerdeFeatures rightFeats = right.keyFormat.getFeatures();
    if (!leftFeats.equals(rightFeats)) {
        throw new IllegalArgumentException("Key format features mismatch in join. " + "left: " + leftFeats + ", right: " + rightFeats);
    }
    final Optional<WindowType> leftWnd = this.keyFormat.getWindowInfo().map(WindowInfo::getType);
    final Optional<WindowType> rightWnd = right.keyFormat.getWindowInfo().map(WindowInfo::getType);
    if (leftWnd.isPresent() != rightWnd.isPresent()) {
        throw new IllegalArgumentException("Key format windowing mismatch in join. " + "left: " + leftWnd + ", right: " + rightWnd);
    }
    final boolean leftIsSession = leftWnd.map(type -> type == WindowType.SESSION).orElse(false);
    final boolean rightIsSession = rightWnd.map(type -> type == WindowType.SESSION).orElse(false);
    if (leftIsSession != rightIsSession) {
        throw new IllegalArgumentException("Key format window type mismatch in join. " + "left: " + (leftIsSession ? "Session Windowed" : "Non Session Windowed") + ", right: " + (rightIsSession ? "Session Windowed" : "Non Session Windowed"));
    }
}
Also used : StatementRewriteForMagicPseudoTimestamp(io.confluent.ksql.engine.rewrite.StatementRewriteForMagicPseudoTimestamp) ColumnName(io.confluent.ksql.name.ColumnName) WithinExpression(io.confluent.ksql.parser.tree.WithinExpression) StreamFilter(io.confluent.ksql.execution.plan.StreamFilter) KeyFormat(io.confluent.ksql.serde.KeyFormat) QueryContext(io.confluent.ksql.execution.context.QueryContext) JoinType(io.confluent.ksql.execution.plan.JoinType) SerdeFeaturesFactory(io.confluent.ksql.serde.SerdeFeaturesFactory) Formats(io.confluent.ksql.execution.plan.Formats) StreamGroupByKey(io.confluent.ksql.execution.plan.StreamGroupByKey) StepSchemaResolver(io.confluent.ksql.execution.streams.StepSchemaResolver) WindowInfo(io.confluent.ksql.serde.WindowInfo) NoneFormat(io.confluent.ksql.serde.none.NoneFormat) StreamSelect(io.confluent.ksql.execution.plan.StreamSelect) Objects.requireNonNull(java.util.Objects.requireNonNull) ExpressionTypeManager(io.confluent.ksql.execution.util.ExpressionTypeManager) WindowType(io.confluent.ksql.model.WindowType) Repartitioning(io.confluent.ksql.util.Repartitioning) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures) ExecutionStepFactory(io.confluent.ksql.execution.streams.ExecutionStepFactory) StreamTableJoin(io.confluent.ksql.execution.plan.StreamTableJoin) ExecutionStep(io.confluent.ksql.execution.plan.ExecutionStep) PlanBuildContext(io.confluent.ksql.planner.plan.PlanBuildContext) Expression(io.confluent.ksql.execution.expression.tree.Expression) FunctionRegistry(io.confluent.ksql.function.FunctionRegistry) KsqlConfig(io.confluent.ksql.util.KsqlConfig) InternalFormats(io.confluent.ksql.serde.InternalFormats) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Collectors(java.util.stream.Collectors) TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) SelectExpression(io.confluent.ksql.execution.plan.SelectExpression) KStreamHolder(io.confluent.ksql.execution.plan.KStreamHolder) Objects(java.util.Objects) FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) List(java.util.List) StreamStreamJoin(io.confluent.ksql.execution.plan.StreamStreamJoin) StreamSink(io.confluent.ksql.execution.plan.StreamSink) Stacker(io.confluent.ksql.execution.context.QueryContext.Stacker) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) KsqlException(io.confluent.ksql.util.KsqlException) Optional(java.util.Optional) StreamFlatMap(io.confluent.ksql.execution.plan.StreamFlatMap) FormatInfo(io.confluent.ksql.serde.FormatInfo) StreamGroupBy(io.confluent.ksql.execution.plan.StreamGroupBy) FormatInfo(io.confluent.ksql.serde.FormatInfo) WindowType(io.confluent.ksql.model.WindowType) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures) WindowInfo(io.confluent.ksql.serde.WindowInfo)

Aggregations

WindowInfo (io.confluent.ksql.serde.WindowInfo)7 GenericRow (io.confluent.ksql.GenericRow)2 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)2 KStreamHolder (io.confluent.ksql.execution.plan.KStreamHolder)2 SourceBuilderUtils.getPhysicalSchema (io.confluent.ksql.execution.streams.SourceBuilderUtils.getPhysicalSchema)2 WindowType (io.confluent.ksql.model.WindowType)2 PhysicalSchema (io.confluent.ksql.schema.ksql.PhysicalSchema)2 GenericKey (io.confluent.ksql.GenericKey)1 StatementRewriteForMagicPseudoTimestamp (io.confluent.ksql.engine.rewrite.StatementRewriteForMagicPseudoTimestamp)1 QueryContext (io.confluent.ksql.execution.context.QueryContext)1 Stacker (io.confluent.ksql.execution.context.QueryContext.Stacker)1 Expression (io.confluent.ksql.execution.expression.tree.Expression)1 FunctionCall (io.confluent.ksql.execution.expression.tree.FunctionCall)1 ExecutionStep (io.confluent.ksql.execution.plan.ExecutionStep)1 Formats (io.confluent.ksql.execution.plan.Formats)1 JoinType (io.confluent.ksql.execution.plan.JoinType)1 KTableHolder (io.confluent.ksql.execution.plan.KTableHolder)1 SelectExpression (io.confluent.ksql.execution.plan.SelectExpression)1 StreamFilter (io.confluent.ksql.execution.plan.StreamFilter)1 StreamFlatMap (io.confluent.ksql.execution.plan.StreamFlatMap)1