add reversed implementation to Pregel API - #813
Conversation
There was a problem hiding this comment.
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 ScalaGraphFrameAPI (reverse all edges, preserve edge attributes). - Expose reversal in Python: classic delegates to JVM; connect performs a pure-DataFrame
src/dstswap; public wrapper addsas_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.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
SemyonSinchenko
left a comment
There was a problem hiding this comment.
~LGTM, thanks for the contribution @slavlotski !
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) withthe same attributes. Vertices remain unchanged.
Implemented across all three layers:
asReversed()inGraphFrame.scalaself._jvm_graph.asReversed()as_reversed()delegates toself._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:
Currently users must manually swap src/dst columns — this provides an API for it.