Skip to content

[Python] Keep Nexmark Query 1 bid prices as integers - #40548

Merged
Abacn merged 5 commits into
apache:masterfrom
raams95:fix-nexmark-query1-integer-price
Oct 15, 2026
Merged

Abacn merged 5 commits into
apache:masterfrom
raams95:fix-nexmark-query1-integer-price

Conversation

@raams95

@raams95 raams95 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #24678

Python Nexmark Query 1 converts bid prices with bid.price * 0.89, which turns the price into a float. BidCoder writes the price with VarIntCoderImpl, so encoding the converted bid fails with:

TypeError: unsupported operand type(s) for &: 'float' and 'int'

The Java version of the query does integer math, (bid.price * 89) / 100. This change does the same in Python with (bid.price * 89) // 100, so the result is still an int and matches the Java output.

This also re-enables Query 1 in the Python Nexmark Direct postcommit, which had excluded it because of this issue.

Testing: ran the Nexmark suite locally the same way the Direct postcommit does (Java Nexmark to generate 100,000 events, then the Python launcher on DirectRunner). Query 1 fails on master with the error above and passes with this change; queries 0 and 2 give the same results with and without it.


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123 or fixes #456).
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement. (Not needed, small change.)

See the Contributor Guide for more tips on how to make review process smoother.

Query 1 multiplied the bid price by a float, so the converted Bid could
not be encoded by BidCoder, which writes the price as a varint. Use the
same integer arithmetic as the Java Query 1.

Fixes apache#24678
@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @tvalentyn for label python.

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

@Abacn

Abacn commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution. The fix sounds valid, however Nexmark benchmarks has been unmaintained for long and old issues may be out-of-date. If still interested:

  • Nexmark suite itself is a test, it's redundant to write a test for a test, and we need the suite itself fixed, therefore
  • could you please run the Nexmark test suite locally with Query 1 re-enabled?

@raams95

raams95 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, makes sense. I removed the unit test and re-enabled Query 1 in beam_PostCommit_Python_Nexmark_Direct.yml.

I ran the suite locally the same way that workflow does: Java Nexmark (:sdks:java:testing:nexmark:run, DirectRunner, SMOKE, 100,000 events) to generate the event file, then the Python launcher on it with DirectRunner.

Query master this PR
0 100000 in, 100000 out 100000 in, 100000 out
1 fails 100000 in, 92000 out
2 100000 in, 351 out 100000 in, 351 out

On master, Query 1 fails with:

TypeError: unsupported operand type(s) for &: 'float' and 'int' [while running 'ConvertToEuro']
  ... nexmark_model.py, line 201, in encode_to_stream
    self._int_coder_impl.encode_to_stream(value.price, stream, True)

One thing I noticed: the Python launcher logs "Discarding unparseable args" for --suite=SMOKE, --enforce_encodability and --enforce_immutability, so those flags don't take effect there (same in CI). The failure above happens anyway, because the coder encodes the bids.

@github-actions github-actions Bot added the build label Oct 13, 2026

@Abacn Abacn 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.

LGTM after resolving merge conflict

Comment thread CHANGES.md Outdated
* (Python) `Duration` built from float seconds now rounds to the nearest microsecond instead of truncating, which could lose a microsecond ([#40263](https://github.com/apache/beam/issues/40263)).
* (Python) `ReadFromText` with `escapechar` no longer skips a delimiter that directly follows an escaped delimiter, which merged two records into one ([#40459](https://github.com/apache/beam/issues/40459)).
* (Python) DataFrame API: `agg` with a list that includes `'count'` or `'size'` now labels those rows `count`/`size` instead of `sum` ([#40504](https://github.com/apache/beam/issues/40504)).
* (Python) Nexmark Query 1 now keeps bid prices as integers, so its output can be encoded by `BidCoder` ([#24678](https://github.com/apache/beam/issues/24678)).

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.

We can skip CHANGES.md as this is a test-only change

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.

I mean we don't add items to CHANGES.md for test-only change

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.

Done, removed the entry.

@raams95

raams95 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks! Merged master and resolved the CHANGES.md conflict.

@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.90%. Comparing base (76f6e6d) to head (49fb288).
⚠️ Report is 178 commits behind head on master.

Additional details and impacted files
@@              Coverage Diff              @@
##             master   #40548       +/-   ##
=============================================
+ Coverage     56.16%   79.90%   +23.73%     
=============================================
  Files          1124      488      -636     
  Lines        178336    82384    -95952     
  Branches       1489        0     -1489     
=============================================
- Hits         100170    65829    -34341     
+ Misses        75645    16555    -59090     
+ Partials       2521        0     -2521     
Flag Coverage Δ
go ?
java ?
python 79.90% <ø> (+0.34%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Abacn
Abacn merged commit ebe23f3 into apache:master Oct 15, 2026
90 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.

[Bug]: Python Nexmark Query 1 is broken unsupported operand & float and int

2 participants