Skip to content

Commit c9e5fb1

Browse files
committed
Implement async TopologicalSort
1 parent 5889a4c commit c9e5fb1

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

algorithms-compute-facade/src/main/java/org/neo4j/gds/pathfinding/PathFindingComputeFacade.java

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
import org.neo4j.gds.dag.longestPath.DagLongestPath;
4242
import org.neo4j.gds.dag.longestPath.DagLongestPathParameters;
4343
import org.neo4j.gds.dag.longestPath.LongestPathTask;
44+
import org.neo4j.gds.dag.topologicalsort.TopSortTask;
45+
import org.neo4j.gds.dag.topologicalsort.TopologicalSort;
46+
import org.neo4j.gds.dag.topologicalsort.TopologicalSortParameters;
4447
import org.neo4j.gds.dag.topologicalsort.TopologicalSortResult;
4548
import org.neo4j.gds.kspanningtree.KSpanningTree;
4649
import org.neo4j.gds.kspanningtree.KSpanningTreeParameters;
@@ -837,13 +840,47 @@ CompletableFuture<SteinerTreeResult> steinerTree(
837840
);
838841
}
839842

840-
CompletableFuture<TopologicalSortResult> topologicalSort() {
843+
CompletableFuture<TopologicalSortResult> topologicalSort(
844+
GraphName graphName,
845+
GraphParameters graphParameters,
846+
Optional<String> relationshipProperty,
847+
TopologicalSortParameters parameters,
848+
JobId jobId,
849+
boolean logProgress
850+
) {
841851
// Fetch the Graph the algorithm will operate on
852+
var graph = graphStoreCatalogService.fetchGraphResources(
853+
graphName,
854+
graphParameters,
855+
relationshipProperty,
856+
new NoAlgorithmValidation(),
857+
Optional.empty(),
858+
user,
859+
databaseId
860+
).graph();
861+
842862
// Create ProgressTracker
863+
var progressTracker = progressTrackerFactory.create(
864+
TopSortTask.create(graph),
865+
jobId,
866+
parameters.concurrency(),
867+
logProgress
868+
);
869+
843870
// Create the algorithm
844-
// Submit the algorithm for async computation
871+
var topologicalSort = new TopologicalSort(
872+
graph,
873+
progressTracker,
874+
parameters.concurrency(),
875+
parameters.computeMaxDistanceFromSource(),
876+
terminationFlag
877+
);
845878

846-
return CompletableFuture.failedFuture(new RuntimeException("Not yet implemented"));
879+
// Submit the algorithm for async computation
880+
return algorithmCaller.run(
881+
topologicalSort::compute,
882+
jobId
883+
);
847884
}
848885

849886
}

algorithms-compute-facade/src/test/java/org/neo4j/gds/pathfinding/PathFindingComputeFacadeTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.neo4j.gds.core.utils.progress.tasks.IterativeTask;
4444
import org.neo4j.gds.core.utils.progress.tasks.ProgressTracker;
4545
import org.neo4j.gds.dag.longestPath.DagLongestPathParameters;
46+
import org.neo4j.gds.dag.topologicalsort.TopologicalSortParameters;
4647
import org.neo4j.gds.extension.GdlExtension;
4748
import org.neo4j.gds.extension.GdlGraph;
4849
import org.neo4j.gds.extension.IdFunction;
@@ -497,4 +498,25 @@ void steinerTree() {
497498
assertThat(future.join()).isNotNull();
498499
}
499500

501+
@Test
502+
void topologicalSort() {
503+
var future = facade.topologicalSort(
504+
new GraphName("foo"),
505+
new GraphParameters(
506+
List.of(NodeLabel.of("Node")),
507+
List.of(RelationshipType.of("REL")),
508+
true,
509+
Optional.empty()
510+
),
511+
Optional.empty(),
512+
new TopologicalSortParameters(
513+
false,
514+
new Concurrency(4)
515+
),
516+
jobIdMock,
517+
true
518+
);
519+
assertThat(future.join()).isNotNull();
520+
}
521+
500522
}

0 commit comments

Comments
 (0)