Skip to content

Commit 724c44d

Browse files
jjaderbergsoerenreichardtDarthMaxknutwalkerlassewesth
committed
Fix AIIOB in Node Sim and KNN
Co-authored-by: Sören Reichardt <[email protected]> Co-authored-by: Max Kießling <[email protected]> Co-Authored-By: Paul Horn <[email protected]> Co-Authored-By: Lasse Westh-Nielsen <[email protected]>
1 parent cca7a2a commit 724c44d

File tree

4 files changed

+105
-1
lines changed

4 files changed

+105
-1
lines changed

core/src/main/java/org/neo4j/graphalgo/core/huge/UnionGraph.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public long nodeCount() {
7575

7676
@Override
7777
public long rootNodeCount() {
78-
return first.nodeCount();
78+
return first.rootNodeCount();
7979
}
8080

8181
@Override

core/src/test/java/org/neo4j/graphalgo/core/huge/UnionGraphTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.junit.jupiter.params.ParameterizedTest;
2525
import org.junit.jupiter.params.provider.Arguments;
2626
import org.junit.jupiter.params.provider.MethodSource;
27+
import org.neo4j.graphalgo.NodeLabel;
2728
import org.neo4j.graphalgo.Orientation;
2829
import org.neo4j.graphalgo.RelationshipType;
2930
import org.neo4j.graphalgo.api.Graph;
@@ -38,6 +39,7 @@
3839

3940
import java.util.Collection;
4041
import java.util.List;
42+
import java.util.Optional;
4143
import java.util.Set;
4244
import java.util.stream.Stream;
4345

@@ -186,4 +188,24 @@ void overlappingRelationshipProperty() {
186188
assertThat(graph.relationshipProperty(a, b, -1)).isIn(3D, 5D);
187189
}
188190

191+
@Test
192+
void filteredGraphRootNodeCountShouldAgreeWithUnfilteredGraph() {
193+
// A graph that is both label filtered and has multiple relationship types
194+
var graphStore = GdlFactory.of(
195+
"CREATE " +
196+
" (a:A)" +
197+
", (b:B)" +
198+
", (a)-[:R1]->(b)" +
199+
", (b)-[:R2]->(a)"
200+
).build().graphStore();
201+
202+
var unionGraph = graphStore.getGraph(
203+
List.of(NodeLabel.of("A")),
204+
List.of(RelationshipType.of("R1"), RelationshipType.of("R2")),
205+
Optional.empty()
206+
);
207+
208+
assertThat(unionGraph.rootNodeCount()).isEqualTo(graphStore.nodeCount());
209+
}
210+
189211
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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.graphalgo.similarity.knn;
21+
22+
import org.junit.jupiter.api.BeforeEach;
23+
import org.junit.jupiter.api.Test;
24+
import org.neo4j.graphalgo.BaseProcTest;
25+
import org.neo4j.graphalgo.catalog.GraphCreateProc;
26+
import org.neo4j.graphalgo.catalog.GraphStreamRelationshipPropertiesProc;
27+
import org.neo4j.graphalgo.extension.Neo4jGraph;
28+
29+
import static org.assertj.core.api.Assertions.assertThatCode;
30+
31+
class KnnFilteredGraphTest extends BaseProcTest {
32+
33+
@BeforeEach
34+
void setUp() throws Exception {
35+
registerProcedures(GraphCreateProc.class, KnnMutateProc.class, GraphStreamRelationshipPropertiesProc.class);
36+
}
37+
38+
@Neo4jGraph
39+
static String cypher =
40+
"CREATE" +
41+
" (peter:Person {knn: 3.0})" +
42+
", (paul:Person {knn: 3.0})" +
43+
", (secretariat:Horse {knn: 2.0})" +
44+
", (ina_scott:Horse {knn: 3.0})" +
45+
", (mary:Person {knn: 3.0})" +
46+
", (:Person {knn: 3.0})" +
47+
", (lexington:Horse {knn: 3.0})" +
48+
", (:Person {knn: 3.0})" +
49+
", (peter)-[:LIKES]->(mary)" +
50+
", (paul)-[:KNOWS]->(peter)" +
51+
", (secretariat)-[:LIKES]->(ina_scott)" +
52+
", (lexington)-[:KNOWS]->(secretariat)";
53+
54+
55+
@Test
56+
void shouldComputeAndMutateOnFilteredGraph() {
57+
var create = "CALL gds.graph.create(" +
58+
"'g'," +
59+
"['Person', 'Horse']," +
60+
"['LIKES', 'KNOWS']" +
61+
", {" +
62+
"nodeProperties: ['knn']" +
63+
"}" +
64+
")";
65+
runQuery(create);
66+
var knnQuery1 = "CALL gds.beta.knn.mutate('g', {" +
67+
" nodeLabels: ['Horse']," +
68+
" mutateRelationshipType: 'FOO1'," +
69+
" mutateProperty: 'score'," +
70+
" nodeWeightProperty: 'knn'" +
71+
"})";
72+
var knnQuery2 = "CALL gds.beta.knn.mutate('g', {" +
73+
" nodeLabels: ['Person']," +
74+
" mutateRelationshipType: 'FOO2'," +
75+
" mutateProperty: 'score'," +
76+
" nodeWeightProperty: 'knn'" +
77+
"})";
78+
assertThatCode(() -> runQuery(knnQuery1)).doesNotThrowAnyException();
79+
assertThatCode(() -> runQuery(knnQuery2)).doesNotThrowAnyException();
80+
}
81+
}

proc/similarity/src/test/java/org/neo4j/graphalgo/similarity/knn/KnnMutateProcTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ void shouldMutateResults() {
141141
});
142142
}
143143

144+
144145
@Override
145146
@Test
146147
@Disabled("This test does not work for KNN")

0 commit comments

Comments
 (0)