Revert "remove processContext usage across examples (java and kotlin)"#38341
Conversation
|
Fixes #30612 |
Summary of ChangesHello, I'm Gemini Code Assist1! 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 reverts a previous large-scale refactoring that attempted to modernize Apache Beam DoFn methods by removing Highlights
🧠 New Feature in Public Preview: You can now enable Memory 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 to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize 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 Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request reverts modern Apache Beam DoFn parameter injection to the legacy ProcessContext style across numerous Java and Kotlin examples and removes the modernizer documentation. The review feedback identifies several inconsistencies introduced by this change, including redundant method signatures that mix legacy and modern parameters, and logic errors where null checks incorrectly lead to null outputs. Recommendations were made to maintain a consistent API style and simplify signatures by using direct parameter injection for PipelineOptions where appropriate.
| if (map == null) { | ||
| c.output(c.element()); | ||
| return; | ||
| } |
There was a problem hiding this comment.
The logic here is redundant and potentially problematic. If map is null, calling c.output(c.element()) will output a null value, which might cause issues with downstream transforms or coders. If the intention is to skip null elements, the method should simply return. If the intention is to pass them through, it is more efficient to use the local variable map instead of calling c.element() again.
if (map == null) {
return;
}| ProcessContext c, OutputReceiver<KV<Integer, Integer>> out) { | ||
| System.out.printf( | ||
| "Vendor: %s, Passengers: %s%n", element.getKey(), element.getValue()); | ||
| out.output(element); | ||
| "Vendor: %s, Passengers: %s%n", | ||
| c.element().getKey(), c.element().getValue()); | ||
| out.output(c.element()); |
There was a problem hiding this comment.
This method signature mixes legacy ProcessContext with the modern OutputReceiver parameter. For consistency and clarity, it is recommended to use one style. Since this PR is reverting to ProcessContext, you should use c.output() instead of the out parameter.
| ProcessContext c, OutputReceiver<KV<Integer, Integer>> out) { | |
| System.out.printf( | |
| "Vendor: %s, Passengers: %s%n", element.getKey(), element.getValue()); | |
| out.output(element); | |
| "Vendor: %s, Passengers: %s%n", | |
| c.element().getKey(), c.element().getValue()); | |
| out.output(c.element()); | |
| ProcessContext c) { | |
| System.out.printf( | |
| "Vendor: %s, Passengers: %s%n", | |
| c.element().getKey(), c.element().getValue()); | |
| c.output(c.element()); |
| public void process(@Element KV<Integer, Iterable<Row>> element, ProcessContext context) { | ||
| Iterable<Row> rows = element.getValue(); |
There was a problem hiding this comment.
Mixing @Element parameter injection with ProcessContext is redundant and inconsistent. Since ProcessContext is being used for output later in the method, it should also be used to access the element via context.element() for a consistent API usage style.
| public void process(@Element KV<Integer, Iterable<Row>> element, ProcessContext context) { | |
| Iterable<Row> rows = element.getValue(); | |
| public void process(ProcessContext context) { | |
| Iterable<Row> rows = context.element().getValue(); |
| @Element Row in, OutputReceiver<KV<ByteString, Iterable<Mutation>>> out, ProcessContext c) { | ||
| DataTokenizationOptions options = c.getPipelineOptions().as(DataTokenizationOptions.class); |
There was a problem hiding this comment.
The ProcessContext parameter is only used here to access PipelineOptions. In Apache Beam, PipelineOptions can be injected directly as a parameter to @ProcessElement. Mixing ProcessContext with modern parameters like @Element and OutputReceiver is discouraged as it makes the method signature unnecessarily complex.
public void processElement(
@Element Row in,
OutputReceiver<KV<ByteString, Iterable<Mutation>>> out,
PipelineOptions pipelineOptions) {
DataTokenizationOptions options = pipelineOptions.as(DataTokenizationOptions.class);|
|
||
| @ProcessElement | ||
| public void processElement(@Element ReadableFile file, MultiOutputReceiver outputReceiver) { | ||
| public void processElement(ProcessContext context, MultiOutputReceiver outputReceiver) { |
There was a problem hiding this comment.
This method signature contains both ProcessContext and MultiOutputReceiver. This is redundant because ProcessContext already provides the ability to output to multiple tags via context.output(tag, value). For consistency, especially in a PR reverting to legacy context usage, the MultiOutputReceiver parameter should be removed.
| public void processElement(ProcessContext context, MultiOutputReceiver outputReceiver) { | |
| public void processElement(ProcessContext context) { |
|
R: @Amar3tto cc: @stankiewicz we can roll forward after master branch getting a good commit range |
|
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment |
Reverts #37937
Large generated PR had hidden mistakes and broke tests