Skip to content

Conversation

@shnapz
Copy link

@shnapz shnapz commented Jan 8, 2026

This PR adds source lineage reporting to HadoopFormatIO for file-based sources.

Background

While FileBasedSource already reports source lineage metrics, HadoopFormatIO did not. HadoopFormatIO is a more generic IO transform that supports various data sources including databases, NoSQL stores, and file systems through Hadoop's InputFormat/OutputFormat interfaces.

Changes

  • Added lineage reporting to HadoopFormatIO: Implements source lineage reporting for file-based splits (when InputSplit is an instance of FileSplit)
  • Refactored shared logic: Extracted common lineage reporting logic into FileSystems.reportSourceLineage(List<ResourceId>) to reduce code duplication
  • Updated FileBasedSource: Refactored to use the new shared utility method

Implementation Details

The implementation reports lineage only for file-based sources detected via FileSplit instances. Non-file sources (e.g., database reads via DBInputFormat) are intentionally excluded as they don't represent file resources.


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
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
Copy link
Author

shnapz commented Jan 9, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 on lines +412 to +431
public static void reportSourceLineage(List<ResourceId> resourceIds) {
if (resourceIds.size() <= 100) {
for (ResourceId resourceId : resourceIds) {
FileSystems.reportSourceLineage(resourceId);
}
} else {
HashSet<ResourceId> uniqueDirs = new HashSet<>();
for (ResourceId resourceId : resourceIds) {
ResourceId dir = resourceId.getCurrentDirectory();
uniqueDirs.add(dir);
if (uniqueDirs.size() > 100) {
FileSystems.reportSourceLineage(dir, LineageLevel.TOP_LEVEL);
return;
}
}
for (ResourceId uniqueDir : uniqueDirs) {
FileSystems.reportSourceLineage(uniqueDir);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The magic number 100 is used multiple times for thresholding. It would be better to define it as a constant to improve readability and maintainability. A class-level constant would be ideal, but a local constant within the method is also an improvement.

  public static void reportSourceLineage(List<ResourceId> resourceIds) {
    final int MAX_LINEAGE_TARGETS = 100;
    if (resourceIds.size() <= MAX_LINEAGE_TARGETS) {
      for (ResourceId resourceId : resourceIds) {
        FileSystems.reportSourceLineage(resourceId);
      }
    } else {
      HashSet<ResourceId> uniqueDirs = new HashSet<>();
      for (ResourceId resourceId : resourceIds) {
        ResourceId dir = resourceId.getCurrentDirectory();
        uniqueDirs.add(dir);
        if (uniqueDirs.size() > MAX_LINEAGE_TARGETS) {
          FileSystems.reportSourceLineage(dir, LineageLevel.TOP_LEVEL);
          return;
        }
      }
      for (ResourceId uniqueDir : uniqueDirs) {
        FileSystems.reportSourceLineage(uniqueDir);
      }
    }
  }

Comment on lines +757 to +769
List<ResourceId> fileResources = new ArrayList<>();

for (SerializableSplit split : inputSplits) {
InputSplit inputSplit = split.getSplit();

if (inputSplit instanceof FileSplit) {
String pathString = ((FileSplit) inputSplit).getPath().toString();
ResourceId resourceId = FileSystems.matchNewResource(pathString, false);
fileResources.add(resourceId);
}
}

FileSystems.reportSourceLineage(fileResources);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This loop can be refactored to use Java Streams for a more concise and declarative style.

      List<ResourceId> fileResources =
          inputSplits.stream()
              .map(SerializableSplit::getSplit)
              .filter(FileSplit.class::isInstance)
              .map(FileSplit.class::cast)
              .map(fileSplit -> FileSystems.matchNewResource(fileSplit.getPath().toString(), false))
              .collect(Collectors.toList());

      FileSystems.reportSourceLineage(fileResources);

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.

1 participant