Skip to content

[yaml] - mongodb read normalization#38772

Open
derrickaw wants to merge 20 commits into
apache:masterfrom
derrickaw:20260602_readFromMongoDb
Open

[yaml] - mongodb read normalization#38772
derrickaw wants to merge 20 commits into
apache:masterfrom
derrickaw:20260602_readFromMongoDb

Conversation

@derrickaw

Copy link
Copy Markdown
Collaborator
  1. Fixes [yaml] Normalize MongoDBIO #28690
  2. Adds the ReadFromMongoDb transform for yaml

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.

arnavarora2004 and others added 10 commits June 9, 2026 13:21
Squashed draft MongoDB read connector changes from PR apache#35802.
…, and tests

- Fully implemented MongoDB read configuration and Provider with JSON schema parsing
- Enhanced MongoDbUtils with a deep BSON-to-Beam row conversion supporting all primitives, arrays, maps, and nested rows
- Added comprehensive Java unit tests for MongoDbUtils and MongoDbReadSchemaTransformProvider
- Mapped WriteToMongoDB and ReadFromMongoDB in standard_io.yaml
- Implemented end-to-end integration test verifying write/read pipeline against containerized MongoDB
…ansforms

- Standardized standard_io mappings to snake_case (error_handling, batch_size)
- Extended integration test to verify error-handling queues are empty for clean runs
@derrickaw derrickaw force-pushed the 20260602_readFromMongoDb branch from 9df8c17 to 3bec200 Compare June 9, 2026 13:21
@derrickaw

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces support for reading from MongoDB as a SchemaTransform in the Java SDK, along with exposing this capability in Python YAML pipelines. It includes configuration classes, conversion utilities between BSON Documents and Beam Rows, and corresponding unit tests. Key feedback from the review highlights a potential serialization issue in the Java read transform due to an anonymous inner class, performance optimization opportunities in the BSON-to-Row conversion by using Map instead of Document to avoid copying nested structures, and a robustness improvement in the Python YAML reader to support string-based filters.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread sdks/python/apache_beam/yaml/yaml_io.py
@derrickaw

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a MongoDB Read SchemaTransform to Apache Beam, enabling schema-based reads from MongoDB in both Java and YAML pipelines. Key additions include configuration and provider classes in Java, utility methods for converting BSON documents to Beam Rows, and integration with Python YAML IO. Feedback on the changes highlights a compilation error in MongoDbReadSchemaTransformProvider due to an incorrect .iterator() call, potential robustness issues in the error-handling path if doc.toJson() fails, missing defensive type checks in MongoDbUtils that could lead to ClassCastExceptions, and a suggestion to parse the projection parameter in Python YAML for consistency.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread sdks/python/apache_beam/yaml/yaml_io.py
@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 29.41176% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.25%. Comparing base (6ed0635) to head (bf628ad).
⚠️ Report is 26 commits behind head on master.

Files with missing lines Patch % Lines
sdks/python/apache_beam/yaml/yaml_io.py 29.41% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master   #38772   +/-   ##
=========================================
  Coverage     60.25%   60.25%           
  Complexity    20572    20572           
=========================================
  Files          3318     3318           
  Lines        315452   315508   +56     
  Branches      17142    17142           
=========================================
+ Hits         190073   190112   +39     
- Misses       116830   116847   +17     
  Partials       8549     8549           
Flag Coverage Δ
python 79.26% <29.41%> (-0.01%) ⬇️

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.

@derrickaw derrickaw marked this pull request as ready for review June 24, 2026 14:12
@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 introduces the ReadFromMongoDB transform for the Apache Beam YAML SDK, addressing issue #28690. It provides a structured way to read data from MongoDB by defining a schema, supporting optional filtering, and including error handling for malformed or incompatible documents. The changes span across Java IO utilities, Python YAML definitions, and necessary build configuration updates.

Highlights

  • MongoDB Read Transform: Added the ReadFromMongoDB transform to the YAML SDK, enabling users to read data from MongoDB collections using a schema-based approach.
  • Schema Normalization: Implemented robust conversion utilities to map BSON documents to Beam Rows, ensuring data integrity and type safety during the read process.
  • Error Handling: Integrated error handling capabilities into the MongoDB read transform, allowing for the redirection of failed rows to a separate output collection.
New Features

🧠 You can now enable Memory (public preview) 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 the 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 counterproductive. 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.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a MongoDB Read SchemaTransform provider (MongoDbReadSchemaTransformProvider) and its configuration (MongoDbReadSchemaTransformConfiguration) in Java, enabling users to read from MongoDB using Beam schemas. It also updates MongoDbUtils to support converting BSON documents to Beam Rows, registers ReadFromMongoDB in the YAML standard IO, and implements read_from_mongodb in Python's yaml_io.py. Key feedback includes: using BsonDocument.parse instead of Document.parse to avoid serialization and type mismatch issues; explicitly handling ObjectId and Number types in MongoDbUtils conversions; removing redundant null checks in the configuration class; correcting the validation tests to assert on empty strings instead of nulls; and normalizing native BSON types in Python before converting them to Beam Rows.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread sdks/python/apache_beam/yaml/yaml_io.py
@derrickaw

Copy link
Copy Markdown
Collaborator Author

assign set of reviewers

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @tvalentyn for label python.
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).

@tvalentyn

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @tvalentyn for label python. 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).

python bits LGTM

@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

@derrickaw

Copy link
Copy Markdown
Collaborator Author

R: @ahmedabu98

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

Overall looks good! Just left a few comments.

Had a higher level question:
IIUC this PR is adding two ReadFromMongoDB implementations to YAML: One from normalized Java and one from Python
Is it okay that their configurations don't overlap entirely? I know YAML switches tries to use the same implementation that matches the SDK of neighboring transforms. Does it also take configuration compatibility into account?

if (value instanceof Map) {
return toRow((Map<?, ?>) value, rowSchema);
} else {
throw new IllegalArgumentException("Cannot convert value to Row: " + value);

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.

Maybe instead just mention the value type (not the value itself)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

Comment on lines +204 to +205

PAssert.that(errorRows)

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.

Add a PAssert that MongoDbReadSchemaTransformProvider.OUTPUT_TAG pcollection is empty

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added.

@derrickaw

derrickaw commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator Author

Had a higher level question:
IIUC this PR is adding two ReadFromMongoDB implementations to YAML: One from normalized Java and one from Python
Is it okay that their configurations don't overlap entirely? I know YAML switches tries to use the same implementation that matches the SDK of neighboring transforms. Does it also take configuration compatibility into account?

I believe it does take into consider the configuration compatibility, but you bring up a good point and I have reverted those changes to where they match up better now.

@derrickaw derrickaw requested a review from ahmedabu98 June 30, 2026 02:09
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.

[yaml] Normalize MongoDBIO

4 participants