Skip to content

Revert "remove processContext usage across examples (java and kotlin)"#38341

Merged
stankiewicz merged 2 commits intomasterfrom
revert-37937-eradicate_processContext_usage_examples
May 1, 2026
Merged

Revert "remove processContext usage across examples (java and kotlin)"#38341
stankiewicz merged 2 commits intomasterfrom
revert-37937-eradicate_processContext_usage_examples

Conversation

@Abacn
Copy link
Copy Markdown
Contributor

@Abacn Abacn commented Apr 30, 2026

Reverts #37937

Large generated PR had hidden mistakes and broke tests

@Abacn
Copy link
Copy Markdown
Contributor Author

Abacn commented Apr 30, 2026

Fixes #30612

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 ProcessContext in favor of parameter injection. The revert is necessary because the previous changes introduced regressions and broke existing tests, necessitating a return to the stable, albeit more verbose, ProcessContext pattern.

Highlights

  • Revert of ProcessContext removal: This pull request reverts the changes that removed ProcessContext usage across various Java and Kotlin examples, as the previous implementation contained hidden errors and caused test failures.
  • Cleanup of unused imports: Removed unused imports related to DoFn.Element, DoFn.OutputReceiver, and DoFn.Timestamp across multiple files.

🧠 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 Assist

The 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 /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.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@Abacn Abacn mentioned this pull request Apr 30, 2026
3 tasks
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +295 to +298
if (map == null) {
c.output(c.element());
return;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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;
      }

Comment on lines +127 to +131
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());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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());

Comment on lines +202 to 203
public void process(@Element KV<Integer, Iterable<Row>> element, ProcessContext context) {
Iterable<Row> rows = element.getValue();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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();

Comment on lines +78 to +79
@Element Row in, OutputReceiver<KV<ByteString, Iterable<Mutation>>> out, ProcessContext c) {
DataTokenizationOptions options = c.getPipelineOptions().as(DataTokenizationOptions.class);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
public void processElement(ProcessContext context, MultiOutputReceiver outputReceiver) {
public void processElement(ProcessContext context) {

@Abacn
Copy link
Copy Markdown
Contributor Author

Abacn commented Apr 30, 2026

R: @Amar3tto cc: @stankiewicz we can roll forward after master branch getting a good commit range

@github-actions
Copy link
Copy Markdown
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

@stankiewicz stankiewicz merged commit e530809 into master May 1, 2026
16 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants