Skip to content

Commit 279ef98

Browse files
adamnschlassewesth
andcommitted
Don't return relationshipsWritten in new Dijkstra result
Co-Authored-By: Lasse Westh-Nielsen <lassewesth@gmail.com>
1 parent 68383d4 commit 279ef98

File tree

4 files changed

+156
-19
lines changed

4 files changed

+156
-19
lines changed

applications/algorithms/path-finding/src/main/java/org/neo4j/gds/applications/algorithms/pathfinding/PathFindingAlgorithmsMutateModeBusinessFacade.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public <RESULT> RESULT singlePairShortestPathDijkstraWithPaths(
244244
GraphName graphName,
245245
ShortestPathDijkstraMutateConfig configuration,
246246
ResultStore resultStore,
247-
ResultBuilder<ShortestPathDijkstraMutateConfig, PathFindingResult, RESULT, RelationshipsWritten> resultBuilder
247+
ResultBuilder<ShortestPathDijkstraMutateConfig, PathFindingResult, RESULT, Void> resultBuilder
248248
) {
249249

250250
return algorithmProcessingTemplate.processAlgorithmAndAnySideEffects(

applications/algorithms/path-finding/src/main/java/org/neo4j/gds/applications/algorithms/pathfinding/StorePathsSideEffect.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import java.util.concurrent.atomic.AtomicLong;
3939
import java.util.stream.Stream;
4040

41-
public class StorePathsSideEffect implements SideEffect<PathFindingResult, RelationshipsWritten> {
41+
public class StorePathsSideEffect implements SideEffect<PathFindingResult, Void> {
4242
private final ResultStore resultStore;
4343
private final String relationshipTypeAsString;
4444
private final List<String> propertyKeys;
@@ -57,25 +57,28 @@ public StorePathsSideEffect(
5757
}
5858

5959
@Override
60-
public Optional<RelationshipsWritten> process(GraphResources graphResources, Optional<PathFindingResult> pathFindingResult) {
61-
return pathFindingResult.map(result -> {
62-
var relCounter = new AtomicLong(0);
60+
public Optional<Void> process(GraphResources graphResources, Optional<PathFindingResult> pathFindingResult) {
61+
if (pathFindingResult.isEmpty()) {
62+
return Optional.empty();
63+
}
64+
var actualPathResult = pathFindingResult.get();
65+
Stream<ExportedRelationship> relationshipStream = actualPathResult.mapPaths(
66+
pathResult -> new ExportedRelationship(
67+
pathResult.sourceNode(),
68+
pathResult.targetNode(),
69+
createValues(pathResult)
70+
));
6371

64-
Stream<ExportedRelationship> relationshipStream = result.mapPaths(
65-
pathResult -> {
66-
relCounter.incrementAndGet();
67-
return new ExportedRelationship(
68-
pathResult.sourceNode(),
69-
pathResult.targetNode(),
70-
createValues(pathResult)
71-
);
72-
});
72+
ResultStoreEntry.RelationshipStream streamEntry = new ResultStoreEntry.RelationshipStream(
73+
relationshipTypeAsString,
74+
propertyKeys,
75+
propertyTypes,
76+
relationshipStream,
77+
graphResources.graph()::toOriginalNodeId
78+
);
79+
resultStore.add(JobId.parse(this.relationshipTypeAsString), streamEntry);
7380

74-
resultStore.add(JobId.parse(this.relationshipTypeAsString), new ResultStoreEntry.RelationshipStream(
75-
relationshipTypeAsString, propertyKeys, propertyTypes, relationshipStream, graphResources.graph()::toOriginalNodeId));
76-
77-
return new RelationshipsWritten(relCounter.get());
78-
});
81+
return Optional.empty();
7982
}
8083

8184
private Value[] createValues(PathResult pathResult) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.procedures.algorithms.pathfinding;
21+
22+
import org.neo4j.gds.api.Graph;
23+
import org.neo4j.gds.applications.algorithms.machinery.AlgorithmProcessingTimings;
24+
import org.neo4j.gds.applications.algorithms.machinery.ResultBuilder;
25+
import org.neo4j.gds.applications.algorithms.metadata.RelationshipsWritten;
26+
import org.neo4j.gds.config.ToMapConvertible;
27+
import org.neo4j.gds.paths.dijkstra.PathFindingResult;
28+
29+
import java.util.Optional;
30+
31+
public class DijkstraWithPathsResultBuilder<CONFIGURATION extends ToMapConvertible> implements ResultBuilder<CONFIGURATION, PathFindingResult, DijkstraWithPathsResult, Void> {
32+
@Override
33+
public DijkstraWithPathsResult build(
34+
Graph graph,
35+
CONFIGURATION configuration,
36+
Optional<PathFindingResult> pathFindingResult,
37+
AlgorithmProcessingTimings timings,
38+
Optional<Void> metadata
39+
) {
40+
return DijkstraWithPathsResult.create(
41+
timings,
42+
configuration.toMap()
43+
);
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.procedures.algorithms.pathfinding;
21+
22+
import org.neo4j.gds.applications.algorithms.machinery.AlgorithmProcessingTimings;
23+
import org.neo4j.gds.procedures.algorithms.results.MutateResult;
24+
25+
import java.util.Map;
26+
27+
public class DijkstraWithPathsResult implements MutateResult {
28+
29+
public final long preProcessingMillis;
30+
public final long computeMillis;
31+
public final long mutateMillis;
32+
public final long postProcessingMillis;
33+
public final Map<String, Object> configuration;
34+
35+
public DijkstraWithPathsResult(
36+
long preProcessingMillis,
37+
long computeMillis,
38+
long mutateMillis,
39+
long postProcessingMillis,
40+
Map<String, Object> configuration
41+
) {
42+
this.preProcessingMillis = preProcessingMillis;
43+
this.computeMillis = computeMillis;
44+
this.mutateMillis = mutateMillis;
45+
this.postProcessingMillis = postProcessingMillis;
46+
this.configuration = configuration;
47+
}
48+
49+
public static DijkstraWithPathsResult create(
50+
AlgorithmProcessingTimings timings,
51+
Map<String, Object> configuration){
52+
53+
return new DijkstraWithPathsResult(
54+
timings.preProcessingMillis,
55+
timings.computeMillis,
56+
timings.sideEffectMillis,
57+
0L,
58+
configuration
59+
);
60+
61+
62+
}
63+
64+
//add getters to maintain the interface
65+
@Override
66+
public long mutateMillis() {
67+
return mutateMillis;
68+
}
69+
70+
@Override
71+
public long postProcessingMillis() {
72+
return postProcessingMillis;
73+
}
74+
75+
@Override
76+
public long preProcessingMillis() {
77+
return preProcessingMillis;
78+
}
79+
80+
@Override
81+
public long computeMillis() {
82+
return computeMillis;
83+
}
84+
85+
@Override
86+
public Map<String, Object> configuration() {
87+
return configuration;
88+
}
89+
}

0 commit comments

Comments
 (0)