You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "Dippatel98 (via GitHub)" <gi...@apache.org> on 2025/07/31 20:32:44 UTC
[PR] Fix: Dedup input list of Topics/TopicPartitions in KafkaIO [beam]
Dippatel98 opened a new pull request, #35758:
URL: https://github.com/apache/beam/pull/35758
Deduplicate the list of input Topics/TopicPartitions passed into KafkaIO Read. If duplicate topic partitions end up on different splits, then there will be overlapping assignments for the consumer group which is not supported by Kafka.
------------------------
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
- [ ] Mention the appropriate issue in your description (for example: `addresses #123`), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
- [ ] Update `CHANGES.md` with noteworthy changes.
- [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
GitHub Actions Tests Status (on master branch)
------------------------------------------------------------------------------------------------
[](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI or the [workflows README](https://github.com/apache/beam/blob/master/.github/workflows/README.md) to see a list of phrases to trigger workflows.
--
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.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix: Dedup input list of Topics/TopicPartitions in KafkaIO [beam]
Posted by "johnjcasey (via GitHub)" <gi...@apache.org>.
johnjcasey merged PR #35758:
URL: https://github.com/apache/beam/pull/35758
--
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.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix: Dedup input list of Topics/TopicPartitions in KafkaIO [beam]
Posted by "Dippatel98 (via GitHub)" <gi...@apache.org>.
Dippatel98 commented on code in PR #35758:
URL: https://github.com/apache/beam/pull/35758#discussion_r2248144721
##########
sdks/java/io/kafka/src/main/java/org/apache/beam/sdk/io/kafka/KafkaIO.java:
##########
@@ -1648,6 +1650,24 @@ private void warnAboutUnsafeConfigurations(PBegin input) {
}
}
+ private Read<K, V> deduplicateTopics(Read<K, V> kafkaRead) {
+ if (getTopics() != null && getTopics().size() > 0) {
+ List<String> topics = getTopics();
+ return kafkaRead
+ .toBuilder()
+ .setTopics(topics.stream().distinct().collect(Collectors.toList()))
+ .build();
+ }
+ if (getTopicPartitions() != null && getTopicPartitions().size() > 0) {
+ List<TopicPartition> topicPartitions = getTopicPartitions();
+ return kafkaRead
+ .toBuilder()
+ .setTopicPartitions(topicPartitions.stream().distinct().collect(Collectors.toList()))
+ .build();
+ }
+ return kafkaRead;
+ }
Review Comment:
Done
--
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.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix: Dedup input list of Topics/TopicPartitions in KafkaIO [beam]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #35758:
URL: https://github.com/apache/beam/pull/35758#discussion_r2246325586
##########
sdks/java/io/kafka/src/main/java/org/apache/beam/sdk/io/kafka/KafkaIO.java:
##########
@@ -1648,6 +1650,24 @@ private void warnAboutUnsafeConfigurations(PBegin input) {
}
}
+ private Read<K, V> deduplicateTopics(Read<K, V> kafkaRead) {
+ if (getTopics() != null && getTopics().size() > 0) {
+ List<String> topics = getTopics();
+ return kafkaRead
+ .toBuilder()
+ .setTopics(topics.stream().distinct().collect(Collectors.toList()))
+ .build();
+ }
+ if (getTopicPartitions() != null && getTopicPartitions().size() > 0) {
+ List<TopicPartition> topicPartitions = getTopicPartitions();
+ return kafkaRead
+ .toBuilder()
+ .setTopicPartitions(topicPartitions.stream().distinct().collect(Collectors.toList()))
+ .build();
+ }
+ return kafkaRead;
+ }
Review Comment:

This method can be made more efficient. Currently, it may call `getTopics()` and `getTopicPartitions()` multiple times and creates a new `Read` object even if the input list contains no duplicates.
You can improve this by:
1. Storing the result of `getTopics()` and `getTopicPartitions()` in a local variable to avoid redundant calls.
2. Only creating a new `Read` object if duplicates were actually found and removed.
Here's a suggested implementation:
```java
private Read<K, V> deduplicateTopics(Read<K, V> kafkaRead) {
final List<String> topics = getTopics();
if (topics != null && !topics.isEmpty()) {
final List<String> distinctTopics = topics.stream().distinct().collect(Collectors.toList());
if (topics.size() == distinctTopics.size()) {
return kafkaRead;
}
return kafkaRead.toBuilder().setTopics(distinctTopics).build();
}
final List<TopicPartition> topicPartitions = getTopicPartitions();
if (topicPartitions != null && !topicPartitions.isEmpty()) {
final List<TopicPartition> distinctTopicPartitions =
topicPartitions.stream().distinct().collect(Collectors.toList());
if (topicPartitions.size() == distinctTopicPartitions.size()) {
return kafkaRead;
}
return kafkaRead.toBuilder().setTopicPartitions(distinctTopicPartitions).build();
}
return kafkaRead;
}
```
--
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.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix: Dedup input list of Topics/TopicPartitions in KafkaIO [beam]
Posted by "johnjcasey (via GitHub)" <gi...@apache.org>.
johnjcasey commented on code in PR #35758:
URL: https://github.com/apache/beam/pull/35758#discussion_r2246351437
##########
sdks/java/io/kafka/src/main/java/org/apache/beam/sdk/io/kafka/KafkaIO.java:
##########
@@ -1648,6 +1650,24 @@ private void warnAboutUnsafeConfigurations(PBegin input) {
}
}
+ private Read<K, V> deduplicateTopics(Read<K, V> kafkaRead) {
+ if (getTopics() != null && getTopics().size() > 0) {
+ List<String> topics = getTopics();
+ return kafkaRead
+ .toBuilder()
+ .setTopics(topics.stream().distinct().collect(Collectors.toList()))
+ .build();
+ }
+ if (getTopicPartitions() != null && getTopicPartitions().size() > 0) {
+ List<TopicPartition> topicPartitions = getTopicPartitions();
+ return kafkaRead
+ .toBuilder()
+ .setTopicPartitions(topicPartitions.stream().distinct().collect(Collectors.toList()))
+ .build();
+ }
+ return kafkaRead;
+ }
Review Comment:
Feel free to do this, its probably 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.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix: Dedup input list of Topics/TopicPartitions in KafkaIO [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35758:
URL: https://github.com/apache/beam/pull/35758#issuecomment-3141640768
Assigning reviewers:
R: @ahmedabu98 for label java.
R: @johnjcasey for label kafka.
Note: If you would like to opt out of this review, comment `assign to next reviewer`.
Available commands:
- `stop reviewer notifications` - opt out of the automated review tooling
- `remind me after tests pass` - tag the comment author after tests pass
- `waiting on author` - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)
The PR bot will only process comments in the main thread (not review comments).
--
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.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org