You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2021/02/18 17:01:42 UTC

[GitHub] [kafka] bbejeck opened a new pull request #10150: KAFKA-3745: Add access to read-only key in value joiner

bbejeck opened a new pull request #10150:
URL: https://github.com/apache/kafka/pull/10150


   This PR implements adding read-only access to the key for `KStream.join` as described in [KIP-149](https://cwiki.apache.org/confluence/display/KAFKA/KIP-149%3A+Enabling+key+access+in+ValueTransformer%2C+ValueMapper%2C+and+ValueJoiner)
   
   This PR as it stands does not affect the Streams Scala API.  Updating the Streams Scala API will be done in a follow-up PR.
   Additionally, the original KIP did not include the `KTable` API, but I don't see any reason why we wouldn't want the same functionality there as well, this will be done in an additional follow-up PR after updating the existing KIP.
   
   
   Tests added
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [kafka] bbejeck commented on pull request #10150: KAFKA-3745: Add access to read-only key in value joiner

Posted by GitBox <gi...@apache.org>.
bbejeck commented on pull request #10150:
URL: https://github.com/apache/kafka/pull/10150#issuecomment-788178028


   ping @mjsax @cadonna @vvcephei  for reviews


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [kafka] bbejeck commented on pull request #10150: KAFKA-3745: Add access to read-only key in value joiner

Posted by GitBox <gi...@apache.org>.
bbejeck commented on pull request #10150:
URL: https://github.com/apache/kafka/pull/10150#issuecomment-788208213


   including @lct45  and @wcarlson5  in the review request as well


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [kafka] bbejeck commented on pull request #10150: KAFKA-3745: Add access to read-only key in value joiner

Posted by GitBox <gi...@apache.org>.
bbejeck commented on pull request #10150:
URL: https://github.com/apache/kafka/pull/10150#issuecomment-803500675


   Merged #10150 into trunk


-- 
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:
users@infra.apache.org



[GitHub] [kafka] bbejeck commented on a change in pull request #10150: KAFKA-3745: Add access to read-only key in value joiner

Posted by GitBox <gi...@apache.org>.
bbejeck commented on a change in pull request #10150:
URL: https://github.com/apache/kafka/pull/10150#discussion_r594665349



##########
File path: streams/src/test/java/org/apache/kafka/streams/kstream/internals/KStreamImplValueJoinerWithKeyTest.java
##########
@@ -0,0 +1,229 @@
+/*
+ * 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.internals;
+
+import org.apache.kafka.common.serialization.IntegerSerializer;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.serialization.StringDeserializer;
+import org.apache.kafka.common.serialization.StringSerializer;
+import org.apache.kafka.streams.KeyValue;
+import org.apache.kafka.streams.StreamsBuilder;
+import org.apache.kafka.streams.TestInputTopic;
+import org.apache.kafka.streams.TestOutputTopic;
+import org.apache.kafka.streams.TopologyTestDriver;
+import org.apache.kafka.streams.kstream.Consumed;
+import org.apache.kafka.streams.kstream.GlobalKTable;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.Joined;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KTable;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.ValueJoinerWithKey;
+import org.apache.kafka.test.StreamsTestUtils;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+import static java.time.Duration.ofMillis;
+import static org.junit.Assert.assertEquals;
+
+public class KStreamImplValueJoinerWithKeyTest {
+
+    private KStream<String, Integer> leftStream;
+    private KStream<String, Integer> rightStream;
+    private KTable<String, Integer> ktable;
+    private GlobalKTable<String, Integer> globalKTable;
+    private StreamsBuilder builder;
+
+    private final Properties props = StreamsTestUtils.getStreamsConfig(Serdes.String(), Serdes.String());
+    private final String leftTopic = "left";
+    private final String rightTopic = "right";
+    private final String ktableTopic = "ktableTopic";
+    private final String globalTopic = "globalTopic";
+    private final String outputTopic = "joined-result";
+
+    private final ValueJoinerWithKey<String, Integer, Integer, String> valueJoinerWithKey =
+        (key, lv, rv) -> key + ":" + (lv + (rv == null ? 0 : rv));
+    private final JoinWindows joinWindows = JoinWindows.of(ofMillis(100));
+    private final StreamJoined<String, Integer, Integer> streamJoined =
+            StreamJoined.with(Serdes.String(), Serdes.Integer(), Serdes.Integer());
+    private final Joined<String, Integer, Integer> joined =
+            Joined.with(Serdes.String(), Serdes.Integer(), Serdes.Integer());
+    private final KeyValueMapper<String, Integer, String> keyValueMapper =
+        (k, v) -> k;
+
+    @Before
+    public void setup() {
+        builder = new StreamsBuilder();
+        leftStream = builder.stream(leftTopic, Consumed.with(Serdes.String(), Serdes.Integer()));
+        rightStream = builder.stream(rightTopic, Consumed.with(Serdes.String(), Serdes.Integer()));
+        ktable = builder.table(ktableTopic, Consumed.with(Serdes.String(), Serdes.Integer()));
+        globalKTable = builder.globalTable(globalTopic, Consumed.with(Serdes.String(), Serdes.Integer()));
+    }
+
+    @Test
+    public void shouldIncludeKeyInStreamSteamJoinResults() {
+        leftStream.join(
+                rightStream,
+                valueJoinerWithKey,
+                joinWindows,
+                streamJoined
+        ).to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));
+        // Left KV A, 3, Right KV A, 5
+        runJoinTopology(builder,
+                Collections.singletonList(KeyValue.pair("A", "A:5")),
+                false,
+                rightTopic
+        );
+    }
+
+    @Test
+    public void shouldIncludeKeyInStreamLeftJoinResults() {
+        leftStream.leftJoin(
+                rightStream,
+                valueJoinerWithKey,
+                joinWindows,
+                streamJoined
+        ).to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));
+        // Left KV A, 3, Right KV A, 5
+        // TTD pipes records to left stream first, then right
+        // with TTD there's no caching, so join emits immediately with "A, 3, null" then "A, 3, 5"
+        final List<KeyValue<String, String>> expectedResults = Arrays.asList(KeyValue.pair("A", "A:3"), KeyValue.pair("A", "A:5"));
+        runJoinTopology(builder,
+                expectedResults,
+                false,
+                rightTopic
+        );
+    }
+
+    @Test
+    public void shouldIncludeKeyInStreamOuterJoinResults() {
+        leftStream.outerJoin(
+                rightStream,
+                valueJoinerWithKey,
+                joinWindows,
+                streamJoined
+        ).to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));
+
+        // Left KV A, 3, Right KV A, 5
+        // TTD pipes records to left stream first, then right
+        // with TTD there's no caching, so join emits immediately with "A, 3, null" then "A, 3, 5"
+        final List<KeyValue<String, String>> expectedResults = Arrays.asList(KeyValue.pair("A", "A:3"), KeyValue.pair("A", "A:5"));
+        runJoinTopology(builder,
+                expectedResults,
+                false,
+                rightTopic
+        );
+    }
+
+    @Test
+    public void shouldIncludeKeyInStreamTableJoinResults() {
+        leftStream.join(
+            ktable,
+            valueJoinerWithKey,
+            joined
+        ).to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));
+        // Left KV A, 3, Table KV A, 5
+        runJoinTopology(builder,
+                Collections.singletonList(KeyValue.pair("A", "A:5")),
+                true,
+                ktableTopic
+        );
+    }
+
+    @Test
+    public void shouldIncludeKeyInStreamTableLeftJoinResults() {
+        leftStream.leftJoin(
+            ktable,
+            valueJoinerWithKey,
+            joined
+        ).to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));
+        // Left KV A, 3, Table KV A, 5

Review comment:
       Ack




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [kafka] mjsax commented on a change in pull request #10150: KAFKA-3745: Add access to read-only key in value joiner

Posted by GitBox <gi...@apache.org>.
mjsax commented on a change in pull request #10150:
URL: https://github.com/apache/kafka/pull/10150#discussion_r586703617



##########
File path: streams/src/test/java/org/apache/kafka/streams/kstream/internals/KStreamImplTest.java
##########
@@ -792,12 +802,24 @@ public void shouldNotAllowNullValueJoinerOnJoinWithStreamJoined() {
             NullPointerException.class,
             () -> testStream.join(
                 testStream,
-                null,
+                    (ValueJoiner<? super String, ? super String, ?>) null,

Review comment:
       nit: fix indention

##########
File path: streams/src/test/java/org/apache/kafka/streams/kstream/internals/KStreamImplTest.java
##########
@@ -916,12 +946,25 @@ public void shouldNotAllowNullValueJoinerOnLeftJoinWithStreamJoined() {
             NullPointerException.class,
             () -> testStream.leftJoin(
                 testStream,
-                null,
+                    (ValueJoiner<? super String, ? super String, ?>) null,

Review comment:
       nit: fix indention

##########
File path: streams/src/test/java/org/apache/kafka/streams/kstream/internals/KStreamImplTest.java
##########
@@ -1040,12 +1091,24 @@ public void shouldNotAllowNullValueJoinerOnOuterJoinWithStreamJoined() {
             NullPointerException.class,
             () -> testStream.outerJoin(
                 testStream,
-                null,
+                    (ValueJoiner<? super String, ? super String, ?>) null,

Review comment:
       indention

##########
File path: streams/src/main/java/org/apache/kafka/streams/kstream/KStream.java
##########
@@ -1315,15 +1315,15 @@ void to(final TopicNameExtractor<K, V> topicExtractor,
                                  final JoinWindows windows);
 
     /**
-     * Join records of this stream with another {@code KStream}'s records using windowed inner equi join using the

Review comment:
       Oh dear... This diff is confusing... I guess you actually inserted this a copy from above with slight modification only.
   
   Might be helpful if you could highlight the actual changes to the JavaDocs? Two below are clear. Are there others? Or same changes for all other method?

##########
File path: streams/src/test/java/org/apache/kafka/streams/kstream/internals/KStreamImplTest.java
##########
@@ -1225,25 +1320,45 @@ public void shouldNotAllowNullMapperOnJoinWithGlobalTableWithNamed() {
     }
 
     @Test
-    public void shouldNotAllowNullJoinerOnJoinWithGlobalTable() {
+    public void shouldNotAllowNullValueJoinerOnJoinWithGlobalTable() {
+        final NullPointerException exception = assertThrows(
+            NullPointerException.class,
+            () -> testStream.join(testGlobalTable, MockMapper.selectValueMapper(), (ValueJoiner<? super String, ? super String, ?>) null));
+        assertThat(exception.getMessage(), equalTo("joiner can't be null"));
+    }
+
+    @Test
+    public void shouldNotAllowNullValueJoinerWithKeyOnJoinWithGlobalTable() {
         final NullPointerException exception = assertThrows(
             NullPointerException.class,
-            () -> testStream.join(testGlobalTable, MockMapper.selectValueMapper(), null));
+            () -> testStream.join(testGlobalTable, MockMapper.selectValueMapper(), (ValueJoinerWithKey<? super String, ? super String, ? super String, ?>) null));
         assertThat(exception.getMessage(), equalTo("joiner can't be null"));
     }
 
     @Test
-    public void shouldNotAllowNullJoinerOnJoinWithGlobalTableWithNamed() {
+    public void shouldNotAllowNullValueJoinerOnJoinWithGlobalTableWithNamed() {
         final NullPointerException exception = assertThrows(
             NullPointerException.class,
             () -> testStream.join(
                 testGlobalTable,
                 MockMapper.selectValueMapper(),
-                null,
+                    (ValueJoiner<? super String, ? super String, ?>) null,

Review comment:
       indention

##########
File path: streams/src/test/java/org/apache/kafka/streams/kstream/internals/KStreamImplValueJoinerWithKeyTest.java
##########
@@ -0,0 +1,229 @@
+/*
+ * 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.internals;
+
+import org.apache.kafka.common.serialization.IntegerSerializer;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.serialization.StringDeserializer;
+import org.apache.kafka.common.serialization.StringSerializer;
+import org.apache.kafka.streams.KeyValue;
+import org.apache.kafka.streams.StreamsBuilder;
+import org.apache.kafka.streams.TestInputTopic;
+import org.apache.kafka.streams.TestOutputTopic;
+import org.apache.kafka.streams.TopologyTestDriver;
+import org.apache.kafka.streams.kstream.Consumed;
+import org.apache.kafka.streams.kstream.GlobalKTable;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.Joined;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KTable;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.ValueJoinerWithKey;
+import org.apache.kafka.test.StreamsTestUtils;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+import static java.time.Duration.ofMillis;
+import static org.junit.Assert.assertEquals;
+
+public class KStreamImplValueJoinerWithKeyTest {
+
+    private KStream<String, Integer> leftStream;
+    private KStream<String, Integer> rightStream;
+    private KTable<String, Integer> ktable;
+    private GlobalKTable<String, Integer> globalKTable;
+    private StreamsBuilder builder;
+
+    private final Properties props = StreamsTestUtils.getStreamsConfig(Serdes.String(), Serdes.String());
+    private final String leftTopic = "left";
+    private final String rightTopic = "right";
+    private final String ktableTopic = "ktableTopic";
+    private final String globalTopic = "globalTopic";
+    private final String outputTopic = "joined-result";
+
+    private final ValueJoinerWithKey<String, Integer, Integer, String> valueJoinerWithKey =
+        (key, lv, rv) -> key + ":" + (lv + (rv == null ? 0 : rv));
+    private final JoinWindows joinWindows = JoinWindows.of(ofMillis(100));
+    private final StreamJoined<String, Integer, Integer> streamJoined =
+            StreamJoined.with(Serdes.String(), Serdes.Integer(), Serdes.Integer());
+    private final Joined<String, Integer, Integer> joined =
+            Joined.with(Serdes.String(), Serdes.Integer(), Serdes.Integer());
+    private final KeyValueMapper<String, Integer, String> keyValueMapper =
+        (k, v) -> k;
+
+    @Before
+    public void setup() {
+        builder = new StreamsBuilder();
+        leftStream = builder.stream(leftTopic, Consumed.with(Serdes.String(), Serdes.Integer()));
+        rightStream = builder.stream(rightTopic, Consumed.with(Serdes.String(), Serdes.Integer()));
+        ktable = builder.table(ktableTopic, Consumed.with(Serdes.String(), Serdes.Integer()));
+        globalKTable = builder.globalTable(globalTopic, Consumed.with(Serdes.String(), Serdes.Integer()));
+    }
+
+    @Test
+    public void shouldIncludeKeyInStreamSteamJoinResults() {
+        leftStream.join(
+                rightStream,
+                valueJoinerWithKey,
+                joinWindows,
+                streamJoined
+        ).to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));
+        // Left KV A, 3, Right KV A, 5
+        runJoinTopology(builder,
+                Collections.singletonList(KeyValue.pair("A", "A:5")),
+                false,
+                rightTopic
+        );
+    }
+
+    @Test
+    public void shouldIncludeKeyInStreamLeftJoinResults() {
+        leftStream.leftJoin(
+                rightStream,
+                valueJoinerWithKey,
+                joinWindows,
+                streamJoined
+        ).to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));
+        // Left KV A, 3, Right KV A, 5
+        // TTD pipes records to left stream first, then right
+        // with TTD there's no caching, so join emits immediately with "A, 3, null" then "A, 3, 5"
+        final List<KeyValue<String, String>> expectedResults = Arrays.asList(KeyValue.pair("A", "A:3"), KeyValue.pair("A", "A:5"));
+        runJoinTopology(builder,
+                expectedResults,
+                false,
+                rightTopic
+        );
+    }
+
+    @Test
+    public void shouldIncludeKeyInStreamOuterJoinResults() {
+        leftStream.outerJoin(
+                rightStream,
+                valueJoinerWithKey,
+                joinWindows,
+                streamJoined
+        ).to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));
+
+        // Left KV A, 3, Right KV A, 5

Review comment:
       To actually test outer join, should we not send a second right record with different key (ie, `B`)? (I assume you copied an existing test, so maybe we can improve both in a follow up PR?)

##########
File path: streams/src/main/java/org/apache/kafka/streams/kstream/KStream.java
##########
@@ -1315,15 +1315,15 @@ void to(final TopicNameExtractor<K, V> topicExtractor,
                                  final JoinWindows windows);
 
     /**
-     * Join records of this stream with another {@code KStream}'s records using windowed inner equi join using the
-     * {@link Joined} instance for configuration of the {@link Serde key serde}, {@link Serde this stream's value serde},
-     * and {@link Serde the other stream's value serde}.
+     * Join records of this stream with another {@code KStream}'s records using windowed inner equi join with default
+     * serializers and deserializers.
      * The join is computed on the records' key with join attribute {@code thisKStream.key == otherKStream.key}.
      * Furthermore, two records are only joined if their timestamps are close to each other as defined by the given
      * {@link JoinWindows}, i.e., the window defines an additional join predicate on the record timestamps.
      * <p>
-     * For each pair of records meeting both join predicates the provided {@link ValueJoiner} will be called to compute
+     * For each pair of records meeting both join predicates the provided {@link ValueJoinerWithKey} will be called to compute
      * a value (with arbitrary type) for the result record.
+     * Note that the key is read-only and should not be modified, as this can lead to undefined behaviour.

Review comment:
       And this seems to be an actual change?

##########
File path: streams/src/main/java/org/apache/kafka/streams/kstream/KStream.java
##########
@@ -1315,15 +1315,15 @@ void to(final TopicNameExtractor<K, V> topicExtractor,
                                  final JoinWindows windows);
 
     /**
-     * Join records of this stream with another {@code KStream}'s records using windowed inner equi join using the
-     * {@link Joined} instance for configuration of the {@link Serde key serde}, {@link Serde this stream's value serde},
-     * and {@link Serde the other stream's value serde}.
+     * Join records of this stream with another {@code KStream}'s records using windowed inner equi join with default
+     * serializers and deserializers.
      * The join is computed on the records' key with join attribute {@code thisKStream.key == otherKStream.key}.
      * Furthermore, two records are only joined if their timestamps are close to each other as defined by the given
      * {@link JoinWindows}, i.e., the window defines an additional join predicate on the record timestamps.
      * <p>
-     * For each pair of records meeting both join predicates the provided {@link ValueJoiner} will be called to compute
+     * For each pair of records meeting both join predicates the provided {@link ValueJoinerWithKey} will be called to compute

Review comment:
       This seems to be an actual change?

##########
File path: streams/src/test/java/org/apache/kafka/streams/kstream/internals/KStreamImplTest.java
##########
@@ -1285,25 +1400,45 @@ public void shouldNotAllowNullMapperOnLeftJoinWithGlobalTableWithNamed() {
     }
 
     @Test
-    public void shouldNotAllowNullJoinerOnLeftJoinWithGlobalTable() {
+    public void shouldNotAllowNullValueJoinerOnLeftJoinWithGlobalTable() {
+        final NullPointerException exception = assertThrows(
+            NullPointerException.class,
+            () -> testStream.leftJoin(testGlobalTable, MockMapper.selectValueMapper(), (ValueJoiner<? super String, ? super String, ?>) null));
+        assertThat(exception.getMessage(), equalTo("joiner can't be null"));
+    }
+
+    @Test
+    public void shouldNotAllowNullValueJoinerWithKeyOnLeftJoinWithGlobalTable() {
         final NullPointerException exception = assertThrows(
             NullPointerException.class,
-            () -> testStream.leftJoin(testGlobalTable, MockMapper.selectValueMapper(), null));
+            () -> testStream.leftJoin(testGlobalTable, MockMapper.selectValueMapper(), (ValueJoinerWithKey<? super String, ? super String, ? super String, ?>) null));
         assertThat(exception.getMessage(), equalTo("joiner can't be null"));
     }
 
     @Test
-    public void shouldNotAllowNullJoinerOnLeftJoinWithGlobalTableWithNamed() {
+    public void shouldNotAllowNullValueJoinerOnLeftJoinWithGlobalTableWithNamed() {
         final NullPointerException exception = assertThrows(
             NullPointerException.class,
             () -> testStream.leftJoin(
                 testGlobalTable,
                 MockMapper.selectValueMapper(),
-                null,
+                    (ValueJoiner<? super String, ? super String, ?>) null,

Review comment:
       indention

##########
File path: streams/src/test/java/org/apache/kafka/streams/kstream/internals/KStreamImplValueJoinerWithKeyTest.java
##########
@@ -0,0 +1,229 @@
+/*
+ * 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.internals;
+
+import org.apache.kafka.common.serialization.IntegerSerializer;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.serialization.StringDeserializer;
+import org.apache.kafka.common.serialization.StringSerializer;
+import org.apache.kafka.streams.KeyValue;
+import org.apache.kafka.streams.StreamsBuilder;
+import org.apache.kafka.streams.TestInputTopic;
+import org.apache.kafka.streams.TestOutputTopic;
+import org.apache.kafka.streams.TopologyTestDriver;
+import org.apache.kafka.streams.kstream.Consumed;
+import org.apache.kafka.streams.kstream.GlobalKTable;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.Joined;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KTable;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.ValueJoinerWithKey;
+import org.apache.kafka.test.StreamsTestUtils;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+import static java.time.Duration.ofMillis;
+import static org.junit.Assert.assertEquals;
+
+public class KStreamImplValueJoinerWithKeyTest {
+
+    private KStream<String, Integer> leftStream;
+    private KStream<String, Integer> rightStream;
+    private KTable<String, Integer> ktable;
+    private GlobalKTable<String, Integer> globalKTable;
+    private StreamsBuilder builder;
+
+    private final Properties props = StreamsTestUtils.getStreamsConfig(Serdes.String(), Serdes.String());
+    private final String leftTopic = "left";
+    private final String rightTopic = "right";
+    private final String ktableTopic = "ktableTopic";
+    private final String globalTopic = "globalTopic";
+    private final String outputTopic = "joined-result";
+
+    private final ValueJoinerWithKey<String, Integer, Integer, String> valueJoinerWithKey =
+        (key, lv, rv) -> key + ":" + (lv + (rv == null ? 0 : rv));
+    private final JoinWindows joinWindows = JoinWindows.of(ofMillis(100));
+    private final StreamJoined<String, Integer, Integer> streamJoined =
+            StreamJoined.with(Serdes.String(), Serdes.Integer(), Serdes.Integer());
+    private final Joined<String, Integer, Integer> joined =
+            Joined.with(Serdes.String(), Serdes.Integer(), Serdes.Integer());
+    private final KeyValueMapper<String, Integer, String> keyValueMapper =
+        (k, v) -> k;
+
+    @Before
+    public void setup() {
+        builder = new StreamsBuilder();
+        leftStream = builder.stream(leftTopic, Consumed.with(Serdes.String(), Serdes.Integer()));
+        rightStream = builder.stream(rightTopic, Consumed.with(Serdes.String(), Serdes.Integer()));
+        ktable = builder.table(ktableTopic, Consumed.with(Serdes.String(), Serdes.Integer()));
+        globalKTable = builder.globalTable(globalTopic, Consumed.with(Serdes.String(), Serdes.Integer()));
+    }
+
+    @Test
+    public void shouldIncludeKeyInStreamSteamJoinResults() {
+        leftStream.join(
+                rightStream,
+                valueJoinerWithKey,
+                joinWindows,
+                streamJoined
+        ).to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));
+        // Left KV A, 3, Right KV A, 5
+        runJoinTopology(builder,
+                Collections.singletonList(KeyValue.pair("A", "A:5")),
+                false,
+                rightTopic
+        );
+    }
+
+    @Test
+    public void shouldIncludeKeyInStreamLeftJoinResults() {
+        leftStream.leftJoin(
+                rightStream,
+                valueJoinerWithKey,
+                joinWindows,
+                streamJoined
+        ).to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));
+        // Left KV A, 3, Right KV A, 5
+        // TTD pipes records to left stream first, then right
+        // with TTD there's no caching, so join emits immediately with "A, 3, null" then "A, 3, 5"
+        final List<KeyValue<String, String>> expectedResults = Arrays.asList(KeyValue.pair("A", "A:3"), KeyValue.pair("A", "A:5"));
+        runJoinTopology(builder,
+                expectedResults,
+                false,
+                rightTopic
+        );
+    }
+
+    @Test
+    public void shouldIncludeKeyInStreamOuterJoinResults() {
+        leftStream.outerJoin(
+                rightStream,
+                valueJoinerWithKey,
+                joinWindows,
+                streamJoined
+        ).to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));
+
+        // Left KV A, 3, Right KV A, 5
+        // TTD pipes records to left stream first, then right
+        // with TTD there's no caching, so join emits immediately with "A, 3, null" then "A, 3, 5"
+        final List<KeyValue<String, String>> expectedResults = Arrays.asList(KeyValue.pair("A", "A:3"), KeyValue.pair("A", "A:5"));
+        runJoinTopology(builder,
+                expectedResults,
+                false,
+                rightTopic
+        );
+    }
+
+    @Test
+    public void shouldIncludeKeyInStreamTableJoinResults() {
+        leftStream.join(
+            ktable,
+            valueJoinerWithKey,
+            joined
+        ).to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));
+        // Left KV A, 3, Table KV A, 5
+        runJoinTopology(builder,
+                Collections.singletonList(KeyValue.pair("A", "A:5")),
+                true,
+                ktableTopic
+        );
+    }
+
+    @Test
+    public void shouldIncludeKeyInStreamTableLeftJoinResults() {
+        leftStream.leftJoin(
+            ktable,
+            valueJoinerWithKey,
+            joined
+        ).to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));
+        // Left KV A, 3, Table KV A, 5

Review comment:
       Similar to above: should we send one more left record with key `C`?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [kafka] bbejeck merged pull request #10150: KAFKA-3745: Add access to read-only key in value joiner

Posted by GitBox <gi...@apache.org>.
bbejeck merged pull request #10150:
URL: https://github.com/apache/kafka/pull/10150


   


-- 
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:
users@infra.apache.org



[GitHub] [kafka] bbejeck commented on pull request #10150: KAFKA-3745: Add access to read-only key in value joiner

Posted by GitBox <gi...@apache.org>.
bbejeck commented on pull request #10150:
URL: https://github.com/apache/kafka/pull/10150#issuecomment-803000216


   Java 11 failed with `org.apache.kafka.connect.integration.RebalanceSourceConnectorsIntegrationTest.testMultipleWorkersRejoining`


-- 
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:
users@infra.apache.org



[GitHub] [kafka] bbejeck commented on pull request #10150: KAFKA-3745: Add access to read-only key in value joiner

Posted by GitBox <gi...@apache.org>.
bbejeck commented on pull request #10150:
URL: https://github.com/apache/kafka/pull/10150#issuecomment-803228133


   Java 8 failed with `org.apache.kafka.clients.consumer.KafkaConsumerTest.testReturnRecordsDuringRebalance()`


-- 
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:
users@infra.apache.org



[GitHub] [kafka] bbejeck commented on a change in pull request #10150: KAFKA-3745: Add access to read-only key in value joiner

Posted by GitBox <gi...@apache.org>.
bbejeck commented on a change in pull request #10150:
URL: https://github.com/apache/kafka/pull/10150#discussion_r594678897



##########
File path: streams/src/main/java/org/apache/kafka/streams/kstream/KStream.java
##########
@@ -1315,15 +1315,15 @@ void to(final TopicNameExtractor<K, V> topicExtractor,
                                  final JoinWindows windows);
 
     /**
-     * Join records of this stream with another {@code KStream}'s records using windowed inner equi join using the

Review comment:
       >I guess you actually inserted this a copy from above with slight modification only.
   
   Yes, I wanted to keep everything in the same order.  I'm not sure how to handle how the diffs get rendered in this situation




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [kafka] bbejeck commented on pull request #10150: KAFKA-3745: Add access to read-only key in value joiner

Posted by GitBox <gi...@apache.org>.
bbejeck commented on pull request #10150:
URL: https://github.com/apache/kafka/pull/10150#issuecomment-782651197


   Failures unrelated
   
   ```
   Build / JDK 11 / org.apache.kafka.connect.integration.InternalTopicsIntegrationTest.testCreateInternalTopicsWithDefaultSettings
   Build / JDK 15 / org.apache.kafka.connect.integration.RebalanceSourceConnectorsIntegrationTest.testMultipleWorkersRejoining
   ```


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [kafka] bbejeck commented on pull request #10150: KAFKA-3745: Add access to read-only key in value joiner

Posted by GitBox <gi...@apache.org>.
bbejeck commented on pull request #10150:
URL: https://github.com/apache/kafka/pull/10150#issuecomment-781501884


   \cc @cadonna for review as well


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [kafka] bbejeck commented on a change in pull request #10150: KAFKA-3745: Add access to read-only key in value joiner

Posted by GitBox <gi...@apache.org>.
bbejeck commented on a change in pull request #10150:
URL: https://github.com/apache/kafka/pull/10150#discussion_r594665281



##########
File path: streams/src/test/java/org/apache/kafka/streams/kstream/internals/KStreamImplValueJoinerWithKeyTest.java
##########
@@ -0,0 +1,229 @@
+/*
+ * 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.internals;
+
+import org.apache.kafka.common.serialization.IntegerSerializer;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.serialization.StringDeserializer;
+import org.apache.kafka.common.serialization.StringSerializer;
+import org.apache.kafka.streams.KeyValue;
+import org.apache.kafka.streams.StreamsBuilder;
+import org.apache.kafka.streams.TestInputTopic;
+import org.apache.kafka.streams.TestOutputTopic;
+import org.apache.kafka.streams.TopologyTestDriver;
+import org.apache.kafka.streams.kstream.Consumed;
+import org.apache.kafka.streams.kstream.GlobalKTable;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.Joined;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KTable;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.ValueJoinerWithKey;
+import org.apache.kafka.test.StreamsTestUtils;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+import static java.time.Duration.ofMillis;
+import static org.junit.Assert.assertEquals;
+
+public class KStreamImplValueJoinerWithKeyTest {
+
+    private KStream<String, Integer> leftStream;
+    private KStream<String, Integer> rightStream;
+    private KTable<String, Integer> ktable;
+    private GlobalKTable<String, Integer> globalKTable;
+    private StreamsBuilder builder;
+
+    private final Properties props = StreamsTestUtils.getStreamsConfig(Serdes.String(), Serdes.String());
+    private final String leftTopic = "left";
+    private final String rightTopic = "right";
+    private final String ktableTopic = "ktableTopic";
+    private final String globalTopic = "globalTopic";
+    private final String outputTopic = "joined-result";
+
+    private final ValueJoinerWithKey<String, Integer, Integer, String> valueJoinerWithKey =
+        (key, lv, rv) -> key + ":" + (lv + (rv == null ? 0 : rv));
+    private final JoinWindows joinWindows = JoinWindows.of(ofMillis(100));
+    private final StreamJoined<String, Integer, Integer> streamJoined =
+            StreamJoined.with(Serdes.String(), Serdes.Integer(), Serdes.Integer());
+    private final Joined<String, Integer, Integer> joined =
+            Joined.with(Serdes.String(), Serdes.Integer(), Serdes.Integer());
+    private final KeyValueMapper<String, Integer, String> keyValueMapper =
+        (k, v) -> k;
+
+    @Before
+    public void setup() {
+        builder = new StreamsBuilder();
+        leftStream = builder.stream(leftTopic, Consumed.with(Serdes.String(), Serdes.Integer()));
+        rightStream = builder.stream(rightTopic, Consumed.with(Serdes.String(), Serdes.Integer()));
+        ktable = builder.table(ktableTopic, Consumed.with(Serdes.String(), Serdes.Integer()));
+        globalKTable = builder.globalTable(globalTopic, Consumed.with(Serdes.String(), Serdes.Integer()));
+    }
+
+    @Test
+    public void shouldIncludeKeyInStreamSteamJoinResults() {
+        leftStream.join(
+                rightStream,
+                valueJoinerWithKey,
+                joinWindows,
+                streamJoined
+        ).to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));
+        // Left KV A, 3, Right KV A, 5
+        runJoinTopology(builder,
+                Collections.singletonList(KeyValue.pair("A", "A:5")),
+                false,
+                rightTopic
+        );
+    }
+
+    @Test
+    public void shouldIncludeKeyInStreamLeftJoinResults() {
+        leftStream.leftJoin(
+                rightStream,
+                valueJoinerWithKey,
+                joinWindows,
+                streamJoined
+        ).to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));
+        // Left KV A, 3, Right KV A, 5
+        // TTD pipes records to left stream first, then right
+        // with TTD there's no caching, so join emits immediately with "A, 3, null" then "A, 3, 5"
+        final List<KeyValue<String, String>> expectedResults = Arrays.asList(KeyValue.pair("A", "A:3"), KeyValue.pair("A", "A:5"));
+        runJoinTopology(builder,
+                expectedResults,
+                false,
+                rightTopic
+        );
+    }
+
+    @Test
+    public void shouldIncludeKeyInStreamOuterJoinResults() {
+        leftStream.outerJoin(
+                rightStream,
+                valueJoinerWithKey,
+                joinWindows,
+                streamJoined
+        ).to(outputTopic, Produced.with(Serdes.String(), Serdes.String()));
+
+        // Left KV A, 3, Right KV A, 5

Review comment:
       SGTM




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [kafka] bbejeck commented on pull request #10150: KAFKA-3745: Add access to read-only key in value joiner

Posted by GitBox <gi...@apache.org>.
bbejeck commented on pull request #10150:
URL: https://github.com/apache/kafka/pull/10150#issuecomment-782288891


   Java 11 passed
   Java 8 and Java 15 failed with 
   ```
   JDK 15 
     org.apache.kafka.connect.integration.InternalTopicsIntegrationTest.testCreateInternalTopicsWithFewerReplicasThanBrokers
   JDK 8 
     org.apache.kafka.connect.integration.InternalTopicsIntegrationTest.testCreateInternalTopicsWithFewerReplicasThanBrokers
     kafka.api.ConsumerBounceTest.testClose()
   org.apache.kafka.streams.integration.KTableKTableForeignKeyInnerJoinMultiIntegrationTest.shouldInnerJoinMultiPartitionQueryable
   
   ```
   


----------------------------------------------------------------
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:
users@infra.apache.org