inponomarev commented on a change in pull request #9107:
URL: https://github.com/apache/kafka/pull/9107#discussion_r548523976



##########
File path: 
streams/src/main/java/org/apache/kafka/streams/kstream/BranchedKStream.java
##########
@@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.streams.kstream;
+
+import java.util.Map;
+
+/**
+ * Branches the records in the original stream based on the predicates 
supplied for the branch definitions.
+ * <p>
+ * Branches are defined with {@link BranchedKStream#branch(Predicate, 
Branched)} or
+ * {@link BranchedKStream#defaultBranch(Branched)} methods. Each record is 
evaluated against the predicates
+ * supplied via {@link Branched} parameters, and is routed to the first branch 
for which its respective predicate
+ * evaluates to {@code true}.
+ * <p>
+ * Each branch (which is a {@link KStream} instance) then can be processed 
either by
+ * a {@link java.util.function.Function} or a {@link 
java.util.function.Consumer} provided via a {@link Branched}
+ * parameter. It also can be accessed from the {@link Map} returned by {@link 
BranchedKStream#defaultBranch(Branched)} or
+ * {@link BranchedKStream#noDefaultBranch()} (see <a href="#examples">usage 
examples</a>).
+ * <p>
+ * The branching happens on first-match: A record in the original stream is 
assigned to the corresponding result
+ * stream for the first predicate that evaluates to true, and is assigned to 
this stream only. If you need
+ * to route a record to multiple streams, you can use {@link 
KStream#filter(Predicate)} for each predicate instead
+ * of branching.
+ * <p>
+ * The process of routing the records to different branches is a stateless 
record-by-record operation.
+ * <h2><a name="maprules">Rules of forming the resulting map</a></h2>
+ * The keys of the {@code Map<String, KStream<K, V>>} entries returned by 
{@link BranchedKStream#defaultBranch(Branched)} or
+ * {@link BranchedKStream#noDefaultBranch()} are defined by the following 
rules:
+ * <p>
+ * <ul>
+ *     <li>If {@link Named} parameter was provided for {@link 
KStream#split(Named)}, its value is used as
+ *     a prefix for each key. By default, no prefix is used
+ *     <li>If a name is provided for the {@link 
BranchedKStream#branch(Predicate, Branched)} via
+ *     {@link Branched} parameter, its value is appended to the prefix to form 
the {@code Map} key
+ *     <li>If a name is not provided for the branch, then the key defaults to 
{@code prefix + position} of the branch
+ *     as a decimal number, starting from {@code "1"}
+ *     <li>If a name is not provided for the {@link 
BranchedKStream#defaultBranch()} call, then the key defaults
+ *     to {@code prefix + "0"}
+ * </ul>
+ * <p>
+ * The values of the respective {@code Map<Stream, KStream<K, V>>} entries are 
formed as following:
+ * <p>
+ * <ul>
+ *     <li>If no chain function or consumer is provided {@link 
BranchedKStream#branch(Predicate, Branched)} via
+ *     {@link Branched} parameter, then the value is the branch itself (which 
is equivalent to {@code ks -> ks}
+ *     identity chain function)

Review comment:
       No we don't, removed )




----------------------------------------------------------------
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:
[email protected]


Reply via email to