Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Commit 2806408

Browse files
mneedhamjexp
authored andcommitted
default value for weight property for shortest path is null, making it optional (#868)
1 parent c9574ab commit 2806408

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

algo/src/main/java/org/neo4j/graphalgo/ShortestPathProc.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public class ShortestPathProc {
7878
public Stream<ShortestPathDijkstra.Result> dijkstraStream(
7979
@Name("startNode") Node startNode,
8080
@Name("endNode") Node endNode,
81-
@Name("propertyName") String propertyName,
81+
@Name(value = "propertyName", defaultValue = "null") String propertyName,
8282
@Name(value = "config", defaultValue = "{}")
8383
Map<String, Object> config) {
8484

@@ -121,7 +121,7 @@ public Stream<ShortestPathDijkstra.Result> dijkstraStream(
121121
public Stream<DijkstraResult> dijkstra(
122122
@Name("startNode") Node startNode,
123123
@Name("endNode") Node endNode,
124-
@Name("propertyName") String propertyName,
124+
@Name(value = "propertyName", defaultValue="null") String propertyName,
125125
@Name(value = "config", defaultValue = "{}")
126126
Map<String, Object> config) {
127127

tests/src/test/java/org/neo4j/graphalgo/algo/ShortestPathIntegrationTest.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,54 @@ public static Collection<Object[]> data() {
9191
@Parameterized.Parameter
9292
public String graphImpl;
9393

94+
@Test
95+
public void noWeightStream() throws Exception {
96+
PathConsumer consumer = mock(PathConsumer.class);
97+
DB.execute(
98+
"MATCH (start:Node{type:'start'}), (end:Node{type:'end'}) " +
99+
"CALL algo.shortestPath.stream(start, end) " +
100+
"YIELD nodeId, cost RETURN nodeId, cost")
101+
.accept((Result.ResultVisitor<Exception>) row -> {
102+
consumer.accept((Long) row.getNumber("nodeId"), (Double) row.getNumber("cost"));
103+
return true;
104+
});
105+
verify(consumer, times(2)).accept(anyLong(), anyDouble());
106+
verify(consumer, times(1)).accept(anyLong(), eq(0.0));
107+
verify(consumer, times(1)).accept(anyLong(), eq(1.0));
108+
}
109+
110+
@Test
111+
public void noWeightWrite() throws Exception {
112+
DB.execute(
113+
"MATCH (start:Node{type:'start'}), (end:Node{type:'end'}) " +
114+
"CALL algo.shortestPath(start, end) " +
115+
"YIELD loadMillis, evalMillis, writeMillis, nodeCount, totalCost\n" +
116+
"RETURN loadMillis, evalMillis, writeMillis, nodeCount, totalCost")
117+
.accept((Result.ResultVisitor<Exception>) row -> {
118+
assertEquals(1.0, (Double) row.getNumber("totalCost"), 0.01);
119+
assertEquals(2L, row.getNumber("nodeCount"));
120+
assertNotEquals(-1L, row.getNumber("loadMillis"));
121+
assertNotEquals(-1L, row.getNumber("evalMillis"));
122+
assertNotEquals(-1L, row.getNumber("writeMillis"));
123+
return false;
124+
});
125+
126+
final StepConsumer mock = mock(StepConsumer.class);
127+
128+
DB.execute("MATCH (n) WHERE exists(n.sssp) RETURN id(n) as id, n.sssp as sssp")
129+
.accept(row -> {
130+
mock.accept(
131+
row.getNumber("id").longValue(),
132+
row.getNumber("sssp").intValue());
133+
return true;
134+
});
135+
136+
verify(mock, times(2)).accept(anyLong(), anyInt());
137+
138+
verify(mock, times(1)).accept(anyLong(), eq(0));
139+
verify(mock, times(1)).accept(anyLong(), eq(1));
140+
}
141+
94142
@Test
95143
public void testDijkstraStream() throws Exception {
96144
PathConsumer consumer = mock(PathConsumer.class);

0 commit comments

Comments
 (0)