Search in sources :

Example 11 with GenericKey

use of io.confluent.ksql.GenericKey in project ksql by confluentinc.

the class StreamAggregateBuilderTest method givenSessionWindowedAggregate.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void givenSessionWindowedAggregate() {
    when(materializedFactory.<GenericKey, SessionStore<Bytes, byte[]>>create(any(), any(), any(), any())).thenReturn(sessionWindowMaterialized);
    when(groupedStream.windowedBy(any(SessionWindows.class))).thenReturn(sessionWindowedStream);
    when(sessionWindowedStream.aggregate(any(), any(), any(), any(Materialized.class))).thenReturn(windowed);
    when(windowed.transformValues(any(), any(Named.class))).thenReturn((KTable) windowedWithResults);
    when(windowedWithResults.transformValues(any(), any(Named.class))).thenReturn((KTable) windowedWithWindowBounds);
    windowedAggregate = new StreamWindowedAggregate(new ExecutionStepPropertiesV1(CTX), sourceStep, Formats.of(KEY_FORMAT, VALUE_FORMAT, SerdeFeatures.of(), SerdeFeatures.of()), NON_AGG_COLUMNS, FUNCTIONS, new SessionWindowExpression(Optional.empty(), new WindowTimeClause(WINDOW.getSeconds(), TimeUnit.SECONDS), Optional.of(retentionClause), Optional.of(gracePeriodClause)));
}
Also used : SessionStore(org.apache.kafka.streams.state.SessionStore) Named(org.apache.kafka.streams.kstream.Named) SessionWindows(org.apache.kafka.streams.kstream.SessionWindows) ExecutionStepPropertiesV1(io.confluent.ksql.execution.plan.ExecutionStepPropertiesV1) StreamWindowedAggregate(io.confluent.ksql.execution.plan.StreamWindowedAggregate) WindowTimeClause(io.confluent.ksql.execution.windows.WindowTimeClause) GenericKey(io.confluent.ksql.GenericKey) Materialized(org.apache.kafka.streams.kstream.Materialized) SessionWindowExpression(io.confluent.ksql.execution.windows.SessionWindowExpression)

Example 12 with GenericKey

use of io.confluent.ksql.GenericKey in project ksql by confluentinc.

the class StreamAggregateBuilderTest method assertCorrectMaterializationBuilder.

private void assertCorrectMaterializationBuilder(final KTableHolder<?> result, final boolean windowed) {
    assertThat(result.getMaterializationBuilder().isPresent(), is(true));
    final MaterializationInfo info = result.getMaterializationBuilder().get().build();
    assertThat(info.stateStoreName(), equalTo("agg-regate-Materialize"));
    assertThat(info.getSchema(), equalTo(OUTPUT_SCHEMA));
    assertThat(info.getStateStoreSchema(), equalTo(AGGREGATE_SCHEMA));
    assertThat(info.getTransforms(), hasSize(1 + (windowed ? 1 : 0)));
    final MapperInfo aggMapInfo = (MapperInfo) info.getTransforms().get(0);
    final KsqlTransformer<Object, GenericRow> mapper = aggMapInfo.getMapper(name -> null);
    // Given:
    final GenericKey key = mock(GenericKey.class);
    final GenericRow value = mock(GenericRow.class);
    // When:
    mapper.transform(key, value, ctx);
    // Then:
    verify(resultMapper).transform(key, value, ctx);
}
Also used : GenericRow(io.confluent.ksql.GenericRow) MaterializationInfo(io.confluent.ksql.execution.materialization.MaterializationInfo) MapperInfo(io.confluent.ksql.execution.materialization.MaterializationInfo.MapperInfo) GenericKey(io.confluent.ksql.GenericKey)

Example 13 with GenericKey

use of io.confluent.ksql.GenericKey in project ksql by confluentinc.

the class SourceBuilderV1Test method shouldApplyCorrectTransformationsToSourceTableWithDownstreamRepartition.

@Test
@SuppressWarnings("unchecked")
public void shouldApplyCorrectTransformationsToSourceTableWithDownstreamRepartition() {
    // Given:
    givenUnwindowedSourceTableV1(true, LEGACY_PSEUDOCOLUMN_VERSION_NUMBER);
    final PlanInfo planInfo = givenDownstreamRepartition(tableSourceV1);
    // When:
    final KTableHolder<GenericKey> builtKTable = tableSourceV1.build(planBuilder, planInfo);
    // Then:
    assertThat(builtKTable.getTable(), is(kTable));
    final InOrder validator = inOrder(streamsBuilder, kTable);
    validator.verify(streamsBuilder).table(eq(TOPIC_NAME), eq(consumed));
    validator.verify(kTable).transformValues(any(ValueTransformerWithKeySupplier.class));
    verify(consumedFactory).create(keySerde, valueSerde);
    verify(consumed).withTimestampExtractor(any());
    verify(consumed).withOffsetResetPolicy(AutoOffsetReset.EARLIEST);
    verify(kTable, never()).mapValues(any(ValueMapper.class), any(Materialized.class));
}
Also used : PlanInfo(io.confluent.ksql.execution.plan.PlanInfo) InOrder(org.mockito.InOrder) ValueMapper(org.apache.kafka.streams.kstream.ValueMapper) GenericKey(io.confluent.ksql.GenericKey) Materialized(org.apache.kafka.streams.kstream.Materialized) ValueTransformerWithKeySupplier(org.apache.kafka.streams.kstream.ValueTransformerWithKeySupplier) Test(org.junit.Test)

Example 14 with GenericKey

use of io.confluent.ksql.GenericKey in project ksql by confluentinc.

the class SourceBuilderV1Test method shouldHandleMultiKeyFieldWithNullColLegacy.

@Test
public void shouldHandleMultiKeyFieldWithNullColLegacy() {
    // Given:
    givenMultiColumnSourceStream(LEGACY_PSEUDOCOLUMN_VERSION_NUMBER);
    final ValueTransformerWithKey<GenericKey, GenericRow, GenericRow> transformer = getTransformerFromStreamSource(streamSource);
    final GenericKey key = GenericKey.genericKey(null, 2d);
    // When:
    final GenericRow withTimestamp = transformer.transform(key, row);
    // Then:
    assertThat(withTimestamp, equalTo(GenericRow.genericRow("baz", 123, HEADER_A, HEADER_B, null, A_ROWTIME, null, 2d)));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) GenericKey(io.confluent.ksql.GenericKey) Test(org.junit.Test)

Example 15 with GenericKey

use of io.confluent.ksql.GenericKey in project ksql by confluentinc.

the class SourceBuilderV1Test method shouldHandleMultiKeyFieldLegacy.

@Test
public void shouldHandleMultiKeyFieldLegacy() {
    // Given:
    givenMultiColumnSourceStream(LEGACY_PSEUDOCOLUMN_VERSION_NUMBER);
    final ValueTransformerWithKey<GenericKey, GenericRow, GenericRow> transformer = getTransformerFromStreamSource(streamSource);
    final GenericKey key = GenericKey.genericKey(1d, 2d);
    // When:
    final GenericRow withTimestamp = transformer.transform(key, row);
    // Then:
    assertThat(withTimestamp, equalTo(GenericRow.genericRow("baz", 123, HEADER_A, HEADER_B, null, A_ROWTIME, 1d, 2d)));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) GenericKey(io.confluent.ksql.GenericKey) Test(org.junit.Test)

Aggregations

GenericKey (io.confluent.ksql.GenericKey)147 GenericRow (io.confluent.ksql.GenericRow)100 Test (org.junit.Test)93 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)24 Windowed (org.apache.kafka.streams.kstream.Windowed)20 WindowedRow (io.confluent.ksql.execution.streams.materialization.WindowedRow)14 PhysicalSchema (io.confluent.ksql.schema.ksql.PhysicalSchema)14 Materialized (org.apache.kafka.streams.kstream.Materialized)13 ValueAndTimestamp (org.apache.kafka.streams.state.ValueAndTimestamp)13 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)12 MaterializationException (io.confluent.ksql.execution.streams.materialization.MaterializationException)9 IntegrationTest (io.confluent.common.utils.IntegrationTest)8 Materialization (io.confluent.ksql.execution.streams.materialization.Materialization)8 Row (io.confluent.ksql.execution.streams.materialization.Row)8 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)8 TimeWindow (org.apache.kafka.streams.kstream.internals.TimeWindow)8 IntegrationTest (org.apache.kafka.test.IntegrationTest)8 InOrder (org.mockito.InOrder)8 MaterializedTable (io.confluent.ksql.execution.streams.materialization.MaterializedTable)7 Objects (java.util.Objects)7