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