Skip to content

add reversed implementation to Pregel API - #813

Merged
SemyonSinchenko merged 5 commits into
graphframes:mainfrom
slavlotski:feat--GraphFrames.as_reversed
Apr 7, 2026
Merged

SemyonSinchenko merged 5 commits into
graphframes:mainfrom
slavlotski:feat--GraphFrames.as_reversed

Conversation

@slavlotski

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Adds asReversed() method to GraphFrame that reverses the direction of all edges in the graph. For every directed edge (src, dst), the resulting graph contains an edge (dst, src) with
the same attributes. Vertices remain unchanged.

Implemented across all three layers:

  • Scala API: asReversed() in GraphFrame.scala
  • PySpark Classic: delegates to JVM via self._jvm_graph.asReversed()
  • PySpark Connect: pure DataFrame column swap (no protobuf needed)
  • Python wrapper: as_reversed() delegates to self._impl.asReversed()

Tests added for both Scala (GraphFrameSuite) and Python (test_graphframes.py), covering edges with and without attributes.

Closes #796

Why are the changes needed?

Edge reversal is a common graph operation needed for:

  1. Reusing forward-only Pregel algorithms in the backward direction without rewriting them
  2. Supporting upcoming optimizations to Pregel and future AggregateNeighbors, both of which depend on edge directionality
  3. Computing reverse PageRank, backward reachability, and other direction-dependent analyses

Currently users must manually swap src/dst columns — this provides an API for it.

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

Pull request overview

Adds an edge-reversal helper to GraphFrames so users can easily run direction-dependent algorithms (e.g., Pregel) on the transposed graph without manually swapping src/dst.

Changes:

  • Add asReversed() to the Scala GraphFrame API (reverse all edges, preserve edge attributes).
  • Expose reversal in Python: classic delegates to JVM; connect performs a pure-DataFrame src/dst swap; public wrapper adds as_reversed().
  • Add Scala + Python tests for reversing edges with/without attributes.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
core/src/main/scala/org/graphframes/GraphFrame.scala Adds Scala asReversed() implementation to flip edge direction while preserving attributes.
core/src/test/scala/org/graphframes/GraphFrameSuite.scala Adds unit tests validating edge reversal behavior (with and without edge attributes).
python/graphframes/classic/graphframe.py Adds classic (JVM-backed) asReversed() delegating to Scala.
python/graphframes/connect/graphframes_client.py Adds connect asReversed() implemented via DataFrame column swapping.
python/graphframes/graphframe.py Adds public Python wrapper as_reversed() delegating to the underlying impl.
python/tests/test_graphframes.py Adds Python tests for as_reversed() (with and without edge attributes).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread python/graphframes/graphframe.py Outdated
Comment thread python/graphframes/connect/graphframes_client.py Outdated
@codecov-commenter

codecov-commenter commented Apr 4, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.78%. Comparing base (f1db6f4) to head (ca3c6a5).
⚠️ Report is 18 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #813      +/-   ##
==========================================
- Coverage   84.94%   80.78%   -4.17%     
==========================================
  Files          68       78      +10     
  Lines        3507     4428     +921     
  Branches      453      536      +83     
==========================================
+ Hits         2979     3577     +598     
- Misses        528      851     +323     

☔ View full report in Codecov by Sentry.
📢 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.

@SemyonSinchenko SemyonSinchenko left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

~LGTM, thanks for the contribution @slavlotski !

@SemyonSinchenko
SemyonSinchenko merged commit 131a0d4 into graphframes:main Apr 7, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: GraphFrames.as_reversed

4 participants