Skip to content

Name the grouping key in PAssert.GroupGlobally - #41734

Open
harshilv17 wants to merge 2 commits into
apache:masterfrom
harshilv17:fix/18257-passert-grouping-key
Open

harshilv17 wants to merge 2 commits into
apache:masterfrom
harshilv17:fix/18257-passert-grouping-key

Conversation

@harshilv17

@harshilv17 harshilv17 commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #18257.

PAssert.GroupGlobally grouped every element under a local final int combinedKey = 42;. When debugging ValidatesRunner tests the bare 42 shows up in the grouped KV elements and reads as if it meant something. It is now a documented private static final String SINGLETON_KEY = "PAssert-global-key" on GroupGlobally, and the grouped collections are KV<String, ...> instead of KV<Integer, ...>.

Ran PAssertTest locally with JDK 17, including its 26 NeedsRunner tests on the direct runner (:runners:direct-java:needsRunnerTests); compileJava and checkstyleMain are clean.

  • Small/focused contribution (ICLA not required).
  • Mentions the issue (Fixes #18257).
  • CHANGES.md: not needed, no behavior change.

PAssert grouped every element under the bare literal 42, which reads as
if the value mattered when debugging ValidatesRunner tests. Make it a
documented SINGLETON_KEY constant. The value is unchanged.

Fixes apache#18257
@github-actions github-actions Bot added java core size/s S: 10-49 lines changed labels Nov 28, 2026

@github-actions github-actions Bot left a comment

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.

📋 Review Summary

This PR extracts the local variable combinedKey = 42 in PAssert.GroupGlobally into a private static final int SINGLETON_KEY = 42 constant. However, this does not actually address the root cause of #18257 (originally BEAM-1854), which is that the runtime key value 42 itself causes confusion when inspecting keyed elements while debugging ValidatesRunner tests.

🔍 General Feedback

  • In BEAM-1854, the reporter noted that seeing 42 as the key during runtime debugging of ValidatesRunner tests is confusing, and suggested replacing the integer key 42 with a descriptive string key such as "PAssert-global-key" (updating the corresponding PCollection<KV<String, ...>> types in GroupGlobally). Simply renaming the variable in source code while keeping the runtime value 42 leaves the debugging experience unchanged.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

* The single key all elements are grouped under so the assertion sees them together. Its value
* has no meaning.
*/
private static final int SINGLETON_KEY = 42;

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.

🟠 High: Per the original issue context in BEAM-1854, the confusion when debugging ValidatesRunner tests comes from seeing the runtime key value 42 in KV<Integer, ...> elements during pipeline execution, rather than the local variable name in PAssert.java.

As suggested by the issue author in BEAM-1854, please replace the integer 42 with a self-explanatory string constant (e.g., "PAssert-global-key") and update the corresponding KV<Integer, ...> type parameters in GroupGlobally#expand to KV<String, ...>.

Suggested change
private static final int SINGLETON_KEY = 42;
private static final String SINGLETON_KEY = "PAssert-global-key";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, the value is what shows up in the elements. Changed in the latest commit: SINGLETON_KEY is now the string "PAssert-global-key" and GroupGlobally uses KV<String, ...> throughout. PAssertTest (including its 26 NeedsRunner tests on the direct runner) passes.

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @damccorm for label java.
Backup reviewer: kennknowles (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

This pull request likely touches a core component ("core" label). Please review with scrutiny.

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

The confusion in apache#18257 comes from seeing the key 42 in the elements of a
running pipeline. Key GroupGlobally on the string "PAssert-global-key"
instead, so the grouped elements say what they are.
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.

Replace the magic number 42 in PAssert.

1 participant