Search in sources :

Example 1 with TableProcessorNode

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

the class KTableImpl method doTransformValues.

private <VR> KTable<K, VR> doTransformValues(final ValueTransformerWithKeySupplier<? super K, ? super V, ? extends VR> transformerSupplier, final MaterializedInternal<K, VR, KeyValueStore<Bytes, byte[]>> materializedInternal, final NamedInternal namedInternal, final String... stateStoreNames) {
    Objects.requireNonNull(stateStoreNames, "stateStoreNames");
    final Serde<K> keySerde;
    final Serde<VR> valueSerde;
    final String queryableStoreName;
    final StoreBuilder<TimestampedKeyValueStore<K, VR>> storeBuilder;
    if (materializedInternal != null) {
        // don't inherit parent value serde, since this operation may change the value type, more specifically:
        // we preserve the key following the order of 1) materialized, 2) parent, 3) null
        keySerde = materializedInternal.keySerde() != null ? materializedInternal.keySerde() : this.keySerde;
        // we preserve the value following the order of 1) materialized, 2) null
        valueSerde = materializedInternal.valueSerde();
        queryableStoreName = materializedInternal.queryableStoreName();
        // only materialize if materialized is specified and it has queryable name
        storeBuilder = queryableStoreName != null ? (new TimestampedKeyValueStoreMaterializer<>(materializedInternal)).materialize() : null;
    } else {
        keySerde = this.keySerde;
        valueSerde = null;
        queryableStoreName = null;
        storeBuilder = null;
    }
    final String name = namedInternal.orElseGenerateWithPrefix(builder, TRANSFORMVALUES_NAME);
    final KTableProcessorSupplier<K, V, K, VR> processorSupplier = new KTableTransformValues<>(this, transformerSupplier, queryableStoreName);
    final ProcessorParameters<K, VR, ?, ?> processorParameters = unsafeCastProcessorParametersToCompletelyDifferentType(new ProcessorParameters<>(processorSupplier, name));
    final GraphNode tableNode = new TableProcessorNode<>(name, processorParameters, storeBuilder, stateStoreNames);
    builder.addGraphNode(this.graphNode, tableNode);
    return new KTableImpl<>(name, keySerde, valueSerde, subTopologySourceNodes, queryableStoreName, processorSupplier, tableNode, builder);
}
Also used : GraphNode(org.apache.kafka.streams.kstream.internals.graph.GraphNode) ProcessorGraphNode(org.apache.kafka.streams.kstream.internals.graph.ProcessorGraphNode) TableProcessorNode(org.apache.kafka.streams.kstream.internals.graph.TableProcessorNode) TimestampedKeyValueStore(org.apache.kafka.streams.state.TimestampedKeyValueStore)

Example 2 with TableProcessorNode

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

the class KTableImpl method doMapValues.

private <VR> KTable<K, VR> doMapValues(final ValueMapperWithKey<? super K, ? super V, ? extends VR> mapper, final Named named, final MaterializedInternal<K, VR, KeyValueStore<Bytes, byte[]>> materializedInternal) {
    final Serde<K> keySerde;
    final Serde<VR> valueSerde;
    final String queryableStoreName;
    final StoreBuilder<TimestampedKeyValueStore<K, VR>> storeBuilder;
    if (materializedInternal != null) {
        // materialize the store; but we still need to burn one index BEFORE generating the processor to keep compatibility.
        if (materializedInternal.storeName() == null) {
            builder.newStoreName(MAPVALUES_NAME);
        }
        keySerde = materializedInternal.keySerde() != null ? materializedInternal.keySerde() : this.keySerde;
        valueSerde = materializedInternal.valueSerde();
        queryableStoreName = materializedInternal.queryableStoreName();
        // only materialize if materialized is specified and it has queryable name
        storeBuilder = queryableStoreName != null ? (new TimestampedKeyValueStoreMaterializer<>(materializedInternal)).materialize() : null;
    } else {
        keySerde = this.keySerde;
        valueSerde = null;
        queryableStoreName = null;
        storeBuilder = null;
    }
    final String name = new NamedInternal(named).orElseGenerateWithPrefix(builder, MAPVALUES_NAME);
    final KTableProcessorSupplier<K, V, K, VR> processorSupplier = new KTableMapValues<>(this, mapper, queryableStoreName);
    // leaving in calls to ITB until building topology with graph
    final ProcessorParameters<K, VR, ?, ?> processorParameters = unsafeCastProcessorParametersToCompletelyDifferentType(new ProcessorParameters<>(processorSupplier, name));
    final GraphNode tableNode = new TableProcessorNode<>(name, processorParameters, storeBuilder);
    builder.addGraphNode(this.graphNode, tableNode);
    // we preserve the value following the order of 1) materialized, 2) null
    return new KTableImpl<>(name, keySerde, valueSerde, subTopologySourceNodes, queryableStoreName, processorSupplier, tableNode, builder);
}
Also used : GraphNode(org.apache.kafka.streams.kstream.internals.graph.GraphNode) ProcessorGraphNode(org.apache.kafka.streams.kstream.internals.graph.ProcessorGraphNode) TableProcessorNode(org.apache.kafka.streams.kstream.internals.graph.TableProcessorNode) TimestampedKeyValueStore(org.apache.kafka.streams.state.TimestampedKeyValueStore)

Example 3 with TableProcessorNode

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

the class KTableImpl method doFilter.

private KTable<K, V> doFilter(final Predicate<? super K, ? super V> predicate, final Named named, final MaterializedInternal<K, V, KeyValueStore<Bytes, byte[]>> materializedInternal, final boolean filterNot) {
    final Serde<K> keySerde;
    final Serde<V> valueSerde;
    final String queryableStoreName;
    final StoreBuilder<TimestampedKeyValueStore<K, V>> storeBuilder;
    if (materializedInternal != null) {
        // materialize the store; but we still need to burn one index BEFORE generating the processor to keep compatibility.
        if (materializedInternal.storeName() == null) {
            builder.newStoreName(FILTER_NAME);
        }
        // we can inherit parent key and value serde if user do not provide specific overrides, more specifically:
        // we preserve the key following the order of 1) materialized, 2) parent
        keySerde = materializedInternal.keySerde() != null ? materializedInternal.keySerde() : this.keySerde;
        // we preserve the value following the order of 1) materialized, 2) parent
        valueSerde = materializedInternal.valueSerde() != null ? materializedInternal.valueSerde() : this.valueSerde;
        queryableStoreName = materializedInternal.queryableStoreName();
        // only materialize if materialized is specified and it has queryable name
        storeBuilder = queryableStoreName != null ? (new TimestampedKeyValueStoreMaterializer<>(materializedInternal)).materialize() : null;
    } else {
        keySerde = this.keySerde;
        valueSerde = this.valueSerde;
        queryableStoreName = null;
        storeBuilder = null;
    }
    final String name = new NamedInternal(named).orElseGenerateWithPrefix(builder, FILTER_NAME);
    final KTableProcessorSupplier<K, V, K, V> processorSupplier = new KTableFilter<>(this, predicate, filterNot, queryableStoreName);
    final ProcessorParameters<K, V, ?, ?> processorParameters = unsafeCastProcessorParametersToCompletelyDifferentType(new ProcessorParameters<>(processorSupplier, name));
    final GraphNode tableNode = new TableProcessorNode<>(name, processorParameters, storeBuilder);
    builder.addGraphNode(this.graphNode, tableNode);
    return new KTableImpl<K, V, V>(name, keySerde, valueSerde, subTopologySourceNodes, queryableStoreName, processorSupplier, tableNode, builder);
}
Also used : GraphNode(org.apache.kafka.streams.kstream.internals.graph.GraphNode) ProcessorGraphNode(org.apache.kafka.streams.kstream.internals.graph.ProcessorGraphNode) TableProcessorNode(org.apache.kafka.streams.kstream.internals.graph.TableProcessorNode) TimestampedKeyValueStore(org.apache.kafka.streams.state.TimestampedKeyValueStore)

Aggregations

GraphNode (org.apache.kafka.streams.kstream.internals.graph.GraphNode)3 ProcessorGraphNode (org.apache.kafka.streams.kstream.internals.graph.ProcessorGraphNode)3 TableProcessorNode (org.apache.kafka.streams.kstream.internals.graph.TableProcessorNode)3 TimestampedKeyValueStore (org.apache.kafka.streams.state.TimestampedKeyValueStore)3