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