Search in sources :

Example 1 with KGroupedTableHolder

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

the class TableGroupByBuilderBase method build.

public <K> KGroupedTableHolder build(final KTableHolder<K> table, final QueryContext queryContext, final Formats formats, final List<Expression> groupByExpressions) {
    final LogicalSchema sourceSchema = table.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 PhysicalSchema physicalSchema = PhysicalSchema.from(params.getSchema(), formats.getKeyFeatures(), formats.getValueFeatures());
    final Serde<GenericKey> keySerde = buildContext.buildKeySerde(formats.getKeyFormat(), physicalSchema, queryContext);
    final Serde<GenericRow> valSerde = buildContext.buildValueSerde(formats.getValueFormat(), physicalSchema, queryContext);
    final Grouped<GenericKey, GenericRow> grouped = groupedFactory.create(StreamsUtil.buildOpName(queryContext), keySerde, valSerde);
    final KGroupedTable<GenericKey, GenericRow> groupedTable = table.getTable().filter((k, v) -> v != null).groupBy(new TableKeyValueMapper<>(params.getMapper()), grouped);
    return KGroupedTableHolder.of(groupedTable, params.getSchema());
}
Also used : PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema) KeyValueMapper(org.apache.kafka.streams.kstream.KeyValueMapper) RuntimeBuildContext(io.confluent.ksql.execution.runtime.RuntimeBuildContext) Expression(io.confluent.ksql.execution.expression.tree.Expression) QueryContext(io.confluent.ksql.execution.context.QueryContext) KeyValue(org.apache.kafka.streams.KeyValue) CompiledExpression(io.confluent.ksql.execution.codegen.CompiledExpression) Formats(io.confluent.ksql.execution.plan.Formats) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Function(java.util.function.Function) CodeGenRunner(io.confluent.ksql.execution.codegen.CodeGenRunner) Grouped(org.apache.kafka.streams.kstream.Grouped) KGroupedTableHolder(io.confluent.ksql.execution.plan.KGroupedTableHolder) KTableHolder(io.confluent.ksql.execution.plan.KTableHolder) List(java.util.List) KGroupedTable(org.apache.kafka.streams.kstream.KGroupedTable) 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) CompiledExpression(io.confluent.ksql.execution.codegen.CompiledExpression) GenericRow(io.confluent.ksql.GenericRow) PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema) GenericKey(io.confluent.ksql.GenericKey)

Example 2 with KGroupedTableHolder

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

the class TableGroupByBuilderV1Test method shouldPerformGroupByCorrectly.

@Test
public void shouldPerformGroupByCorrectly() {
    // When:
    final KGroupedTableHolder result = build(builder, tableHolder, groupBy);
    // Then:
    assertThat(result.getGroupedTable(), is(groupedTable));
    verify(sourceTable).filter(any());
    verify(filteredTable).groupBy(any(), same(grouped));
    verifyNoMoreInteractions(filteredTable, sourceTable);
}
Also used : KGroupedTableHolder(io.confluent.ksql.execution.plan.KGroupedTableHolder) Test(org.junit.Test)

Example 3 with KGroupedTableHolder

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

the class TableGroupByBuilderV1Test method shouldReturnCorrectSchema.

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

Example 4 with KGroupedTableHolder

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

the class TableGroupByBuilderTest method shouldReturnCorrectSchema.

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

Example 5 with KGroupedTableHolder

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

the class TableGroupByBuilderTest method shouldPerformGroupByCorrectly.

@Test
public void shouldPerformGroupByCorrectly() {
    // When:
    final KGroupedTableHolder result = build(builder, tableHolder, groupBy);
    // Then:
    assertThat(result.getGroupedTable(), is(groupedTable));
    verify(sourceTable).filter(any());
    verify(filteredTable).groupBy(any(), same(grouped));
    verifyNoMoreInteractions(filteredTable, sourceTable);
}
Also used : KGroupedTableHolder(io.confluent.ksql.execution.plan.KGroupedTableHolder) Test(org.junit.Test)

Aggregations

KGroupedTableHolder (io.confluent.ksql.execution.plan.KGroupedTableHolder)5 Test (org.junit.Test)4 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 KTableHolder (io.confluent.ksql.execution.plan.KTableHolder)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 Function (java.util.function.Function)1 Serde (org.apache.kafka.common.serialization.Serde)1 KeyValue (org.apache.kafka.streams.KeyValue)1 Grouped (org.apache.kafka.streams.kstream.Grouped)1