Search in sources :

Example 6 with KGroupedStreamHolder

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

the class StreamGroupByBuilderV1Test method shouldPerformGroupByCorrectly.

@Test
public void shouldPerformGroupByCorrectly() {
    // When:
    final KGroupedStreamHolder result = buildGroupBy(builder, streamHolder, groupBy);
    // Then:
    assertThat(result.getGroupedStream(), is(groupedStream));
    verify(sourceStream).filter(any());
    verify(filteredStream).groupBy(any(), same(grouped));
    verifyNoMoreInteractions(filteredStream, sourceStream);
}
Also used : KGroupedStreamHolder(io.confluent.ksql.execution.plan.KGroupedStreamHolder) Test(org.junit.Test)

Example 7 with KGroupedStreamHolder

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

the class StreamGroupByBuilderV1Test method shouldPerformGroupByKeyCorrectly.

@Test
public void shouldPerformGroupByKeyCorrectly() {
    // When:
    final KGroupedStreamHolder result = builder.build(streamHolder, groupByKey);
    // Then:
    assertThat(result.getGroupedStream(), is(groupedStream));
    verify(sourceStream).groupByKey(grouped);
    verifyNoMoreInteractions(sourceStream);
}
Also used : KGroupedStreamHolder(io.confluent.ksql.execution.plan.KGroupedStreamHolder) Test(org.junit.Test)

Example 8 with KGroupedStreamHolder

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

the class StreamGroupByBuilderV1Test method shouldReturnCorrectSchemaForGroupBy.

@Test
public void shouldReturnCorrectSchemaForGroupBy() {
    // When:
    final KGroupedStreamHolder result = buildGroupBy(builder, streamHolder, groupBy);
    // Then:
    assertThat(result.getSchema(), is(REKEYED_SCHEMA));
}
Also used : KGroupedStreamHolder(io.confluent.ksql.execution.plan.KGroupedStreamHolder) Test(org.junit.Test)

Example 9 with KGroupedStreamHolder

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

the class StreamGroupByBuilderBase method build.

public <K> KGroupedStreamHolder build(final KStreamHolder<K> stream, final QueryContext queryContext, final Formats formats, final List<Expression> groupByExpressions) {
    final LogicalSchema sourceSchema = stream.getSchema();
    final List<CompiledExpression> groupBy = CodeGenRunner.compileExpressions(groupByExpressions.stream(), "Group By", sourceSchema, buildContext.getKsqlConfig(), buildContext.getFunctionRegistry());
    final ProcessingLogger logger = buildContext.getProcessingLogger(queryContext);
    final GroupByParams params = paramsFactory.build(sourceSchema, groupBy, logger);
    final Grouped<GenericKey, GenericRow> grouped = buildGrouped(formats, params.getSchema(), queryContext, buildContext, groupedFactory);
    final KGroupedStream<GenericKey, GenericRow> groupedStream = stream.getStream().filter((k, v) -> v != null).groupBy((k, v) -> params.getMapper().apply(v), grouped);
    return KGroupedStreamHolder.of(groupedStream, params.getSchema());
}
Also used : GenericRow(io.confluent.ksql.GenericRow) PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema) RuntimeBuildContext(io.confluent.ksql.execution.runtime.RuntimeBuildContext) KGroupedStream(org.apache.kafka.streams.kstream.KGroupedStream) Expression(io.confluent.ksql.execution.expression.tree.Expression) QueryContext(io.confluent.ksql.execution.context.QueryContext) CompiledExpression(io.confluent.ksql.execution.codegen.CompiledExpression) Formats(io.confluent.ksql.execution.plan.Formats) StreamGroupByKey(io.confluent.ksql.execution.plan.StreamGroupByKey) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) CodeGenRunner(io.confluent.ksql.execution.codegen.CodeGenRunner) Grouped(org.apache.kafka.streams.kstream.Grouped) KGroupedStreamHolder(io.confluent.ksql.execution.plan.KGroupedStreamHolder) KStreamHolder(io.confluent.ksql.execution.plan.KStreamHolder) List(java.util.List) GenericRow(io.confluent.ksql.GenericRow) Serde(org.apache.kafka.common.serialization.Serde) Objects.requireNonNull(java.util.Objects.requireNonNull) ProcessingLogger(io.confluent.ksql.logging.processing.ProcessingLogger) GenericKey(io.confluent.ksql.GenericKey) ProcessingLogger(io.confluent.ksql.logging.processing.ProcessingLogger) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) GenericKey(io.confluent.ksql.GenericKey) CompiledExpression(io.confluent.ksql.execution.codegen.CompiledExpression)

Aggregations

KGroupedStreamHolder (io.confluent.ksql.execution.plan.KGroupedStreamHolder)9 Test (org.junit.Test)8 GenericKey (io.confluent.ksql.GenericKey)1 GenericRow (io.confluent.ksql.GenericRow)1 CodeGenRunner (io.confluent.ksql.execution.codegen.CodeGenRunner)1 CompiledExpression (io.confluent.ksql.execution.codegen.CompiledExpression)1 QueryContext (io.confluent.ksql.execution.context.QueryContext)1 Expression (io.confluent.ksql.execution.expression.tree.Expression)1 Formats (io.confluent.ksql.execution.plan.Formats)1 KStreamHolder (io.confluent.ksql.execution.plan.KStreamHolder)1 StreamGroupByKey (io.confluent.ksql.execution.plan.StreamGroupByKey)1 RuntimeBuildContext (io.confluent.ksql.execution.runtime.RuntimeBuildContext)1 ProcessingLogger (io.confluent.ksql.logging.processing.ProcessingLogger)1 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)1 PhysicalSchema (io.confluent.ksql.schema.ksql.PhysicalSchema)1 List (java.util.List)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Serde (org.apache.kafka.common.serialization.Serde)1 Grouped (org.apache.kafka.streams.kstream.Grouped)1 KGroupedStream (org.apache.kafka.streams.kstream.KGroupedStream)1