Skip to content

Commit a0e2714

Browse files
authored
[KafkaIO] Remove beam_fn_api requirement for dynamic reads (#39735)
1 parent 22b73bb commit a0e2714

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
## Bugfixes
8282

8383
* (Python) Fixed incorrect profiler options handling on portable runners ([#39613](https://github.com/apache/beam/issues/39613)).
84+
* (Java) KafkaIO dynamic reads no longer require the obsolete `beam_fn_api` experiment ([#29998](https://github.com/apache/beam/issues/29998)).
8485

8586
## Security Fixes
8687

sdks/java/io/kafka/src/main/java/org/apache/beam/sdk/io/kafka/KafkaIO.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,18 +1651,13 @@ public PCollection<KafkaRecord<K, V>> expand(PBegin input) {
16511651
checkArgument(
16521652
getConsumerConfig().get(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG) != null,
16531653
"withBootstrapServers() is required");
1654-
// With dynamic read, we no longer require providing topic/partition during pipeline
1655-
// construction time. But it requires enabling beam_fn_api.
1654+
// With dynamic read, topics and partitions are discovered during pipeline execution.
16561655
if (!isDynamicRead()) {
16571656
checkArgument(
16581657
(getTopics() != null && getTopics().size() > 0)
16591658
|| (getTopicPartitions() != null && getTopicPartitions().size() > 0)
16601659
|| getTopicPattern() != null,
16611660
"Either withTopic(), withTopics(), withTopicPartitions() or withTopicPattern() is required");
1662-
} else {
1663-
checkArgument(
1664-
ExperimentalOptions.hasExperiment(input.getPipeline().getOptions(), "beam_fn_api"),
1665-
"Kafka Dynamic Read requires enabling experiment beam_fn_api.");
16661661
}
16671662
checkArgument(getKeyDeserializerProvider() != null, "withKeyDeserializer() is required");
16681663
checkArgument(getValueDeserializerProvider() != null, "withValueDeserializer() is required");

sdks/java/io/kafka/src/test/java/org/apache/beam/sdk/io/kafka/KafkaIOReadImplementationCompatibilityTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package org.apache.beam.sdk.io.kafka;
1919

20+
import static org.apache.beam.sdk.io.kafka.KafkaIOReadImplementationCompatibility.KafkaIOReadImplementation.SDF;
2021
import static org.apache.beam.sdk.io.kafka.KafkaIOTest.mkKafkaReadTransformWithOffsetDedup;
2122
import static org.hamcrest.MatcherAssert.assertThat;
2223
import static org.hamcrest.Matchers.containsInAnyOrder;
@@ -30,6 +31,7 @@
3031
import java.util.function.Function;
3132
import java.util.stream.Collectors;
3233
import java.util.stream.Stream;
34+
import org.apache.beam.sdk.Pipeline;
3335
import org.apache.beam.sdk.PipelineResult;
3436
import org.apache.beam.sdk.io.kafka.KafkaIOReadImplementationCompatibility.KafkaIOReadProperties;
3537
import org.apache.beam.sdk.io.kafka.KafkaIOTest.ValueAsTimestampFn;
@@ -162,6 +164,26 @@ public void testReadTransformCreationWithSdfImplementationBoundProperty() {
162164
assertThat(Lineage.query(r.metrics(), Lineage.Type.SOURCE), containsInAnyOrder(expect));
163165
}
164166

167+
@Test
168+
public void testDynamicReadUsesSdfWithoutBeamFnApiExperiment() {
169+
KafkaIO.Read<Integer, Long> read =
170+
KafkaIOTest.mkKafkaReadTransform(
171+
1000,
172+
null,
173+
new ValueAsTimestampFn(),
174+
false, /* redistribute */
175+
false, /* allowDuplicates */
176+
0, /* numKeys */
177+
null, /* offsetDeduplication */
178+
null, /* topics */
179+
null /* redistributeByRecordKey */)
180+
.withDynamicRead(Duration.standardMinutes(1));
181+
182+
assertThat(
183+
KafkaIOReadImplementationCompatibility.getCompatibility(read).supportsOnly(SDF), is(true));
184+
Pipeline.create().apply(read);
185+
}
186+
165187
@Test
166188
public void testReadTransformCreationWithBothImplementationBoundProperties() {
167189
thrown.expect(IllegalStateException.class);

0 commit comments

Comments
 (0)