Search in sources :

Example 6 with GenericKey

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

the class ForeignKeyTableTableJoinBuilderTest method shouldDoInnerJoinOnNonKey.

@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void shouldDoInnerJoinOnNonKey() {
    // Given:
    givenInnerJoin(left, JOIN_COLUMN);
    // When:
    final KTableHolder<Struct> result = join.build(planBuilder, planInfo);
    // Then:
    final ArgumentCaptor<KsqlKeyExtractor> ksqlKeyExtractor = ArgumentCaptor.forClass(KsqlKeyExtractor.class);
    verify(leftKTable).join(same(rightKTable), ksqlKeyExtractor.capture(), eq(new KsqlValueJoiner(LEFT_SCHEMA.value().size(), RIGHT_SCHEMA.value().size(), 0)), any(Materialized.class));
    verifyNoMoreInteractions(leftKTable, rightKTable, resultKTable);
    final GenericKey extractedKey = GenericKey.genericKey(FOREIGN_KEY);
    assertThat(ksqlKeyExtractor.getValue().apply(LEFT_ROW), is(extractedKey));
    assertThat(result.getTable(), is(resultKTable));
    assertThat(result.getExecutionKeyFactory(), is(executionKeyFactory));
}
Also used : GenericKey(io.confluent.ksql.GenericKey) Materialized(org.apache.kafka.streams.kstream.Materialized) Struct(org.apache.kafka.connect.data.Struct) Test(org.junit.Test)

Example 7 with GenericKey

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

the class KsMaterializedTableIQv2Test method getIteratorResult.

private static StateQueryResult getIteratorResult() {
    final StateQueryResult result = new StateQueryResult<>();
    Set<GenericKey> keySet = new HashSet<>();
    keySet.add(A_KEY);
    keySet.add(A_KEY2);
    Map<GenericKey, ValueAndTimestamp<GenericRow>> map = new HashMap<>();
    map.put(A_KEY, VALUE_AND_TIMESTAMP1);
    map.put(A_KEY2, VALUE_AND_TIMESTAMP2);
    final KeyValueIterator iterator = new TestKeyValueIterator(keySet, map);
    final QueryResult queryResult = QueryResult.forResult(iterator);
    queryResult.setPosition(POSITION);
    result.addResult(PARTITION, queryResult);
    return result;
}
Also used : ValueAndTimestamp(org.apache.kafka.streams.state.ValueAndTimestamp) QueryResult(org.apache.kafka.streams.query.QueryResult) StateQueryResult(org.apache.kafka.streams.query.StateQueryResult) HashMap(java.util.HashMap) KeyValueIterator(org.apache.kafka.streams.state.KeyValueIterator) StateQueryResult(org.apache.kafka.streams.query.StateQueryResult) GenericKey(io.confluent.ksql.GenericKey) HashSet(java.util.HashSet)

Example 8 with GenericKey

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

the class SourceBuilderV1Test method shouldAddRowTimeAndTimeWindowedRowKeyColumnsToLegacyStream.

@Test
public void shouldAddRowTimeAndTimeWindowedRowKeyColumnsToLegacyStream() {
    // Given:
    givenWindowedSourceStream(LEGACY_PSEUDOCOLUMN_VERSION_NUMBER);
    final ValueTransformerWithKey<Windowed<GenericKey>, GenericRow, GenericRow> transformer = getTransformerFromStreamSource(windowedStreamSource);
    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, equalTo(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 9 with GenericKey

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

the class SourceBuilderV1Test method shouldHandleEmptyKeyLegacy.

@Test
public void shouldHandleEmptyKeyLegacy() {
    // Given:
    givenUnwindowedSourceStream(LEGACY_PSEUDOCOLUMN_VERSION_NUMBER);
    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, null)));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) GenericKey(io.confluent.ksql.GenericKey) Test(org.junit.Test)

Example 10 with GenericKey

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

the class StreamAggregateBuilderTest method shouldBuildUnwindowedAggregateCorrectly.

@Test
public void shouldBuildUnwindowedAggregateCorrectly() {
    // Given:
    givenUnwindowedAggregate();
    // When:
    final KTableHolder<GenericKey> result = aggregate.build(planBuilder, planInfo);
    // Then:
    assertThat(result.getTable(), is(aggregatedWithResults));
    final InOrder inOrder = Mockito.inOrder(groupedStream, aggregated, aggregatedWithResults);
    inOrder.verify(groupedStream).aggregate(initializer, aggregator, materialized);
    inOrder.verify(aggregated).transformValues(any(), any(Named.class));
    inOrder.verifyNoMoreInteractions();
}
Also used : Named(org.apache.kafka.streams.kstream.Named) InOrder(org.mockito.InOrder) 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