Search in sources :

Example 16 with GenericKey

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

the class SourceBuilderV1Test method shouldApplyCorrectTransformationsToSourceTable.

@Test
@SuppressWarnings("unchecked")
public void shouldApplyCorrectTransformationsToSourceTable() {
    // Given:
    givenUnwindowedSourceTableV1(true, LEGACY_PSEUDOCOLUMN_VERSION_NUMBER);
    // 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).mapValues(any(ValueMapper.class), any(Materialized.class));
    validator.verify(kTable).transformValues(any(ValueTransformerWithKeySupplier.class));
    verify(consumedFactory).create(keySerde, valueSerde);
    verify(consumed).withTimestampExtractor(any());
    verify(consumed).withOffsetResetPolicy(AutoOffsetReset.EARLIEST);
}
Also used : 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 17 with GenericKey

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

the class SourceBuilderV1Test method shouldHandleNullKey.

@Test
public void shouldHandleNullKey() {
    // Given:
    givenUnwindowedSourceStream();
    final ValueTransformerWithKey<GenericKey, GenericRow, GenericRow> transformer = getTransformerFromStreamSource(streamSource);
    final GenericKey nullKey = null;
    // When:
    final GenericRow withTimestamp = transformer.transform(nullKey, row);
    // Then:
    assertThat(withTimestamp, equalTo(GenericRow.genericRow("baz", 123, HEADER_DATA, A_ROWTIME, A_ROWPARTITION, A_ROWOFFSET, null)));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) GenericKey(io.confluent.ksql.GenericKey) Test(org.junit.Test)

Example 18 with GenericKey

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

the class SourceBuilderV1Test method shouldAddRowTimeAndTimeWindowedRowKeyColumnsToLegacyTable.

@Test
public void shouldAddRowTimeAndTimeWindowedRowKeyColumnsToLegacyTable() {
    // Given:
    givenWindowedSourceTable(LEGACY_PSEUDOCOLUMN_VERSION_NUMBER);
    final ValueTransformerWithKey<Windowed<GenericKey>, GenericRow, GenericRow> transformer = getTransformerFromTableSource(windowedTableSource);
    final Windowed<GenericKey> key = new Windowed<>(KEY, new TimeWindow(A_WINDOW_START, A_WINDOW_END));
    // When:
    final GenericRow withTimestamp = transformer.transform(key, row);
    // Then:
    assertThat(withTimestamp, is(GenericRow.genericRow("baz", 123, HEADER_DATA, A_ROWTIME, A_KEY, A_WINDOW_START, A_WINDOW_END)));
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) GenericRow(io.confluent.ksql.GenericRow) GenericKey(io.confluent.ksql.GenericKey) TimeWindow(org.apache.kafka.streams.kstream.internals.TimeWindow) Test(org.junit.Test)

Example 19 with GenericKey

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

the class SourceBuilderV1Test method shouldAddPseudoColumnsAndSessionWindowedRowKeyColumnsToStream.

@Test
public void shouldAddPseudoColumnsAndSessionWindowedRowKeyColumnsToStream() {
    // Given:
    givenWindowedSourceStream();
    final ValueTransformerWithKey<Windowed<GenericKey>, GenericRow, GenericRow> transformer = getTransformerFromStreamSource(windowedStreamSource);
    final Windowed<GenericKey> key = new Windowed<>(KEY, new SessionWindow(A_WINDOW_START, A_WINDOW_END));
    // When:
    final GenericRow withTimestamp = transformer.transform(key, row);
    // Then:
    assertThat(withTimestamp, equalTo(GenericRow.genericRow("baz", 123, HEADER_DATA, A_ROWTIME, A_ROWPARTITION, A_ROWOFFSET, A_KEY, A_WINDOW_START, A_WINDOW_END)));
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) GenericRow(io.confluent.ksql.GenericRow) GenericKey(io.confluent.ksql.GenericKey) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) Test(org.junit.Test)

Example 20 with GenericKey

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

the class SourceBuilderV1Test method shouldHandleEmptyKey.

@Test
public void shouldHandleEmptyKey() {
    // Given:
    givenUnwindowedSourceStream();
    final ValueTransformerWithKey<GenericKey, GenericRow, GenericRow> transformer = getTransformerFromStreamSource(streamSource);
    final GenericKey nullKey = GenericKey.genericKey((Object) null);
    // When:
    final GenericRow withTimestamp = transformer.transform(nullKey, row);
    // Then:
    assertThat(withTimestamp, equalTo(GenericRow.genericRow("baz", 123, HEADER_DATA, A_ROWTIME, A_ROWPARTITION, A_ROWOFFSET, null)));
}
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