Skip to content

[runners-flink] Use index-based version comparison in flink_runner.gradle#38272

Open
tkaymak wants to merge 4 commits intoapache:masterfrom
tkaymak:flink-runner-version-comparison
Open

[runners-flink] Use index-based version comparison in flink_runner.gradle#38272
tkaymak wants to merge 4 commits intoapache:masterfrom
tkaymak:flink-runner-version-comparison

Conversation

@tkaymak
Copy link
Copy Markdown
Contributor

@tkaymak tkaymak commented Apr 23, 2026

Summary

Promised follow-up to @Abacn from PR #38233 review (issue comment 2026-04-17), where the same lex-comparison bug was flagged in spark_runner.gradle and asked to be split into a separate PR for the Flink side.

runners/flink/flink_runner.gradle resolves previous_versions (the list
of older Flink majors whose source-overrides should be merged into the
current build) via lexicographic string comparison against flink_major:

def previous_versions = all_versions.findAll { it < flink_major }

This breaks for the current flink_versions=1.17,1.18,1.19,1.20,2.0 because
lexicographic ordering disagrees with semantic ordering whenever a two-digit
minor crosses a single-digit boundary.

Impact today

flink_major Computed previous_versions Correct
1.17 [] []
1.18 ["1.17", "1.20"] ["1.17"]
1.19 ["1.17", "1.18", "1.20"] ["1.17", "1.18"]
1.20 [] ["1.17", "1.18", "1.19"]
2.0 ["1.17", "1.18", "1.19", "1.20"] same ✓

Concretely:

  • 1.18 and 1.19 builds erroneously pull in runners/flink/1.20/src/main/java/.../DoFnOperator.java as a "previous" override. If that file relies on Flink 1.20+ APIs, those builds would fail to compile.
  • 1.20 builds drop the 1.19 test overrides (MemoryStateBackendWrapper, StreamSources). Both classes also exist in the shared base, so 1.20's tests use the shared-base versions today; whether that's correct depends on whether the 1.19 overrides exist precisely because the shared-base versions don't compile against the 1.19+ test API.

Fix

Mirror the Spark approach landed in #38233 (runners/spark/spark_runner.gradle):

  • Compute flink_major_index = all_versions.indexOf(flink_major) and derive previous_versions as all_versions.subList(0, flink_major_index).
  • Throw a clear GradleException if flink_major isn't listed in flink_versions (today the buggy path silently produced []).
  • Update use_override to (flink_major_index > 0), matching the Spark formulation.
  • Trim whitespace from each flink_versions entry, defensive against flink_versions=1.17, 1.18, ... style.

…adle

`previous_versions` was computed by lexicographic string comparison
against `flink_major`:

    def previous_versions = all_versions.findAll { it < flink_major }

This breaks for `flink_versions=1.17,1.18,1.19,1.20,2.0` (the current
gradle.properties value) because lexicographic ordering disagrees with
semantic ordering whenever a two-digit minor crosses a single-digit
boundary. Concretely, today this resolves to:

    flink_major=1.17 -> []                              (correct)
    flink_major=1.18 -> ["1.17", "1.20"]                (wrong; should be ["1.17"])
    flink_major=1.19 -> ["1.17", "1.18", "1.20"]        (wrong; should be ["1.17", "1.18"])
    flink_major=1.20 -> []                              (wrong; should be ["1.17", "1.18", "1.19"])
    flink_major=2.0  -> ["1.17", "1.18", "1.19", "1.20"](correct)

The 1.18 and 1.19 builds therefore pick up
`runners/flink/1.20/src/main/java/.../DoFnOperator.java` as a "previous"
override, and the 1.20 build loses the 1.19 test overrides
(MemoryStateBackendWrapper, StreamSources).

Replace the lex compare with index lookup against `flink_versions`,
exactly like spark_runner.gradle does (PR apache#38233). Also:

- Trim whitespace from each entry (defensive against
  `flink_versions=1.17, 1.18, ...`).
- Throw a clear GradleException if `flink_major` isn't listed in
  `flink_versions`, instead of silently producing an empty
  `previous_versions` list.
- Update `use_override` to derive from the same index, mirroring the
  Spark version.
@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 addresses a critical bug in the Flink runner's build configuration where version comparison was performed using string-based logic. This caused incorrect identification of previous versions when minor versions reached double digits, leading to erroneous source code overrides during compilation. The changes align the Flink runner's build logic with the Spark runner's approach by utilizing list indices for version ordering, ensuring build stability across different Flink versions.

Highlights

  • Version Comparison Logic: Replaced lexicographic string comparison with index-based lookup in the flink_versions list to correctly handle semantic versioning, specifically for two-digit minor versions.
  • Error Handling: Added a GradleException to explicitly fail if the current flink_major is not found within the defined flink_versions list.
  • Input Sanitization: Added whitespace trimming to flink_versions entries to prevent configuration errors.

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

@tkaymak tkaymak changed the title [WIP][runners-flink] Use index-based version comparison in flink_runner.gradle [runners-flink] Use index-based version comparison in flink_runner.gradle Apr 23, 2026
@tkaymak tkaymak marked this pull request as ready for review April 23, 2026 14:09
@tkaymak
Copy link
Copy Markdown
Contributor Author

tkaymak commented Apr 23, 2026

/gemini review

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 modifies the Flink runner's Gradle build script to use list indices for version ordering instead of string comparisons, which correctly handles two-digit minor versions. The review feedback recommends improving the robustness of the version lookup by trimming the input version string and simplifying the code by removing a redundant ternary operator when calculating previous versions.

Comment thread runners/flink/flink_runner.gradle Outdated
Comment thread runners/flink/flink_runner.gradle Outdated
- Trim/stringify flink_major before indexOf so command-line / GString
  values match the trimmed all_versions entries.
- Drop redundant ternary on previous_versions; subList(0, 0) is already
  empty when flink_major is the first listed version.
@tkaymak
Copy link
Copy Markdown
Contributor Author

tkaymak commented Apr 23, 2026

/gemini review

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 updates the Flink runner's Gradle configuration to correctly handle version ordering. It replaces string-based version comparisons with index-based lookups from the flink_versions list, ensuring that two-digit minor versions (e.g., 1.20) are correctly identified relative to earlier versions. Additionally, it adds validation to ensure the specified flink_major version exists in the configuration. I have no feedback to provide.

@tkaymak
Copy link
Copy Markdown
Contributor Author

tkaymak commented Apr 23, 2026

assign set of reviewers

@github-actions
Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @damccorm 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).

@damccorm
Copy link
Copy Markdown
Contributor

@Abacn would you mind taking a look at this one since you have context?

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.

2 participants