Abacn commented on code in PR #34258: URL: https://github.com/apache/beam/pull/34258#discussion_r2042335539
########## sdks/java/io/kafka/src/main/java/org/apache/beam/sdk/io/kafka/KafkaUnboundedSource.java: ########## @@ -100,8 +104,34 @@ public List<KafkaUnboundedSource<K, V>> split(int desiredNumSplits, PipelineOpti } } } else { + final Map<String, List<Integer>> topicsAndPartitions = new HashMap<>(); for (TopicPartition p : partitions) { - Lineage.getSources().add("kafka", ImmutableList.of(bootStrapServers, p.topic())); + topicsAndPartitions.computeIfAbsent(p.topic(), k -> new ArrayList<>()).add(p.partition()); + } + try (Consumer<?, ?> consumer = spec.getConsumerFactoryFn().apply(spec.getConsumerConfig())) { + for (Map.Entry<String, List<Integer>> e : topicsAndPartitions.entrySet()) { + final String providedTopic = e.getKey(); + final List<Integer> providedPartitions = e.getValue(); + final Set<Integer> partitionsForTopic; + try { + partitionsForTopic = + consumer.partitionsFor(providedTopic).stream() + .map(PartitionInfo::partition) + .collect(Collectors.toSet()); + for (Integer p : providedPartitions) { + checkState( + partitionsForTopic.contains(p), + "Partition " + + p + + " does not exist for topic " + + providedTopic + + ". Please check Kafka configuration."); + } + } catch (KafkaException exception) { Review Comment: This catch statement does not work as expected, because KafkaException throws outside the for. see https://github.com/apache/beam/pull/34258#issuecomment-2799855776 -- 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-unsubscr...@beam.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org