Skip to content

Report source lineage from HadoopFormatIO#37265

Merged
Abacn merged 8 commits into
apache:masterfrom
shnapz:hadoop-format-io-lineage-support
May 22, 2026
Merged

Report source lineage from HadoopFormatIO#37265
Abacn merged 8 commits into
apache:masterfrom
shnapz:hadoop-format-io-lineage-support

Conversation

@shnapz

@shnapz shnapz commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

This PR adds source lineage reporting to HadoopFormatIO and HadoopFileSystem.

Background

While FileBasedSource already reports source lineage metrics, HadoopFormatIO and HadoopFileSystem did not. HadoopFormatIO is a generic IO transform that supports various data sources through Hadoop's InputFormat/OutputFormat interfaces, and HadoopFileSystem is Beam's HDFS filesystem implementation which lacked a reportLineage override.

Changes

  • HadoopFormatIO: Reports source lineage for file-based splits by calling Lineage.getSources().add() directly, consistent with how other Beam connectors (Kafka, BigQuery, JDBC, etc.) report lineage. Only FileSplit instances are reported; non-file sources (e.g., database reads via DBInputFormat) are skipped.
  • HadoopFileSystem: Overrides reportLineage to extract HDFS URI authority and path segments, enabling lineage reporting for HDFS file operations.
  • HadoopFileSystemTest: Unit tests verifying correct lineage segment extraction for HDFS URIs.

No changes to core modules (FileBasedSource, FileSystems).


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.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @shnapz, 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 enhances Apache Beam's data lineage capabilities by extending source lineage reporting to HadoopFormatIO for file-based inputs. Previously, only FileBasedSource provided this functionality. The change introduces a centralized utility method for reporting lineage from multiple ResourceIds, which is then adopted by both HadoopFormatIO and FileBasedSource to ensure consistent and efficient lineage tracking across file-based data sources. This improvement helps users better understand the origins of their data within Beam pipelines.

Highlights

  • Source Lineage Reporting for HadoopFormatIO: Implemented source lineage reporting for file-based sources within HadoopFormatIO, specifically for InputSplit instances that are FileSplit.
  • Refactored Lineage Logic: Extracted common lineage reporting logic into a new shared utility method FileSystems.reportSourceLineage(List<ResourceId>) to reduce code duplication and centralize the logic for handling multiple resources.
  • Updated FileBasedSource: Refactored FileBasedSource to utilize the newly introduced shared FileSystems.reportSourceLineage(List<ResourceId>) method, simplifying its internal lineage reporting.

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

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

@shnapz

shnapz commented Jan 9, 2026

Copy link
Copy Markdown
Contributor 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 adds source lineage reporting to HadoopFormatIO for file-based sources, which is a valuable addition. The implementation correctly identifies file-based splits and extracts their paths for lineage tracking.

The refactoring of the common lineage reporting logic into a shared utility method FileSystems.reportSourceLineage(List<ResourceId>) is a great improvement, reducing code duplication and centralizing the logic.

I have a couple of suggestions to improve maintainability and readability:

  • In FileSystems.java, I've suggested introducing a constant for the magic number 100 to make the code clearer.
  • In HadoopFormatIO.java, I've proposed refactoring the new reportSourceLineage method to use Java Streams for a more concise and modern implementation.

Overall, this is a well-structured and useful contribution.

Comment thread sdks/java/core/src/main/java/org/apache/beam/sdk/io/FileSystems.java Outdated
@shnapz
shnapz force-pushed the hadoop-format-io-lineage-support branch from 1938428 to 23e762c Compare January 9, 2026 21:37
@shnapz
shnapz marked this pull request as ready for review January 12, 2026 16:26
@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

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

@github-actions

Copy link
Copy Markdown
Contributor

Reminder, please take a look at this pr: @ahmedabu98

@github-actions

Copy link
Copy Markdown
Contributor

Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment assign to next reviewer:

R: @Abacn for label java.

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)

@damccorm

Copy link
Copy Markdown
Contributor

R: @ahmedabu98

Could you please take a look?

@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

@Abacn

Abacn commented Jan 27, 2026

Copy link
Copy Markdown
Contributor

This change alone won't be sufficient to make lineage report effective, as HadoopFileSystem doesn't override the no-op reportLineage method in base FileSystem:

https://github.com/apache/beam/blob/master/sdks/java/io/hadoop-file-system/src/main/java/org/apache/beam/sdk/io/hdfs/HadoopFileSystem.java

Also it would be nice to unit test the change to make sure its effectiveness and does not break existing use cases

@shnapz

shnapz commented Mar 30, 2026

Copy link
Copy Markdown
Contributor Author

@Abacn I have added lineage reporting to HadoopFileSystem as well

@shnapz

shnapz commented Mar 31, 2026

Copy link
Copy Markdown
Contributor Author

btw CI checks are OK, the only thing that failed is:
testCreateManyTables[0] (org.apache.beam.sdk.io.gcp.bigquery.StorageApiSinkCreateIfNeededIT) failed
which is a flaky integration test

FileSystems.reportSourceLineage(uniqueDir);
}
}
List<ResourceId> resourceIds =

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.

Just make this public and add "internal use only...." comments. Not necessarily to move code around

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.

Is the concern whether to commit to a new public API? I took a second look and wanted to propose an alternative before reverting the move:
I've marked the method @internal with a "for internal use only by Beam-provided file-based connectors; not a stable public API" note in the javadoc. FileSystems already uses this same pattern for setDefaultPipelineOptions and registerFileSystemsOnce, so there's precedent for @internal public static helpers living here

The reason I prefer FileSystems over making it public on FileBasedSource: HadoopFormatIO isn't a FileBasedSource (it's a generic InputFormat wrapper that only sometimes produces file splits) so reaching into FileBasedSource as a utility namespace feels off. FileSystems is already the shared home for lineage reporting, it has three other reportSourceLineage overloads and this logic is applicable to any file-producing connector, not just subclasses of FileBasedSource.

Iam happy to revert to the FileBasedSource approach if you still prefer it. Just wanted tofloat this as an option first

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.

A generic guide is specific component change ( HadoopIO/HadoopFormat) should have minimum touch on core (FileSystems) code.

It sounds weird because in current approach HadoopFormat lineage report uses internal method belongs to FileBasedSource. Moving it to FileSystems public API further diverge the encapsulations.

Another approach is to implement HadoopFormat's reportLineage with existing FileSystems.reportSourceLineage or it's own methods

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.

I have reworked the approach. HadoopFormatIO now calls Lineage.getSources().add(scheme, segments, "/") directly like other IOs. The only changes are in HadoopFormatIO and HadoopFileSystem.

}

@Override
protected void reportLineage(HadoopResourceId resourceId, Lineage lineage) {

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.

This duplicates base classes' default impl. We only need to override reportLineage(HadoopResourceId resourceId, Lineage lineage, LineageLevel level)

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.

Sure, done!

@shnapz
shnapz force-pushed the hadoop-format-io-lineage-support branch from fc948dd to a9e88ef Compare April 23, 2026 14:40
@shnapz
shnapz requested a review from Abacn April 23, 2026 14:41
@damccorm

damccorm commented May 1, 2026

Copy link
Copy Markdown
Contributor

@Abacn would you mind taking another look?

@Abacn

Abacn commented May 4, 2026

Copy link
Copy Markdown
Contributor

waiting on author

@Abacn

Abacn commented May 4, 2026

Copy link
Copy Markdown
Contributor

latest comment was in #37265 (comment)

@shnapz
shnapz force-pushed the hadoop-format-io-lineage-support branch from 36b9a8f to 26c846a Compare May 20, 2026 14:06
@shnapz

shnapz commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

please check the latest change

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

Thank you!

@Abacn
Abacn merged commit 590c9c2 into apache:master May 22, 2026
18 checks passed
ash6898 pushed a commit to ash6898/beam that referenced this pull request Jun 29, 2026
* Report source lineage from HadoopFormatIO

* Extract shared code into FileSystems public API

* A little refactoring

* Fix import in HadoopFormatIO

* check style

* Implement lineage in HDFS and add tests

* address review comments

* Address review comments
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.

4 participants