Skip to content

[#39900] Fix MongoDbIO read splitting to preserve non-ObjectId _id types - #39901

Open
ogiogidayo wants to merge 1 commit into
apache:masterfrom
ogiogidayo:mongodbio-non-objectid-split-39900
Open

[#39900] Fix MongoDbIO read splitting to preserve non-ObjectId _id types#39901
ogiogidayo wants to merge 1 commit into
apache:masterfrom
ogiogidayo:mongodbio-non-objectid-split-39900

Conversation

@ogiogidayo

@ogiogidayo ogiogidayo commented Aug 27, 2026

Copy link
Copy Markdown

Fixes #39900.

BoundedMongoDbSource.splitKeysToFilters formatted split boundaries unconditionally as ObjectId("..."), so collections keyed by non-ObjectId _id values (e.g. application-defined string ids, which MongoDB fully supports) failed with IllegalArgumentException: state should be: hexString has 24 characters as soon as read splitting was enabled via withBucketAuto(true) or withNumSplits(n). The AggregationQuery path (splitKeysToMatch) had the same assumption via getObjectId("_id").

This change serializes split boundaries with their actual BSON types:

  • splitKeysToFilters now builds the range filters as Documents and serializes them with Document#toJson (extended JSON). ObjectId boundaries keep producing semantically identical filters, while string/integer ids are preserved.
  • splitKeysToMatch keeps the raw _id value instead of reading it as an ObjectId. The generated $match documents for ObjectId ids are unchanged (the pre-existing expectations in testSplitIntoBucket pass without modification).

Backward compatible: no public API change. Note that testSplitIntoFilters previously asserted output that could never be parsed back (ObjectId("56") for an Integer id, which only passed because the test compared strings without parsing them); it now verifies the generated filters by parsing them. Added string-id tests for both paths.


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), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

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

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@ogiogidayo
ogiogidayo marked this pull request as ready for review August 27, 2026 09:33
splitKeysToFilters formatted split boundaries unconditionally as
ObjectId("..."), so collections keyed by non-ObjectId ids (e.g.
application-defined string ids) failed to parse the generated range
filters when splitting was enabled via bucketAuto or numSplits.
Serialize boundaries with their actual BSON types instead, and keep
the raw id type in splitKeysToMatch as well.

Fixes apache#39900
@ogiogidayo
ogiogidayo force-pushed the mongodbio-non-objectid-split-39900 branch from 0ef7358 to e152ecc Compare August 27, 2026 09:40
@ogiogidayo

Copy link
Copy Markdown
Author

assign set of reviewers

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @kennknowles for label java.

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

Thanks!

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]: MongoDbIO read splitting fails for collections with non-ObjectId _id (splitKeysToFilters hardcodes ObjectId)

2 participants