lct45 commented on a change in pull request #9141: URL: https://github.com/apache/kafka/pull/9141#discussion_r467236081
########## File path: streams/src/main/java/org/apache/kafka/streams/kstream/internals/CogroupedStreamAggregateBuilder.java ########## @@ -47,18 +47,96 @@ CogroupedStreamAggregateBuilder(final InternalStreamsBuilder builder) { this.builder = builder; } - - <KR, VIn, W extends Window> KTable<KR, VOut> build(final Map<KGroupedStreamImpl<K, ?>, Aggregator<? super K, ? super Object, VOut>> groupPatterns, + <KR, VIn, W extends Window> KTable<KR, VOut> buildNotWindowed(final Map<KGroupedStreamImpl<K, ?>, Aggregator<? super K, ? super Object, VOut>> groupPatterns, final Initializer<VOut> initializer, final NamedInternal named, final StoreBuilder<?> storeBuilder, final Serde<KR> keySerde, final Serde<VOut> valueSerde, - final String queryableName, - final Windows<W> windows, - final SessionWindows sessionWindows, - final Merger<? super K, VOut> sessionMerger) { + final String queryableName) { + build(groupPatterns, storeBuilder); + final Collection<StreamsGraphNode> processors = new ArrayList<>(); + boolean stateCreated = false; + int counter = 0; + for (final Entry<KGroupedStreamImpl<K, ?>, Aggregator<? super K, Object, VOut>> kGroupedStream : groupPatterns.entrySet()) { + final StatefulProcessorNode<K, ?> statefulProcessorNode = getStatefulProcessorNode( + initializer, + named.suffixWithOrElseGet( + "-cogroup-agg-" + counter++, + builder, + CogroupedKStreamImpl.AGGREGATE_NAME), + stateCreated, + storeBuilder, + new KStreamAggregate<>(storeBuilder.name(), initializer, kGroupedStream.getValue())); + stateCreated = true; + processors.add(statefulProcessorNode); + builder.addGraphNode(parentNodes.get(kGroupedStream.getKey()), statefulProcessorNode); + } + return createTable(processors, named, keySerde, valueSerde, queryableName); + } + + <KR, VIn, W extends Window> KTable<KR, VOut> buildTimeWindows(final Map<KGroupedStreamImpl<K, ?>, Aggregator<? super K, ? super Object, VOut>> groupPatterns, + final Initializer<VOut> initializer, + final NamedInternal named, + final StoreBuilder<?> storeBuilder, + final Serde<KR> keySerde, + final Serde<VOut> valueSerde, + final String queryableName, + final Windows<W> windows) { + build(groupPatterns, storeBuilder); + final Collection<StreamsGraphNode> processors = new ArrayList<>(); + boolean stateCreated = false; + int counter = 0; + for (final Entry<KGroupedStreamImpl<K, ?>, Aggregator<? super K, Object, VOut>> kGroupedStream : groupPatterns.entrySet()) { + final StatefulProcessorNode<K, ?> statefulProcessorNode = getStatefulProcessorNode( + initializer, + named.suffixWithOrElseGet( + "-cogroup-agg-" + counter++, + builder, + CogroupedKStreamImpl.AGGREGATE_NAME), + stateCreated, + storeBuilder, + new KStreamWindowAggregate<>(windows, storeBuilder.name(), initializer, kGroupedStream.getValue())); + stateCreated = true; + processors.add(statefulProcessorNode); + builder.addGraphNode(parentNodes.get(kGroupedStream.getKey()), statefulProcessorNode); + } + return createTable(processors, named, keySerde, valueSerde, queryableName); + } + + <KR, VIn, W extends Window> KTable<KR, VOut> buildSessionWindows(final Map<KGroupedStreamImpl<K, ?>, Aggregator<? super K, ? super Object, VOut>> groupPatterns, + final Initializer<VOut> initializer, + final NamedInternal named, + final StoreBuilder<?> storeBuilder, + final Serde<KR> keySerde, + final Serde<VOut> valueSerde, + final String queryableName, + final SessionWindows sessionWindows, + final Merger<? super K, VOut> sessionMerger) { + build(groupPatterns, storeBuilder); + final Collection<StreamsGraphNode> processors = new ArrayList<>(); + boolean stateCreated = false; + int counter = 0; + for (final Entry<KGroupedStreamImpl<K, ?>, Aggregator<? super K, Object, VOut>> kGroupedStream : groupPatterns.entrySet()) { + final StatefulProcessorNode<K, ?> statefulProcessorNode = getStatefulProcessorNode( + initializer, + named.suffixWithOrElseGet( + "-cogroup-agg-" + counter++, + builder, + CogroupedKStreamImpl.AGGREGATE_NAME), + stateCreated, + storeBuilder, + new KStreamSessionWindowAggregate<>(sessionWindows, storeBuilder.name(), initializer, kGroupedStream.getValue(), sessionMerger)); + stateCreated = true; + processors.add(statefulProcessorNode); + builder.addGraphNode(parentNodes.get(kGroupedStream.getKey()), statefulProcessorNode); + } + return createTable(processors, named, keySerde, valueSerde, queryableName); + } + + private void build(final Map<KGroupedStreamImpl<K, ?>, Aggregator<? super K, ? super Object, VOut>> groupPatterns, + final StoreBuilder<?> storeBuilder) { Review comment: I went with processRepartitions and then updated all the other methods to just be `build` with different parameters since that seems cleaner ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org