You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "junaiddshaukat (via GitHub)" <gi...@apache.org> on 2026/07/08 19:17:06 UTC
[PR] [GSoC 2026] Kafka Streams runner #39192: bounded Read (primitive) + Create support [beam]
junaiddshaukat opened a new pull request, #39249:
URL: https://github.com/apache/beam/pull/39249
Adds bounded primitive Read support to the Kafka Streams runner, which also
unblocks `Create.of(...)` with two or more elements.
Part of #39192 (this is part b -- Create support -- implemented via the Read
primitive, as discussed with je-ik).
Background: `Create` of 2+ elements expands to `Read.from(CreateSource)`, which
in the Fn API path becomes a splittable-DoFn bounded read the runner can't run
yet. Per the Slack discussion with je-ik, this uses the deprecated primitive
Read instead, and forces the conversion so it doesn't depend on the
`use_deprecated_read` experiment.
What's here:
- `ReadTranslator` -- parses the ReadPayload, deserializes the BoundedSource, and
adds a bootstrap source + `ReadProcessor` + a fired-state store, same shape as
the Impulse translator.
- `ReadProcessor` -- reads the whole source once on a one-shot wall-clock
punctuator, emitting one data payload per element and a terminal MAX watermark.
Single-instance, no splitting for now.
- `KafkaStreamsTestRunner.translate` applies
`SplittableParDo.convertReadBasedSplittableDoFnsToPrimitiveReads`
unconditionally, so `Read.Bounded` (and Create) translate as the primitive Read
regardless of the experiment.
- Tests: `ReadTest` (CountingSource) and `CreateTest` (`Create.of(1, 2, 3)`),
both end to end through the in-process EMBEDDED harness.
One thing that bit me -- the wire form. A primitive Read hands the runner decoded
Java objects, but the SDK harness input receiver expects each element in the
runner-side wire form: a raw object for a coder the runner knows (VarLongCoder
worked directly), but a length-prefixed byte[] for one it doesn't (VarIntCoder
threw `ClassCastException: Integer cannot be cast to [B`). Stage-to-stage edges
already carry that form because harness outputs are decoded with the runner-side
wire coder; the source edge doesn't. So `ReadProcessor` transcodes each element
through the SDK-side wire coder (encode) and back through the runner-side wire
coder (decode) -- they're byte-compatible by construction and this also handles
nested coders.
Follow-up, not in this PR: the force-conversion is wired into the test translate
path (`KafkaStreamsTestRunner`) only. The production runner's translate path
still needs the same conversion (or `use_deprecated_read` defaulted in its
options). I can do that here or as a separate change -- whichever you prefer.
--
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] [GSoC 2026] Kafka Streams runner: bounded Read (primitive) + Create support [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #39249:
URL: https://github.com/apache/beam/pull/39249#issuecomment-4918957204
Assigning reviewers:
R: @jrmccluskey added as fallback since no labels match configuration
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
Re: [PR] [GSoC 2026] Kafka Streams runner: bounded Read (primitive) + Create support [beam]
Posted by "je-ik (via GitHub)" <gi...@apache.org>.
je-ik commented on PR #39249:
URL: https://github.com/apache/beam/pull/39249#issuecomment-4923048095
> There is a bit misunderstanding how Read works. The flow is: a) call source.split b) shuffle the splits so that we read in parallel c) call createReader only on the split sources
>
> From the implementation point, the initial source.split can be driven by preceding Impulse. We can then fan-out all Impulses together so that we need only single "fake" topic.
Ah! I see, we plan to add the splitting in follow-up issue.
--
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] [GSoC 2026] Kafka Streams runner #39192: bounded Read (primitive) + Create support [beam]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on PR #39249:
URL: https://github.com/apache/beam/pull/39249#issuecomment-4918398775
## Summary of Changes
Hello, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces support for bounded primitive `Read` operations in the Kafka Streams runner. By implementing a custom translator and processor, the runner can now handle `Read.Bounded` transforms directly, which also resolves issues with `Create` transforms containing multiple elements that previously failed due to unsupported splittable-DoFn expansion. The implementation ensures reliable element emission and watermark handling while maintaining compatibility with the SDK harness wire format.
### Highlights
* **Primitive Read Support**: Added a `ReadTranslator` and `ReadProcessor` to implement bounded primitive `Read` support in the Kafka Streams runner, bypassing the need for splittable-DoFn expansion.
* **Create Support**: Enabled support for `Create.of(...)` with two or more elements by leveraging the new primitive `Read` implementation.
* **Test Coverage**: Added end-to-end tests `ReadTest` and `CreateTest` to verify the new functionality within the EMBEDDED harness.
<details>
<summary><b>New Features</b></summary>
🧠You can now enable **Memory** (public preview) to help **Gemini Code Assist** learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. **Click [here](https://codeassist.google/code-review/login) to enable Memory in your admin console.**
</details>
<details>
<summary><b>Using Gemini Code Assist</b></summary>
<br>
The full guide for Gemini Code Assist can be found on our [documentation page](https://developers.google.com/gemini-code-assist/docs/review-github-code), here are some quick tips.
<b>Invoking Gemini</b>
You can request assistance from Gemini at any point by creating a comment using either `/gemini <command>` or `@gemini-code-assist <command>`. Below is a summary of the supported commands on the current page.
Feature | Command | Description
--- | --- | ---
Code Review | `/gemini review` | Performs a code review for the current pull request in its current state.
Pull Request Summary | `/gemini summary` | Provides a summary of the current pull request in its current state.
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help | `/gemini help` | Displays a list of available commands.
<b>Customization</b>
To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a `.gemini/` folder in the base of the repository. Detailed instructions can be found [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
<b>Limitations & Feedback</b>
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up [here](https://google.qualtrics.com/jfe/form/SV_2cyuGuTWsEw84yG).
</details>
[^1]: Review the [Privacy Notices](https://policies.google.com/privacy), [Generative AI Prohibited Use Policy](https://policies.google.com/terms/generative-ai/use-policy), [Terms of Service](https://policies.google.com/terms), and learn how to configure Gemini Code Assist in GitHub [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github). Gemini can make mistakes, so double check it and [use code with caution](https://support.google.com/legal/answer/13505487).
--
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] [GSoC 2026] Kafka Streams runner: bounded Read (primitive) + Create support [beam]
Posted by "je-ik (via GitHub)" <gi...@apache.org>.
je-ik commented on code in PR #39249:
URL: https://github.com/apache/beam/pull/39249#discussion_r3549961744
##########
runners/kafka-streams/src/main/java/org/apache/beam/runners/kafka/streams/translation/KafkaStreamsTranslationContext.java:
##########
@@ -34,6 +35,12 @@ public class KafkaStreamsTranslationContext {
/** Prefix for the per-job bootstrap topic Impulse reads from. */
private static final String IMPULSE_BOOTSTRAP_TOPIC_PREFIX = "__beam_impulse_";
+ /** Prefix for the per-transform bootstrap topic a primitive Read reads from. */
+ private static final String READ_BOOTSTRAP_TOPIC_PREFIX = "__beam_read_";
Review Comment:
Do we need per-transform topic? Could we just fan-out the single element to all Impulse transforms? It would require analysis of the Pipeline DAG before translation and then maybe add s single ParDo that will do the fan-out? Or it could be done implicitly.
--
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] [GSoC 2026] Kafka Streams runner: bounded Read (primitive) + Create support [beam]
Posted by "junaiddshaukat (via GitHub)" <gi...@apache.org>.
junaiddshaukat commented on code in PR #39249:
URL: https://github.com/apache/beam/pull/39249#discussion_r3546769860
##########
runners/kafka-streams/src/main/java/org/apache/beam/runners/kafka/streams/translation/ReadProcessor.java:
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.beam.runners.kafka.streams.translation;
+
+import java.io.IOException;
+import java.time.Duration;
+import org.apache.beam.sdk.coders.Coder;
+import org.apache.beam.sdk.coders.CoderException;
+import org.apache.beam.sdk.io.BoundedSource;
+import org.apache.beam.sdk.io.BoundedSource.BoundedReader;
+import org.apache.beam.sdk.options.PipelineOptions;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+import org.apache.beam.sdk.util.CoderUtils;
+import org.apache.beam.sdk.values.WindowedValue;
+import org.apache.beam.sdk.values.WindowedValues;
+import org.apache.kafka.streams.processor.Cancellable;
+import org.apache.kafka.streams.processor.PunctuationType;
+import org.apache.kafka.streams.processor.api.Processor;
+import org.apache.kafka.streams.processor.api.ProcessorContext;
+import org.apache.kafka.streams.processor.api.Record;
+import org.apache.kafka.streams.state.KeyValueStore;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Kafka Streams {@link Processor} implementing Beam's deprecated primitive {@code Read}
+ * (beam:transform:read:v1) over a {@link BoundedSource}.
+ *
+ * <p>For each task instance, reads the whole {@link BoundedSource} once and emits, in order:
+ *
+ * <ol>
+ * <li>One {@link KStreamsPayload#data data} payload per source element, each wrapping a {@link
+ * WindowedValue} in the {@link org.apache.beam.sdk.transforms.windowing.GlobalWindow} at the
+ * element's own event time (from {@link BoundedReader#getCurrentTimestamp()}).
+ * <li>A {@link KStreamsPayload#watermark watermark} payload at {@link
+ * BoundedWindow#TIMESTAMP_MAX_VALUE} telling downstream transforms the source is done.
+ * </ol>
+ *
+ * <p><b>Wire form.</b> Unlike Impulse (whose element is already an opaque {@code byte[]}), a Read
+ * produces <em>decoded</em> Java objects. Downstream {@link ExecutableStageProcessor} feeds
+ * whatever it receives straight into the SDK harness, whose main-input receiver expects each
+ * element in the runner-side wire form — a raw object for a model coder, but a length-prefixed
+ * {@code byte[]} for a coder the runner does not know (e.g. {@code VarIntCoder}). Stage-to-stage
+ * edges already carry that wire form because harness outputs are decoded with the runner-side wire
+ * coder; this processor reproduces it for the source edge by transcoding each element through the
+ * SDK-side wire coder (encode) and back through the runner-side wire coder (decode). The two are
+ * byte-compatible by construction, so the transcode yields exactly the object the receiver expects,
+ * nesting and all.
+ *
+ * <p>This mirrors {@link ImpulseProcessor}: a persistent state store records whether the elements
+ * have already been emitted so task restarts do not duplicate them, while the terminal watermark is
+ * re-emitted on every restart so downstream watermark holds still release after recovery. The
+ * trigger is a wall-clock punctuator scheduled on {@link #init} so the processor fires even though
+ * its bootstrap source topic is empty.
+ *
+ * <p>The source is read in a single instance with no splitting — parallelism across the source's
+ * splits arrives with the topic-based shuffle work (#18479). Kafka Streams disallows negative
+ * record timestamps, so each forwarded {@link Record} carries the Unix epoch ({@code 0L}); the Beam
+ * event time lives inside the {@link WindowedValue}.
+ */
+class ReadProcessor<T> implements Processor<byte[], byte[], byte[], KStreamsPayload<?>> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ReadProcessor.class);
+
+ /** Sole entry in the state store; the value tracks whether this processor has already emitted. */
+ static final String FIRED_KEY = "fired";
+
+ /** How soon after {@link #init} the punctuator first fires. */
+ private static final Duration PUNCTUATION_DELAY = Duration.ofMillis(50);
+
+ private final BoundedSource<T> source;
+ private final PipelineOptions options;
+ // Encodes a raw WindowedValue<T> as the SDK harness would on the wire (length-prefixing the
+ // element coder if the runner does not know it); the runner-side coder then decodes it into the
+ // wire form the downstream stage's input receiver expects. See the class javadoc.
+ private final Coder<WindowedValue<T>> sdkWireCoder;
+ private final Coder<WindowedValue<?>> runnerWireCoder;
+ private final String stateStoreName;
+ private final String transformId;
+
+ private @Nullable ProcessorContext<byte[], KStreamsPayload<?>> context;
+ private @Nullable KeyValueStore<String, Boolean> firedStore;
+ private @Nullable Cancellable scheduledPunctuator;
+
+ ReadProcessor(
+ BoundedSource<T> source,
+ PipelineOptions options,
Review Comment:
Done. One note, the class is org.apache.beam.runners.core.construction.SerializablePipelineOptions, not sdk.options. Worth flagging that KS builds the topology per instance and doesn't serialize processor suppliers, so this wasn't a live NotSerializableException, but the wrapper is cheap and keeps the captured state serializable.
--
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] [GSoC 2026] Kafka Streams runner: bounded Read (primitive) + Create support [beam]
Posted by "je-ik (via GitHub)" <gi...@apache.org>.
je-ik merged PR #39249:
URL: https://github.com/apache/beam/pull/39249
--
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] [GSoC 2026] Kafka Streams runner: bounded Read (primitive) + Create support [beam]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #39249:
URL: https://github.com/apache/beam/pull/39249#discussion_r3546669701
##########
runners/kafka-streams/src/main/java/org/apache/beam/runners/kafka/streams/translation/ReadProcessor.java:
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.beam.runners.kafka.streams.translation;
+
+import java.io.IOException;
+import java.time.Duration;
+import org.apache.beam.sdk.coders.Coder;
+import org.apache.beam.sdk.coders.CoderException;
+import org.apache.beam.sdk.io.BoundedSource;
+import org.apache.beam.sdk.io.BoundedSource.BoundedReader;
+import org.apache.beam.sdk.options.PipelineOptions;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+import org.apache.beam.sdk.util.CoderUtils;
+import org.apache.beam.sdk.values.WindowedValue;
+import org.apache.beam.sdk.values.WindowedValues;
+import org.apache.kafka.streams.processor.Cancellable;
+import org.apache.kafka.streams.processor.PunctuationType;
+import org.apache.kafka.streams.processor.api.Processor;
+import org.apache.kafka.streams.processor.api.ProcessorContext;
+import org.apache.kafka.streams.processor.api.Record;
+import org.apache.kafka.streams.state.KeyValueStore;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Kafka Streams {@link Processor} implementing Beam's deprecated primitive {@code Read}
+ * (beam:transform:read:v1) over a {@link BoundedSource}.
+ *
+ * <p>For each task instance, reads the whole {@link BoundedSource} once and emits, in order:
+ *
+ * <ol>
+ * <li>One {@link KStreamsPayload#data data} payload per source element, each wrapping a {@link
+ * WindowedValue} in the {@link org.apache.beam.sdk.transforms.windowing.GlobalWindow} at the
+ * element's own event time (from {@link BoundedReader#getCurrentTimestamp()}).
+ * <li>A {@link KStreamsPayload#watermark watermark} payload at {@link
+ * BoundedWindow#TIMESTAMP_MAX_VALUE} telling downstream transforms the source is done.
+ * </ol>
+ *
+ * <p><b>Wire form.</b> Unlike Impulse (whose element is already an opaque {@code byte[]}), a Read
+ * produces <em>decoded</em> Java objects. Downstream {@link ExecutableStageProcessor} feeds
+ * whatever it receives straight into the SDK harness, whose main-input receiver expects each
+ * element in the runner-side wire form — a raw object for a model coder, but a length-prefixed
+ * {@code byte[]} for a coder the runner does not know (e.g. {@code VarIntCoder}). Stage-to-stage
+ * edges already carry that wire form because harness outputs are decoded with the runner-side wire
+ * coder; this processor reproduces it for the source edge by transcoding each element through the
+ * SDK-side wire coder (encode) and back through the runner-side wire coder (decode). The two are
+ * byte-compatible by construction, so the transcode yields exactly the object the receiver expects,
+ * nesting and all.
+ *
+ * <p>This mirrors {@link ImpulseProcessor}: a persistent state store records whether the elements
+ * have already been emitted so task restarts do not duplicate them, while the terminal watermark is
+ * re-emitted on every restart so downstream watermark holds still release after recovery. The
+ * trigger is a wall-clock punctuator scheduled on {@link #init} so the processor fires even though
+ * its bootstrap source topic is empty.
+ *
+ * <p>The source is read in a single instance with no splitting — parallelism across the source's
+ * splits arrives with the topic-based shuffle work (#18479). Kafka Streams disallows negative
+ * record timestamps, so each forwarded {@link Record} carries the Unix epoch ({@code 0L}); the Beam
+ * event time lives inside the {@link WindowedValue}.
+ */
+class ReadProcessor<T> implements Processor<byte[], byte[], byte[], KStreamsPayload<?>> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ReadProcessor.class);
+
+ /** Sole entry in the state store; the value tracks whether this processor has already emitted. */
+ static final String FIRED_KEY = "fired";
+
+ /** How soon after {@link #init} the punctuator first fires. */
+ private static final Duration PUNCTUATION_DELAY = Duration.ofMillis(50);
+
+ private final BoundedSource<T> source;
+ private final PipelineOptions options;
+ // Encodes a raw WindowedValue<T> as the SDK harness would on the wire (length-prefixing the
+ // element coder if the runner does not know it); the runner-side coder then decodes it into the
+ // wire form the downstream stage's input receiver expects. See the class javadoc.
+ private final Coder<WindowedValue<T>> sdkWireCoder;
+ private final Coder<WindowedValue<?>> runnerWireCoder;
+ private final String stateStoreName;
+ private final String transformId;
+
+ private @Nullable ProcessorContext<byte[], KStreamsPayload<?>> context;
+ private @Nullable KeyValueStore<String, Boolean> firedStore;
+ private @Nullable Cancellable scheduledPunctuator;
+
+ ReadProcessor(
+ BoundedSource<T> source,
+ PipelineOptions options,
Review Comment:

Update the constructor parameter to accept `SerializablePipelineOptions`.
```suggestion
org.apache.beam.sdk.options.SerializablePipelineOptions options,
```
##########
runners/kafka-streams/src/main/java/org/apache/beam/runners/kafka/streams/translation/ReadProcessor.java:
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.beam.runners.kafka.streams.translation;
+
+import java.io.IOException;
+import java.time.Duration;
+import org.apache.beam.sdk.coders.Coder;
+import org.apache.beam.sdk.coders.CoderException;
+import org.apache.beam.sdk.io.BoundedSource;
+import org.apache.beam.sdk.io.BoundedSource.BoundedReader;
+import org.apache.beam.sdk.options.PipelineOptions;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+import org.apache.beam.sdk.util.CoderUtils;
+import org.apache.beam.sdk.values.WindowedValue;
+import org.apache.beam.sdk.values.WindowedValues;
+import org.apache.kafka.streams.processor.Cancellable;
+import org.apache.kafka.streams.processor.PunctuationType;
+import org.apache.kafka.streams.processor.api.Processor;
+import org.apache.kafka.streams.processor.api.ProcessorContext;
+import org.apache.kafka.streams.processor.api.Record;
+import org.apache.kafka.streams.state.KeyValueStore;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Kafka Streams {@link Processor} implementing Beam's deprecated primitive {@code Read}
+ * (beam:transform:read:v1) over a {@link BoundedSource}.
+ *
+ * <p>For each task instance, reads the whole {@link BoundedSource} once and emits, in order:
+ *
+ * <ol>
+ * <li>One {@link KStreamsPayload#data data} payload per source element, each wrapping a {@link
+ * WindowedValue} in the {@link org.apache.beam.sdk.transforms.windowing.GlobalWindow} at the
+ * element's own event time (from {@link BoundedReader#getCurrentTimestamp()}).
+ * <li>A {@link KStreamsPayload#watermark watermark} payload at {@link
+ * BoundedWindow#TIMESTAMP_MAX_VALUE} telling downstream transforms the source is done.
+ * </ol>
+ *
+ * <p><b>Wire form.</b> Unlike Impulse (whose element is already an opaque {@code byte[]}), a Read
+ * produces <em>decoded</em> Java objects. Downstream {@link ExecutableStageProcessor} feeds
+ * whatever it receives straight into the SDK harness, whose main-input receiver expects each
+ * element in the runner-side wire form — a raw object for a model coder, but a length-prefixed
+ * {@code byte[]} for a coder the runner does not know (e.g. {@code VarIntCoder}). Stage-to-stage
+ * edges already carry that wire form because harness outputs are decoded with the runner-side wire
+ * coder; this processor reproduces it for the source edge by transcoding each element through the
+ * SDK-side wire coder (encode) and back through the runner-side wire coder (decode). The two are
+ * byte-compatible by construction, so the transcode yields exactly the object the receiver expects,
+ * nesting and all.
+ *
+ * <p>This mirrors {@link ImpulseProcessor}: a persistent state store records whether the elements
+ * have already been emitted so task restarts do not duplicate them, while the terminal watermark is
+ * re-emitted on every restart so downstream watermark holds still release after recovery. The
+ * trigger is a wall-clock punctuator scheduled on {@link #init} so the processor fires even though
+ * its bootstrap source topic is empty.
+ *
+ * <p>The source is read in a single instance with no splitting — parallelism across the source's
+ * splits arrives with the topic-based shuffle work (#18479). Kafka Streams disallows negative
+ * record timestamps, so each forwarded {@link Record} carries the Unix epoch ({@code 0L}); the Beam
+ * event time lives inside the {@link WindowedValue}.
+ */
+class ReadProcessor<T> implements Processor<byte[], byte[], byte[], KStreamsPayload<?>> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ReadProcessor.class);
+
+ /** Sole entry in the state store; the value tracks whether this processor has already emitted. */
+ static final String FIRED_KEY = "fired";
+
+ /** How soon after {@link #init} the punctuator first fires. */
+ private static final Duration PUNCTUATION_DELAY = Duration.ofMillis(50);
+
+ private final BoundedSource<T> source;
+ private final PipelineOptions options;
Review Comment:

`PipelineOptions` is not serializable. Since `ReadProcessor` is instantiated inside a serialized `ProcessorSupplier` lambda (or is itself serialized), storing `PipelineOptions` directly will cause a `NotSerializableException` in distributed environments. Use `SerializablePipelineOptions` instead.
```suggestion
private final org.apache.beam.sdk.options.SerializablePipelineOptions options;
```
##########
runners/kafka-streams/src/main/java/org/apache/beam/runners/kafka/streams/translation/ReadProcessor.java:
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.beam.runners.kafka.streams.translation;
+
+import java.io.IOException;
+import java.time.Duration;
+import org.apache.beam.sdk.coders.Coder;
+import org.apache.beam.sdk.coders.CoderException;
+import org.apache.beam.sdk.io.BoundedSource;
+import org.apache.beam.sdk.io.BoundedSource.BoundedReader;
+import org.apache.beam.sdk.options.PipelineOptions;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+import org.apache.beam.sdk.util.CoderUtils;
+import org.apache.beam.sdk.values.WindowedValue;
+import org.apache.beam.sdk.values.WindowedValues;
+import org.apache.kafka.streams.processor.Cancellable;
+import org.apache.kafka.streams.processor.PunctuationType;
+import org.apache.kafka.streams.processor.api.Processor;
+import org.apache.kafka.streams.processor.api.ProcessorContext;
+import org.apache.kafka.streams.processor.api.Record;
+import org.apache.kafka.streams.state.KeyValueStore;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Kafka Streams {@link Processor} implementing Beam's deprecated primitive {@code Read}
+ * (beam:transform:read:v1) over a {@link BoundedSource}.
+ *
+ * <p>For each task instance, reads the whole {@link BoundedSource} once and emits, in order:
+ *
+ * <ol>
+ * <li>One {@link KStreamsPayload#data data} payload per source element, each wrapping a {@link
+ * WindowedValue} in the {@link org.apache.beam.sdk.transforms.windowing.GlobalWindow} at the
+ * element's own event time (from {@link BoundedReader#getCurrentTimestamp()}).
+ * <li>A {@link KStreamsPayload#watermark watermark} payload at {@link
+ * BoundedWindow#TIMESTAMP_MAX_VALUE} telling downstream transforms the source is done.
+ * </ol>
+ *
+ * <p><b>Wire form.</b> Unlike Impulse (whose element is already an opaque {@code byte[]}), a Read
+ * produces <em>decoded</em> Java objects. Downstream {@link ExecutableStageProcessor} feeds
+ * whatever it receives straight into the SDK harness, whose main-input receiver expects each
+ * element in the runner-side wire form — a raw object for a model coder, but a length-prefixed
+ * {@code byte[]} for a coder the runner does not know (e.g. {@code VarIntCoder}). Stage-to-stage
+ * edges already carry that wire form because harness outputs are decoded with the runner-side wire
+ * coder; this processor reproduces it for the source edge by transcoding each element through the
+ * SDK-side wire coder (encode) and back through the runner-side wire coder (decode). The two are
+ * byte-compatible by construction, so the transcode yields exactly the object the receiver expects,
+ * nesting and all.
+ *
+ * <p>This mirrors {@link ImpulseProcessor}: a persistent state store records whether the elements
+ * have already been emitted so task restarts do not duplicate them, while the terminal watermark is
+ * re-emitted on every restart so downstream watermark holds still release after recovery. The
+ * trigger is a wall-clock punctuator scheduled on {@link #init} so the processor fires even though
+ * its bootstrap source topic is empty.
+ *
+ * <p>The source is read in a single instance with no splitting — parallelism across the source's
+ * splits arrives with the topic-based shuffle work (#18479). Kafka Streams disallows negative
+ * record timestamps, so each forwarded {@link Record} carries the Unix epoch ({@code 0L}); the Beam
+ * event time lives inside the {@link WindowedValue}.
+ */
+class ReadProcessor<T> implements Processor<byte[], byte[], byte[], KStreamsPayload<?>> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ReadProcessor.class);
+
+ /** Sole entry in the state store; the value tracks whether this processor has already emitted. */
+ static final String FIRED_KEY = "fired";
+
+ /** How soon after {@link #init} the punctuator first fires. */
+ private static final Duration PUNCTUATION_DELAY = Duration.ofMillis(50);
Review Comment:

To avoid creating a new empty byte array for every single element in the source (and for watermarks), we should define a reusable `static final` constant for the empty byte array.
```suggestion
private static final Duration PUNCTUATION_DELAY = Duration.ofMillis(50);
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
```
##########
runners/kafka-streams/src/main/java/org/apache/beam/runners/kafka/streams/translation/ReadProcessor.java:
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.beam.runners.kafka.streams.translation;
+
+import java.io.IOException;
+import java.time.Duration;
+import org.apache.beam.sdk.coders.Coder;
+import org.apache.beam.sdk.coders.CoderException;
+import org.apache.beam.sdk.io.BoundedSource;
+import org.apache.beam.sdk.io.BoundedSource.BoundedReader;
+import org.apache.beam.sdk.options.PipelineOptions;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+import org.apache.beam.sdk.util.CoderUtils;
+import org.apache.beam.sdk.values.WindowedValue;
+import org.apache.beam.sdk.values.WindowedValues;
+import org.apache.kafka.streams.processor.Cancellable;
+import org.apache.kafka.streams.processor.PunctuationType;
+import org.apache.kafka.streams.processor.api.Processor;
+import org.apache.kafka.streams.processor.api.ProcessorContext;
+import org.apache.kafka.streams.processor.api.Record;
+import org.apache.kafka.streams.state.KeyValueStore;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Kafka Streams {@link Processor} implementing Beam's deprecated primitive {@code Read}
+ * (beam:transform:read:v1) over a {@link BoundedSource}.
+ *
+ * <p>For each task instance, reads the whole {@link BoundedSource} once and emits, in order:
+ *
+ * <ol>
+ * <li>One {@link KStreamsPayload#data data} payload per source element, each wrapping a {@link
+ * WindowedValue} in the {@link org.apache.beam.sdk.transforms.windowing.GlobalWindow} at the
+ * element's own event time (from {@link BoundedReader#getCurrentTimestamp()}).
+ * <li>A {@link KStreamsPayload#watermark watermark} payload at {@link
+ * BoundedWindow#TIMESTAMP_MAX_VALUE} telling downstream transforms the source is done.
+ * </ol>
+ *
+ * <p><b>Wire form.</b> Unlike Impulse (whose element is already an opaque {@code byte[]}), a Read
+ * produces <em>decoded</em> Java objects. Downstream {@link ExecutableStageProcessor} feeds
+ * whatever it receives straight into the SDK harness, whose main-input receiver expects each
+ * element in the runner-side wire form — a raw object for a model coder, but a length-prefixed
+ * {@code byte[]} for a coder the runner does not know (e.g. {@code VarIntCoder}). Stage-to-stage
+ * edges already carry that wire form because harness outputs are decoded with the runner-side wire
+ * coder; this processor reproduces it for the source edge by transcoding each element through the
+ * SDK-side wire coder (encode) and back through the runner-side wire coder (decode). The two are
+ * byte-compatible by construction, so the transcode yields exactly the object the receiver expects,
+ * nesting and all.
+ *
+ * <p>This mirrors {@link ImpulseProcessor}: a persistent state store records whether the elements
+ * have already been emitted so task restarts do not duplicate them, while the terminal watermark is
+ * re-emitted on every restart so downstream watermark holds still release after recovery. The
+ * trigger is a wall-clock punctuator scheduled on {@link #init} so the processor fires even though
+ * its bootstrap source topic is empty.
+ *
+ * <p>The source is read in a single instance with no splitting — parallelism across the source's
+ * splits arrives with the topic-based shuffle work (#18479). Kafka Streams disallows negative
+ * record timestamps, so each forwarded {@link Record} carries the Unix epoch ({@code 0L}); the Beam
+ * event time lives inside the {@link WindowedValue}.
+ */
+class ReadProcessor<T> implements Processor<byte[], byte[], byte[], KStreamsPayload<?>> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ReadProcessor.class);
+
+ /** Sole entry in the state store; the value tracks whether this processor has already emitted. */
+ static final String FIRED_KEY = "fired";
+
+ /** How soon after {@link #init} the punctuator first fires. */
+ private static final Duration PUNCTUATION_DELAY = Duration.ofMillis(50);
+
+ private final BoundedSource<T> source;
+ private final PipelineOptions options;
+ // Encodes a raw WindowedValue<T> as the SDK harness would on the wire (length-prefixing the
+ // element coder if the runner does not know it); the runner-side coder then decodes it into the
+ // wire form the downstream stage's input receiver expects. See the class javadoc.
+ private final Coder<WindowedValue<T>> sdkWireCoder;
+ private final Coder<WindowedValue<?>> runnerWireCoder;
+ private final String stateStoreName;
+ private final String transformId;
+
+ private @Nullable ProcessorContext<byte[], KStreamsPayload<?>> context;
+ private @Nullable KeyValueStore<String, Boolean> firedStore;
+ private @Nullable Cancellable scheduledPunctuator;
+
+ ReadProcessor(
+ BoundedSource<T> source,
+ PipelineOptions options,
+ Coder<WindowedValue<T>> sdkWireCoder,
+ Coder<WindowedValue<?>> runnerWireCoder,
+ String stateStoreName,
+ String transformId) {
+ this.source = source;
+ this.options = options;
+ this.sdkWireCoder = sdkWireCoder;
+ this.runnerWireCoder = runnerWireCoder;
+ this.stateStoreName = stateStoreName;
+ this.transformId = transformId;
+ }
+
+ @Override
+ public void init(ProcessorContext<byte[], KStreamsPayload<?>> context) {
+ this.context = context;
+ this.firedStore = context.getStateStore(stateStoreName);
+ this.scheduledPunctuator =
+ context.schedule(PUNCTUATION_DELAY, PunctuationType.WALL_CLOCK_TIME, ts -> maybeFire());
+ }
+
+ @Override
+ public void process(Record<byte[], byte[]> record) {
+ // Records that happen to land on the bootstrap topic are not actual data; they just provide an
+ // extra opportunity to fire the read on restart. The state store still gates the emit.
+ maybeFire();
+ }
+
+ private void maybeFire() {
+ ProcessorContext<byte[], KStreamsPayload<?>> ctx = context;
+ KeyValueStore<String, Boolean> store = firedStore;
+ if (ctx == null || store == null) {
+ return;
+ }
+ if (Boolean.TRUE.equals(store.get(FIRED_KEY))) {
+ // Elements were already emitted in a previous task lifetime, but downstream watermark holds
+ // may still need to release after the restart — re-emit the terminal watermark and stop.
+ forwardWatermarkMax(ctx);
+ cancelPunctuator();
+ return;
+ }
+ int count = readAndForward(ctx);
+ forwardWatermarkMax(ctx);
+ store.put(FIRED_KEY, Boolean.TRUE);
+ cancelPunctuator();
+ LOG.debug("Read {} emitted {} elements and terminal watermark", transformId, count);
+ }
+
+ /** Reads the whole bounded source and forwards each element, in wire form, as a data payload. */
+ private int readAndForward(ProcessorContext<byte[], KStreamsPayload<?>> ctx) {
+ int count = 0;
+ try (BoundedReader<T> reader = source.createReader(options)) {
+ for (boolean hasElement = reader.start(); hasElement; hasElement = reader.advance()) {
+ WindowedValue<T> element =
+ WindowedValues.timestampedValueInGlobalWindow(
+ reader.getCurrent(), reader.getCurrentTimestamp());
+ // The Read output PCollection is not keyed; use an empty byte[] as a placeholder key so
+ // downstream processors that adopt the byte[]-key convention see a consistent shape.
+ ctx.forward(
+ new Record<byte[], KStreamsPayload<?>>(
+ new byte[0], KStreamsPayload.data(toRunnerWire(element)), 0L));
Review Comment:

Use the reusable `EMPTY_BYTE_ARRAY` constant instead of allocating a new `byte[0]` for every element.
```suggestion
ctx.forward(
new Record<byte[], KStreamsPayload<?>>(
EMPTY_BYTE_ARRAY, KStreamsPayload.data(toRunnerWire(element)), 0L));
```
##########
runners/kafka-streams/src/main/java/org/apache/beam/runners/kafka/streams/translation/ReadProcessor.java:
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.beam.runners.kafka.streams.translation;
+
+import java.io.IOException;
+import java.time.Duration;
+import org.apache.beam.sdk.coders.Coder;
+import org.apache.beam.sdk.coders.CoderException;
+import org.apache.beam.sdk.io.BoundedSource;
+import org.apache.beam.sdk.io.BoundedSource.BoundedReader;
+import org.apache.beam.sdk.options.PipelineOptions;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+import org.apache.beam.sdk.util.CoderUtils;
+import org.apache.beam.sdk.values.WindowedValue;
+import org.apache.beam.sdk.values.WindowedValues;
+import org.apache.kafka.streams.processor.Cancellable;
+import org.apache.kafka.streams.processor.PunctuationType;
+import org.apache.kafka.streams.processor.api.Processor;
+import org.apache.kafka.streams.processor.api.ProcessorContext;
+import org.apache.kafka.streams.processor.api.Record;
+import org.apache.kafka.streams.state.KeyValueStore;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Kafka Streams {@link Processor} implementing Beam's deprecated primitive {@code Read}
+ * (beam:transform:read:v1) over a {@link BoundedSource}.
+ *
+ * <p>For each task instance, reads the whole {@link BoundedSource} once and emits, in order:
+ *
+ * <ol>
+ * <li>One {@link KStreamsPayload#data data} payload per source element, each wrapping a {@link
+ * WindowedValue} in the {@link org.apache.beam.sdk.transforms.windowing.GlobalWindow} at the
+ * element's own event time (from {@link BoundedReader#getCurrentTimestamp()}).
+ * <li>A {@link KStreamsPayload#watermark watermark} payload at {@link
+ * BoundedWindow#TIMESTAMP_MAX_VALUE} telling downstream transforms the source is done.
+ * </ol>
+ *
+ * <p><b>Wire form.</b> Unlike Impulse (whose element is already an opaque {@code byte[]}), a Read
+ * produces <em>decoded</em> Java objects. Downstream {@link ExecutableStageProcessor} feeds
+ * whatever it receives straight into the SDK harness, whose main-input receiver expects each
+ * element in the runner-side wire form — a raw object for a model coder, but a length-prefixed
+ * {@code byte[]} for a coder the runner does not know (e.g. {@code VarIntCoder}). Stage-to-stage
+ * edges already carry that wire form because harness outputs are decoded with the runner-side wire
+ * coder; this processor reproduces it for the source edge by transcoding each element through the
+ * SDK-side wire coder (encode) and back through the runner-side wire coder (decode). The two are
+ * byte-compatible by construction, so the transcode yields exactly the object the receiver expects,
+ * nesting and all.
+ *
+ * <p>This mirrors {@link ImpulseProcessor}: a persistent state store records whether the elements
+ * have already been emitted so task restarts do not duplicate them, while the terminal watermark is
+ * re-emitted on every restart so downstream watermark holds still release after recovery. The
+ * trigger is a wall-clock punctuator scheduled on {@link #init} so the processor fires even though
+ * its bootstrap source topic is empty.
+ *
+ * <p>The source is read in a single instance with no splitting — parallelism across the source's
+ * splits arrives with the topic-based shuffle work (#18479). Kafka Streams disallows negative
+ * record timestamps, so each forwarded {@link Record} carries the Unix epoch ({@code 0L}); the Beam
+ * event time lives inside the {@link WindowedValue}.
+ */
+class ReadProcessor<T> implements Processor<byte[], byte[], byte[], KStreamsPayload<?>> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ReadProcessor.class);
+
+ /** Sole entry in the state store; the value tracks whether this processor has already emitted. */
+ static final String FIRED_KEY = "fired";
+
+ /** How soon after {@link #init} the punctuator first fires. */
+ private static final Duration PUNCTUATION_DELAY = Duration.ofMillis(50);
+
+ private final BoundedSource<T> source;
+ private final PipelineOptions options;
+ // Encodes a raw WindowedValue<T> as the SDK harness would on the wire (length-prefixing the
+ // element coder if the runner does not know it); the runner-side coder then decodes it into the
+ // wire form the downstream stage's input receiver expects. See the class javadoc.
+ private final Coder<WindowedValue<T>> sdkWireCoder;
+ private final Coder<WindowedValue<?>> runnerWireCoder;
+ private final String stateStoreName;
+ private final String transformId;
+
+ private @Nullable ProcessorContext<byte[], KStreamsPayload<?>> context;
+ private @Nullable KeyValueStore<String, Boolean> firedStore;
+ private @Nullable Cancellable scheduledPunctuator;
+
+ ReadProcessor(
+ BoundedSource<T> source,
+ PipelineOptions options,
+ Coder<WindowedValue<T>> sdkWireCoder,
+ Coder<WindowedValue<?>> runnerWireCoder,
+ String stateStoreName,
+ String transformId) {
+ this.source = source;
+ this.options = options;
+ this.sdkWireCoder = sdkWireCoder;
+ this.runnerWireCoder = runnerWireCoder;
+ this.stateStoreName = stateStoreName;
+ this.transformId = transformId;
+ }
+
+ @Override
+ public void init(ProcessorContext<byte[], KStreamsPayload<?>> context) {
+ this.context = context;
+ this.firedStore = context.getStateStore(stateStoreName);
+ this.scheduledPunctuator =
+ context.schedule(PUNCTUATION_DELAY, PunctuationType.WALL_CLOCK_TIME, ts -> maybeFire());
+ }
+
+ @Override
+ public void process(Record<byte[], byte[]> record) {
+ // Records that happen to land on the bootstrap topic are not actual data; they just provide an
+ // extra opportunity to fire the read on restart. The state store still gates the emit.
+ maybeFire();
+ }
+
+ private void maybeFire() {
+ ProcessorContext<byte[], KStreamsPayload<?>> ctx = context;
+ KeyValueStore<String, Boolean> store = firedStore;
+ if (ctx == null || store == null) {
+ return;
+ }
+ if (Boolean.TRUE.equals(store.get(FIRED_KEY))) {
+ // Elements were already emitted in a previous task lifetime, but downstream watermark holds
+ // may still need to release after the restart — re-emit the terminal watermark and stop.
+ forwardWatermarkMax(ctx);
+ cancelPunctuator();
+ return;
+ }
+ int count = readAndForward(ctx);
+ forwardWatermarkMax(ctx);
+ store.put(FIRED_KEY, Boolean.TRUE);
+ cancelPunctuator();
+ LOG.debug("Read {} emitted {} elements and terminal watermark", transformId, count);
+ }
+
+ /** Reads the whole bounded source and forwards each element, in wire form, as a data payload. */
+ private int readAndForward(ProcessorContext<byte[], KStreamsPayload<?>> ctx) {
+ int count = 0;
+ try (BoundedReader<T> reader = source.createReader(options)) {
+ for (boolean hasElement = reader.start(); hasElement; hasElement = reader.advance()) {
+ WindowedValue<T> element =
+ WindowedValues.timestampedValueInGlobalWindow(
+ reader.getCurrent(), reader.getCurrentTimestamp());
+ // The Read output PCollection is not keyed; use an empty byte[] as a placeholder key so
+ // downstream processors that adopt the byte[]-key convention see a consistent shape.
+ ctx.forward(
+ new Record<byte[], KStreamsPayload<?>>(
+ new byte[0], KStreamsPayload.data(toRunnerWire(element)), 0L));
+ count++;
+ }
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to read bounded source for transform " + transformId, e);
+ }
+ return count;
+ }
+
+ /** Transcodes a raw element into the runner-side wire form the SDK harness input expects. */
+ private WindowedValue<?> toRunnerWire(WindowedValue<T> element) {
+ try {
+ byte[] wireBytes = CoderUtils.encodeToByteArray(sdkWireCoder, element);
+ return CoderUtils.decodeFromByteArray(runnerWireCoder, wireBytes);
+ } catch (CoderException e) {
+ throw new RuntimeException(
+ "Failed to transcode a read element to wire form for transform " + transformId, e);
+ }
+ }
+
+ /**
+ * Forwards a terminal {@code TIMESTAMP_MAX_VALUE} watermark payload to downstream processors.
+ *
+ * <p>Read is a single-instance source, so the report is stamped as the only source partition:
+ * {@code sourcePartition=0} of {@code totalSourcePartitions=1}. Real per-partition identities
+ * arrive once the topology gains topic-based shuffle.
+ */
+ private static void forwardWatermarkMax(ProcessorContext<byte[], KStreamsPayload<?>> ctx) {
+ long maxMillis = BoundedWindow.TIMESTAMP_MAX_VALUE.getMillis();
+ ctx.forward(
+ new Record<byte[], KStreamsPayload<?>>(
+ new byte[0], KStreamsPayload.<Object>watermark(maxMillis, 0, 1), 0L));
Review Comment:

Use the reusable `EMPTY_BYTE_ARRAY` constant instead of allocating a new `byte[0]`.
```suggestion
ctx.forward(
new Record<byte[], KStreamsPayload<?>>(
EMPTY_BYTE_ARRAY, KStreamsPayload.<Object>watermark(maxMillis, 0, 1), 0L));
```
##########
runners/kafka-streams/src/main/java/org/apache/beam/runners/kafka/streams/translation/ReadProcessor.java:
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.beam.runners.kafka.streams.translation;
+
+import java.io.IOException;
+import java.time.Duration;
+import org.apache.beam.sdk.coders.Coder;
+import org.apache.beam.sdk.coders.CoderException;
+import org.apache.beam.sdk.io.BoundedSource;
+import org.apache.beam.sdk.io.BoundedSource.BoundedReader;
+import org.apache.beam.sdk.options.PipelineOptions;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+import org.apache.beam.sdk.util.CoderUtils;
+import org.apache.beam.sdk.values.WindowedValue;
+import org.apache.beam.sdk.values.WindowedValues;
+import org.apache.kafka.streams.processor.Cancellable;
+import org.apache.kafka.streams.processor.PunctuationType;
+import org.apache.kafka.streams.processor.api.Processor;
+import org.apache.kafka.streams.processor.api.ProcessorContext;
+import org.apache.kafka.streams.processor.api.Record;
+import org.apache.kafka.streams.state.KeyValueStore;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Kafka Streams {@link Processor} implementing Beam's deprecated primitive {@code Read}
+ * (beam:transform:read:v1) over a {@link BoundedSource}.
+ *
+ * <p>For each task instance, reads the whole {@link BoundedSource} once and emits, in order:
+ *
+ * <ol>
+ * <li>One {@link KStreamsPayload#data data} payload per source element, each wrapping a {@link
+ * WindowedValue} in the {@link org.apache.beam.sdk.transforms.windowing.GlobalWindow} at the
+ * element's own event time (from {@link BoundedReader#getCurrentTimestamp()}).
+ * <li>A {@link KStreamsPayload#watermark watermark} payload at {@link
+ * BoundedWindow#TIMESTAMP_MAX_VALUE} telling downstream transforms the source is done.
+ * </ol>
+ *
+ * <p><b>Wire form.</b> Unlike Impulse (whose element is already an opaque {@code byte[]}), a Read
+ * produces <em>decoded</em> Java objects. Downstream {@link ExecutableStageProcessor} feeds
+ * whatever it receives straight into the SDK harness, whose main-input receiver expects each
+ * element in the runner-side wire form — a raw object for a model coder, but a length-prefixed
+ * {@code byte[]} for a coder the runner does not know (e.g. {@code VarIntCoder}). Stage-to-stage
+ * edges already carry that wire form because harness outputs are decoded with the runner-side wire
+ * coder; this processor reproduces it for the source edge by transcoding each element through the
+ * SDK-side wire coder (encode) and back through the runner-side wire coder (decode). The two are
+ * byte-compatible by construction, so the transcode yields exactly the object the receiver expects,
+ * nesting and all.
+ *
+ * <p>This mirrors {@link ImpulseProcessor}: a persistent state store records whether the elements
+ * have already been emitted so task restarts do not duplicate them, while the terminal watermark is
+ * re-emitted on every restart so downstream watermark holds still release after recovery. The
+ * trigger is a wall-clock punctuator scheduled on {@link #init} so the processor fires even though
+ * its bootstrap source topic is empty.
+ *
+ * <p>The source is read in a single instance with no splitting — parallelism across the source's
+ * splits arrives with the topic-based shuffle work (#18479). Kafka Streams disallows negative
+ * record timestamps, so each forwarded {@link Record} carries the Unix epoch ({@code 0L}); the Beam
+ * event time lives inside the {@link WindowedValue}.
+ */
+class ReadProcessor<T> implements Processor<byte[], byte[], byte[], KStreamsPayload<?>> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ReadProcessor.class);
+
+ /** Sole entry in the state store; the value tracks whether this processor has already emitted. */
+ static final String FIRED_KEY = "fired";
+
+ /** How soon after {@link #init} the punctuator first fires. */
+ private static final Duration PUNCTUATION_DELAY = Duration.ofMillis(50);
+
+ private final BoundedSource<T> source;
+ private final PipelineOptions options;
+ // Encodes a raw WindowedValue<T> as the SDK harness would on the wire (length-prefixing the
+ // element coder if the runner does not know it); the runner-side coder then decodes it into the
+ // wire form the downstream stage's input receiver expects. See the class javadoc.
+ private final Coder<WindowedValue<T>> sdkWireCoder;
+ private final Coder<WindowedValue<?>> runnerWireCoder;
+ private final String stateStoreName;
+ private final String transformId;
+
+ private @Nullable ProcessorContext<byte[], KStreamsPayload<?>> context;
+ private @Nullable KeyValueStore<String, Boolean> firedStore;
+ private @Nullable Cancellable scheduledPunctuator;
+
+ ReadProcessor(
+ BoundedSource<T> source,
+ PipelineOptions options,
+ Coder<WindowedValue<T>> sdkWireCoder,
+ Coder<WindowedValue<?>> runnerWireCoder,
+ String stateStoreName,
+ String transformId) {
+ this.source = source;
+ this.options = options;
+ this.sdkWireCoder = sdkWireCoder;
+ this.runnerWireCoder = runnerWireCoder;
+ this.stateStoreName = stateStoreName;
+ this.transformId = transformId;
+ }
+
+ @Override
+ public void init(ProcessorContext<byte[], KStreamsPayload<?>> context) {
+ this.context = context;
+ this.firedStore = context.getStateStore(stateStoreName);
+ this.scheduledPunctuator =
+ context.schedule(PUNCTUATION_DELAY, PunctuationType.WALL_CLOCK_TIME, ts -> maybeFire());
+ }
+
+ @Override
+ public void process(Record<byte[], byte[]> record) {
+ // Records that happen to land on the bootstrap topic are not actual data; they just provide an
+ // extra opportunity to fire the read on restart. The state store still gates the emit.
+ maybeFire();
+ }
+
+ private void maybeFire() {
+ ProcessorContext<byte[], KStreamsPayload<?>> ctx = context;
+ KeyValueStore<String, Boolean> store = firedStore;
+ if (ctx == null || store == null) {
+ return;
+ }
+ if (Boolean.TRUE.equals(store.get(FIRED_KEY))) {
+ // Elements were already emitted in a previous task lifetime, but downstream watermark holds
+ // may still need to release after the restart — re-emit the terminal watermark and stop.
+ forwardWatermarkMax(ctx);
+ cancelPunctuator();
+ return;
+ }
+ int count = readAndForward(ctx);
+ forwardWatermarkMax(ctx);
+ store.put(FIRED_KEY, Boolean.TRUE);
+ cancelPunctuator();
+ LOG.debug("Read {} emitted {} elements and terminal watermark", transformId, count);
+ }
+
+ /** Reads the whole bounded source and forwards each element, in wire form, as a data payload. */
+ private int readAndForward(ProcessorContext<byte[], KStreamsPayload<?>> ctx) {
+ int count = 0;
+ try (BoundedReader<T> reader = source.createReader(options)) {
Review Comment:

Retrieve the underlying `PipelineOptions` using `options.get()`.
```suggestion
try (BoundedReader<T> reader = source.createReader(options.get())) {
```
##########
runners/kafka-streams/src/main/java/org/apache/beam/runners/kafka/streams/translation/ReadTranslator.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.beam.runners.kafka.streams.translation;
+
+import java.io.IOException;
+import org.apache.beam.model.pipeline.v1.RunnerApi;
+import org.apache.beam.model.pipeline.v1.RunnerApi.ExecutableStagePayload.WireCoderSetting;
+import org.apache.beam.runners.fnexecution.wire.WireCoders;
+import org.apache.beam.sdk.coders.Coder;
+import org.apache.beam.sdk.io.BoundedSource;
+import org.apache.beam.sdk.options.PipelineOptions;
+import org.apache.beam.sdk.util.construction.ReadTranslation;
+import org.apache.beam.sdk.util.construction.RehydratedComponents;
+import org.apache.beam.sdk.util.construction.graph.PipelineNode;
+import org.apache.beam.sdk.util.construction.graph.PipelineNode.PCollectionNode;
+import org.apache.beam.sdk.values.WindowedValue;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.Iterables;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.streams.Topology;
+import org.apache.kafka.streams.state.KeyValueBytesStoreSupplier;
+import org.apache.kafka.streams.state.Stores;
+
+/**
+ * Translates the deprecated primitive {@code Read} URN ({@code beam:transform:read:v1}) over a
+ * {@link BoundedSource}.
+ *
+ * <p>The runner forces every {@code Read.Bounded} (including the one {@code Create} of two or more
+ * elements expands to) into this primitive read before translation — see {@code
+ * KafkaStreamsTestRunner.translate}, which applies {@code
+ * SplittableParDo.convertReadBasedSplittableDoFnsToPrimitiveReads}. This deliberately avoids the
+ * default {@code BoundedSourceAsSDFWrapperFn} splittable-DoFn expansion, which the runner cannot
+ * execute yet (no SDF restriction protocol), as agreed with the mentor.
+ *
+ * <p>Adds the same three-node shape as {@link ImpulseTranslator}:
+ *
+ * <ul>
+ * <li>A {@code byte[]} source bound to a dedicated per-transform bootstrap topic (see {@link
+ * KafkaStreamsTranslationContext#getReadBootstrapTopic(String)}). Kafka Streams refuses to
+ * start a topology with no real source topic; records published to it are ignored by {@link
+ * ReadProcessor}.
+ * <li>The {@link ReadProcessor}, which reads the {@link BoundedSource} on a one-shot wall-clock
+ * punctuator and emits one data payload per element followed by a terminal watermark.
+ * <li>A per-processor persistent state store recording whether the read has already fired so task
+ * restarts do not duplicate elements.
+ * </ul>
+ *
+ * <p>The processor emits elements in the runner-side wire form the downstream stage's SDK harness
+ * expects, so it is handed the SDK-side and runner-side wire coders for the read's output
+ * PCollection (see {@link ReadProcessor} for why). Only {@link
+ * org.apache.beam.model.pipeline.v1.RunnerApi.IsBounded.Enum#BOUNDED bounded} sources are
+ * supported; {@link ReadTranslation#boundedSourceFromProto} rejects an unbounded payload.
+ */
+class ReadTranslator implements PTransformTranslator {
+
+ static final String SOURCE_SUFFIX = "-source";
+ static final String STATE_STORE_SUFFIX = "-state";
+
+ @Override
+ public void translate(
+ String transformId, RunnerApi.Pipeline pipeline, KafkaStreamsTranslationContext context) {
+ RunnerApi.PTransform transform = pipeline.getComponents().getTransformsOrThrow(transformId);
+ // Read produces exactly one output PCollection; downstream consumers are separate PTransforms
+ // whose inputs reference this PCollection id and are wired by their own translators.
+ String outputPCollectionId = Iterables.getOnlyElement(transform.getOutputsMap().values());
+ addReadNodes(
+ transformId,
+ boundedSource(transform),
+ pipeline.getComponents(),
+ outputPCollectionId,
+ context);
+ }
+
+ private static BoundedSource<?> boundedSource(RunnerApi.PTransform transform) {
+ try {
+ RunnerApi.ReadPayload payload =
+ RunnerApi.ReadPayload.parseFrom(transform.getSpec().getPayload());
+ return ReadTranslation.boundedSourceFromProto(payload);
+ } catch (IOException e) {
+ throw new RuntimeException(
+ "Failed to read the BoundedSource from transform " + transform.getUniqueName(), e);
+ }
+ }
+
+ /**
+ * Adds the source, {@link ReadProcessor}, and state store for the read. The type variable {@code
+ * T} captures the {@link BoundedSource}'s element type so the processor and its wire coders are
+ * built consistently.
+ */
+ private <T> void addReadNodes(
+ String transformId,
+ BoundedSource<T> source,
+ RunnerApi.Components components,
+ String outputPCollectionId,
+ KafkaStreamsTranslationContext context) {
+ PCollectionNode outputNode =
+ PipelineNode.pCollection(
+ outputPCollectionId, components.getPcollectionsOrThrow(outputPCollectionId));
+ Coder<WindowedValue<T>> sdkWireCoder = sdkWireCoder(outputNode, components);
+ Coder<WindowedValue<?>> runnerWireCoder = runnerWireCoder(outputNode, components);
+
+ Topology topology = context.getTopology();
+ String sourceNodeName = transformId + SOURCE_SUFFIX;
+ String stateStoreName = transformId + STATE_STORE_SUFFIX;
+ String bootstrapTopic = context.getReadBootstrapTopic(transformId);
+ PipelineOptions options = context.getPipelineOptions();
Review Comment:

Wrap the `PipelineOptions` in `SerializablePipelineOptions` before passing it to the `ReadProcessor` constructor to ensure serializability.
```suggestion
org.apache.beam.sdk.options.SerializablePipelineOptions options =
new org.apache.beam.sdk.options.SerializablePipelineOptions(context.getPipelineOptions());
```
--
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