add reversed implementation to Pregel API#813
add reversed implementation to Pregel API#813slavlotski wants to merge 2 commits intographframes:mainfrom
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.
| return GraphFrame._from_impl(self._impl.asReversed() | ||
|
|
There was a problem hiding this comment.
as_reversed currently has a syntax error: the call to _from_impl(self._impl.asReversed() is missing the closing parentheses, which will prevent the module from importing and will break all users/tests. Close the call (and remove trailing whitespace) so it returns a new GraphFrame built from the reversed impl result.
| return GraphFrame._from_impl(self._impl.asReversed() | |
| return GraphFrame._from_impl(self._impl.asReversed()) |
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.