Search in sources :

Example 1 with StreamToTableNode

use of org.apache.kafka.streams.kstream.internals.graph.StreamToTableNode in project kafka by apache.

the class KStreamImpl method toTable.

@Override
public KTable<K, V> toTable(final Named named, final Materialized<K, V, KeyValueStore<Bytes, byte[]>> materialized) {
    Objects.requireNonNull(named, "named can't be null");
    Objects.requireNonNull(materialized, "materialized can't be null");
    final NamedInternal namedInternal = new NamedInternal(named);
    final String name = namedInternal.orElseGenerateWithPrefix(builder, TO_KTABLE_NAME);
    final MaterializedInternal<K, V, KeyValueStore<Bytes, byte[]>> materializedInternal = new MaterializedInternal<>(materialized, builder, TO_KTABLE_NAME);
    final Serde<K> keySerdeOverride = materializedInternal.keySerde() == null ? keySerde : materializedInternal.keySerde();
    final Serde<V> valueSerdeOverride = materializedInternal.valueSerde() == null ? valueSerde : materializedInternal.valueSerde();
    final Set<String> subTopologySourceNodes;
    final GraphNode tableParentNode;
    if (repartitionRequired) {
        final OptimizableRepartitionNodeBuilder<K, V> repartitionNodeBuilder = optimizableRepartitionNodeBuilder();
        final String sourceName = createRepartitionedSource(builder, keySerdeOverride, valueSerdeOverride, name, null, repartitionNodeBuilder);
        tableParentNode = repartitionNodeBuilder.build();
        builder.addGraphNode(graphNode, tableParentNode);
        subTopologySourceNodes = Collections.singleton(sourceName);
    } else {
        tableParentNode = graphNode;
        subTopologySourceNodes = this.subTopologySourceNodes;
    }
    final KTableSource<K, V> tableSource = new KTableSource<>(materializedInternal.storeName(), materializedInternal.queryableStoreName());
    final ProcessorParameters<K, V, ?, ?> processorParameters = new ProcessorParameters<>(tableSource, name);
    final GraphNode tableNode = new StreamToTableNode<>(name, processorParameters, materializedInternal);
    builder.addGraphNode(tableParentNode, tableNode);
    return new KTableImpl<K, V, V>(name, keySerdeOverride, valueSerdeOverride, subTopologySourceNodes, materializedInternal.queryableStoreName(), tableSource, tableNode, builder);
}
Also used : StreamToTableNode(org.apache.kafka.streams.kstream.internals.graph.StreamToTableNode) ProcessorParameters(org.apache.kafka.streams.kstream.internals.graph.ProcessorParameters) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore) GraphNode(org.apache.kafka.streams.kstream.internals.graph.GraphNode) ProcessorGraphNode(org.apache.kafka.streams.kstream.internals.graph.ProcessorGraphNode)

Aggregations

GraphNode (org.apache.kafka.streams.kstream.internals.graph.GraphNode)1 ProcessorGraphNode (org.apache.kafka.streams.kstream.internals.graph.ProcessorGraphNode)1 ProcessorParameters (org.apache.kafka.streams.kstream.internals.graph.ProcessorParameters)1 StreamToTableNode (org.apache.kafka.streams.kstream.internals.graph.StreamToTableNode)1 KeyValueStore (org.apache.kafka.streams.state.KeyValueStore)1