Search in sources :

Example 76 with GenericKey

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

the class TestDriverPipelineTest method shouldDetectLoops.

@Test
public void shouldDetectLoops() {
    // Given:
    final TopologyTestDriver driver1 = mock(TopologyTestDriver.class);
    final TopologyTestDriver driver2 = mock(TopologyTestDriver.class);
    final TestInputTopic<GenericKey, GenericRow> inA = givenInput(driver1, "a");
    givenOutput(driver1, "b");
    final TestInputTopic<GenericKey, GenericRow> inB = givenInput(driver2, "b");
    givenOutput(driver2, "a");
    givenPipe(inA, "b");
    givenPipe(inB, "a");
    pipeline.addDriver(driver1, ImmutableList.of(inf("a")), inf("b"));
    pipeline.addDriver(driver2, ImmutableList.of(inf("b")), inf("a"));
    // When:
    final KsqlException e = assertThrows(KsqlException.class, () -> pipeline.pipeInput("a", KEY, ROW1, 1));
    // Then:
    assertThat(e.getMessage(), containsString("Detected illegal cycle in topology: a->b->a"));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) TopologyTestDriver(org.apache.kafka.streams.TopologyTestDriver) GenericKey(io.confluent.ksql.GenericKey) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 77 with GenericKey

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

the class TestDriverPipelineTest method shouldHandleLinearChainTopology.

@Test
public void shouldHandleLinearChainTopology() {
    // Given (a topology that pipes a directly to b, and from b to c):
    final TopologyTestDriver driver = mock(TopologyTestDriver.class);
    final TestInputTopic<GenericKey, GenericRow> inA = givenInput(driver, "a");
    givenOutput(driver, "b");
    final TestInputTopic<GenericKey, GenericRow> inB = givenInput(driver, "b");
    givenOutput(driver, "c");
    givenPipe(inA, "b");
    givenPipe(inB, "c");
    pipeline.addDriver(driver, ImmutableList.of(inf("a")), inf("b"));
    pipeline.addDriver(driver, ImmutableList.of(inf("b")), inf("c"));
    // When:
    pipeline.pipeInput("a", KEY, ROW1, 1);
    // Then:
    assertThat(pipeline.getAllRecordsForTopic("b"), is(ImmutableList.of(new TestRecord<>(KEY, ROW1, Instant.ofEpochMilli(1)))));
    assertThat(pipeline.getAllRecordsForTopic("c"), is(ImmutableList.of(new TestRecord<>(KEY, ROW1, Instant.ofEpochMilli(1)))));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) TopologyTestDriver(org.apache.kafka.streams.TopologyTestDriver) GenericKey(io.confluent.ksql.GenericKey) Test(org.junit.Test)

Example 78 with GenericKey

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

the class TestDriverPipelineTest method shouldHandleSingleTopology.

@Test
public void shouldHandleSingleTopology() {
    // Given (a topology that pipes a directly to b):
    final TopologyTestDriver driver = mock(TopologyTestDriver.class);
    final TestInputTopic<GenericKey, GenericRow> inA = givenInput(driver, "a");
    givenOutput(driver, "b");
    givenPipe(inA, "b");
    pipeline.addDriver(driver, ImmutableList.of(inf("a")), inf("b"));
    // When:
    pipeline.pipeInput("a", KEY, ROW1, 1);
    // Then:
    assertThat(pipeline.getAllRecordsForTopic("b"), is(ImmutableList.of(new TestRecord<>(KEY, ROW1, Instant.ofEpochMilli(1)))));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) TopologyTestDriver(org.apache.kafka.streams.TopologyTestDriver) GenericKey(io.confluent.ksql.GenericKey) Test(org.junit.Test)

Example 79 with GenericKey

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

the class SourceBuilderBase method buildTable.

KTableHolder<GenericKey> buildTable(final RuntimeBuildContext buildContext, final SourceStep<KTableHolder<GenericKey>> source, final ConsumedFactory consumedFactory, final MaterializedFactory materializedFactory, final PlanInfo planInfo) {
    final PhysicalSchema physicalSchema = getPhysicalSchema(source);
    final Serde<GenericRow> valueSerde = getValueSerde(buildContext, source, physicalSchema);
    final Serde<GenericKey> keySerde = getKeySerde(source, physicalSchema, buildContext);
    final Consumed<GenericKey, GenericRow> consumed = buildSourceConsumed(source, keySerde, valueSerde, AutoOffsetReset.EARLIEST, buildContext, consumedFactory);
    final String stateStoreName = tableChangeLogOpName(source.getProperties());
    final Materialized<GenericKey, GenericRow, KeyValueStore<Bytes, byte[]>> materialized = buildTableMaterialized(source, buildContext, materializedFactory, keySerde, valueSerde, stateStoreName);
    final KTable<GenericKey, GenericRow> ktable = buildKTable(source, buildContext, consumed, GenericKey::values, materialized, valueSerde, stateStoreName, planInfo);
    final LogicalSchema stateStoreSchema = source.getSourceSchema().withPseudoColumnsToMaterialize(source.getPseudoColumnVersion());
    return KTableHolder.materialized(ktable, buildSchema(source, false), ExecutionKeyFactory.unwindowed(buildContext), MaterializationInfo.builder(stateStoreName, stateStoreSchema));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema) SourceBuilderUtils.getPhysicalSchema(io.confluent.ksql.execution.streams.SourceBuilderUtils.getPhysicalSchema) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) GenericKey(io.confluent.ksql.GenericKey)

Example 80 with GenericKey

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

the class SourceBuilderV1 method buildStream.

public KStreamHolder<GenericKey> buildStream(final RuntimeBuildContext buildContext, final StreamSource source, final ConsumedFactory consumedFactory) {
    final PhysicalSchema physicalSchema = getPhysicalSchema(source);
    final Serde<GenericRow> valueSerde = getValueSerde(buildContext, source, physicalSchema);
    final Serde<GenericKey> keySerde = getKeySerde(source, physicalSchema, buildContext);
    final Consumed<GenericKey, GenericRow> consumed = buildSourceConsumed(source, keySerde, valueSerde, AutoOffsetReset.LATEST, buildContext, consumedFactory);
    final KStream<GenericKey, GenericRow> kstream = buildKStream(source, buildContext, consumed, nonWindowedKeyGenerator(source.getSourceSchema()));
    return new KStreamHolder<>(kstream, buildSchema(source, false), ExecutionKeyFactory.unwindowed(buildContext));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) KStreamHolder(io.confluent.ksql.execution.plan.KStreamHolder) PhysicalSchema(io.confluent.ksql.schema.ksql.PhysicalSchema) SourceBuilderUtils.getPhysicalSchema(io.confluent.ksql.execution.streams.SourceBuilderUtils.getPhysicalSchema) GenericKey(io.confluent.ksql.GenericKey)

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