Search in sources :

Example 6 with KsqlWindowExpression

use of io.confluent.ksql.execution.windows.KsqlWindowExpression in project ksql by confluentinc.

the class ExpressionParserTest method shouldParseWindowExpression.

@Test
public void shouldParseWindowExpression() {
    // When:
    final KsqlWindowExpression parsed = ExpressionParser.parseWindowExpression("TUMBLING (SIZE 1 DAYS)");
    // Then:
    assertThat(parsed, equalTo(new TumblingWindowExpression(parsed.getLocation(), new WindowTimeClause(1, TimeUnit.DAYS), Optional.empty(), Optional.empty())));
}
Also used : KsqlWindowExpression(io.confluent.ksql.execution.windows.KsqlWindowExpression) WindowTimeClause(io.confluent.ksql.execution.windows.WindowTimeClause) TumblingWindowExpression(io.confluent.ksql.execution.windows.TumblingWindowExpression) Test(org.junit.Test)

Example 7 with KsqlWindowExpression

use of io.confluent.ksql.execution.windows.KsqlWindowExpression in project ksql by confluentinc.

the class StreamAggregateBuilder method build.

@SuppressWarnings({ "rawtypes", "unchecked" })
static KTableHolder<Windowed<GenericKey>> build(final KGroupedStreamHolder groupedStream, final StreamWindowedAggregate aggregate, final RuntimeBuildContext buildContext, final MaterializedFactory materializedFactory, final AggregateParamsFactory aggregateParamsFactory) {
    final LogicalSchema sourceSchema = groupedStream.getSchema();
    final List<ColumnName> nonFuncColumns = aggregate.getNonAggregateColumns();
    final AggregateParams aggregateParams = aggregateParamsFactory.create(sourceSchema, nonFuncColumns, buildContext.getFunctionRegistry(), aggregate.getAggregationFunctions(), true, buildContext.getKsqlConfig());
    final LogicalSchema aggregateSchema = aggregateParams.getAggregateSchema();
    final LogicalSchema resultSchema = aggregateParams.getSchema();
    final KsqlWindowExpression ksqlWindowExpression = aggregate.getWindowExpression();
    final KTable<Windowed<GenericKey>, GenericRow> aggregated = ksqlWindowExpression.accept(new WindowedAggregator(groupedStream.getGroupedStream(), aggregate, aggregateSchema, buildContext, materializedFactory, aggregateParams), null);
    final KudafAggregator<Windowed<GenericKey>> aggregator = aggregateParams.getAggregator();
    KTable<Windowed<GenericKey>, GenericRow> reduced = aggregated.transformValues(() -> new KsTransformer<>(aggregator.getResultMapper()), Named.as(StreamsUtil.buildOpName(AggregateBuilderUtils.outputContext(aggregate))));
    final MaterializationInfo.Builder materializationBuilder = AggregateBuilderUtils.materializationInfoBuilder(aggregateParams.getAggregator(), aggregate, aggregateSchema, resultSchema);
    reduced = reduced.transformValues(() -> new KsTransformer<>(new WindowBoundsPopulator()), Named.as(StreamsUtil.buildOpName(AggregateBuilderUtils.windowSelectContext(aggregate))));
    materializationBuilder.map(pl -> (KsqlTransformer) new WindowBoundsPopulator(), resultSchema, AggregateBuilderUtils.windowSelectContext(aggregate));
    return KTableHolder.materialized(reduced, resultSchema, ExecutionKeyFactory.windowed(buildContext, ksqlWindowExpression.getWindowInfo()), materializationBuilder);
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Windowed(org.apache.kafka.streams.kstream.Windowed) GenericRow(io.confluent.ksql.GenericRow) ColumnName(io.confluent.ksql.name.ColumnName) MaterializationInfo(io.confluent.ksql.execution.materialization.MaterializationInfo) KsqlWindowExpression(io.confluent.ksql.execution.windows.KsqlWindowExpression) KsTransformer(io.confluent.ksql.execution.streams.transform.KsTransformer)

Aggregations

KsqlWindowExpression (io.confluent.ksql.execution.windows.KsqlWindowExpression)7 TumblingWindowExpression (io.confluent.ksql.execution.windows.TumblingWindowExpression)3 WindowTimeClause (io.confluent.ksql.execution.windows.WindowTimeClause)3 WindowExpression (io.confluent.ksql.parser.tree.WindowExpression)3 Test (org.junit.Test)3 GenericRow (io.confluent.ksql.GenericRow)1 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)1 MaterializationInfo (io.confluent.ksql.execution.materialization.MaterializationInfo)1 KsTransformer (io.confluent.ksql.execution.streams.transform.KsTransformer)1 HoppingWindowExpression (io.confluent.ksql.execution.windows.HoppingWindowExpression)1 SessionWindowExpression (io.confluent.ksql.execution.windows.SessionWindowExpression)1 ColumnName (io.confluent.ksql.name.ColumnName)1 NodeLocation (io.confluent.ksql.parser.NodeLocation)1 AstNode (io.confluent.ksql.parser.tree.AstNode)1 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)1 RefinementInfo (io.confluent.ksql.serde.RefinementInfo)1 WindowInfo (io.confluent.ksql.serde.WindowInfo)1 KsqlException (io.confluent.ksql.util.KsqlException)1 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)1 Windowed (org.apache.kafka.streams.kstream.Windowed)1