|
19 | 19 | */ |
20 | 20 | package org.neo4j.gds.triangle.intersect; |
21 | 21 |
|
| 22 | +import org.apache.commons.lang3.mutable.MutableInt; |
| 23 | +import org.junit.jupiter.api.Nested; |
22 | 24 | import org.junit.jupiter.api.Test; |
| 25 | +import org.neo4j.gds.NodeLabel; |
23 | 26 | import org.neo4j.gds.Orientation; |
| 27 | +import org.neo4j.gds.RelationshipType; |
24 | 28 | import org.neo4j.gds.api.Graph; |
| 29 | +import org.neo4j.gds.api.GraphStore; |
25 | 30 | import org.neo4j.gds.core.concurrency.Concurrency; |
26 | 31 | import org.neo4j.gds.core.concurrency.DefaultPool; |
27 | 32 | import org.neo4j.gds.core.huge.UnionGraph; |
28 | 33 | import org.neo4j.gds.core.loading.construction.GraphFactory; |
29 | 34 | import org.neo4j.gds.core.loading.construction.RelationshipsBuilder; |
| 35 | +import org.neo4j.gds.extension.GdlExtension; |
| 36 | +import org.neo4j.gds.extension.GdlGraph; |
| 37 | +import org.neo4j.gds.extension.IdFunction; |
| 38 | +import org.neo4j.gds.extension.Inject; |
30 | 39 | import org.neo4j.gds.triangle.LabelFilterChecker; |
31 | 40 |
|
32 | 41 | import java.util.ArrayList; |
33 | 42 | import java.util.Collections; |
34 | 43 | import java.util.List; |
| 44 | +import java.util.Optional; |
35 | 45 | import java.util.Random; |
36 | 46 |
|
37 | 47 | import static org.assertj.core.api.Assertions.assertThat; |
@@ -149,4 +159,48 @@ Graph produceGraph(ArrayList<Long> targets) { |
149 | 159 | return UnionGraph.of(List.of(graph1, graph2)); |
150 | 160 |
|
151 | 161 | } |
| 162 | + @GdlExtension |
| 163 | + @Nested |
| 164 | + class UnionGraphWithFilters { |
| 165 | + @GdlGraph(idOffset = 87, orientation = Orientation.UNDIRECTED) |
| 166 | + public static final String GRAPH = |
| 167 | + "(:A),(:A),(:A),(:A)," + |
| 168 | + "(a:B),(b:B),(c:B)," + |
| 169 | + "(a)-[:R1]->(b)," + |
| 170 | + "(b)-[:R]->(c)," + |
| 171 | + "(c)-[:R]->(a)"; |
| 172 | + @Inject |
| 173 | + private GraphStore graphStore; |
| 174 | + |
| 175 | + @Inject |
| 176 | + private IdFunction idFunction; |
| 177 | + |
| 178 | + @Test |
| 179 | + void testFilter() { |
| 180 | + var graph = graphStore.getGraph( |
| 181 | + List.of(NodeLabel.of("B")), |
| 182 | + List.of(RelationshipType.of("R"), RelationshipType.of("R1")), |
| 183 | + Optional.empty() |
| 184 | + ); |
| 185 | + var maxDegree = Long.MAX_VALUE; |
| 186 | + var nodeCount = graph.nodeCount(); |
| 187 | + |
| 188 | + assertThat(nodeCount).isEqualTo(3); |
| 189 | + assertThat(graph.relationshipCount()).isEqualTo(6); |
| 190 | + |
| 191 | + var intersect = new UnionGraphIntersect.NodeFilteredUnionGraphIntersectFactory().load( |
| 192 | + graph, |
| 193 | + maxDegree, |
| 194 | + new LabelFilterChecker(Collections.emptyList(), graph::hasLabel) |
| 195 | + ); |
| 196 | + |
| 197 | + var triangleCount = new MutableInt(0); |
| 198 | + intersect.intersectAll( //triangles are found in reverse, so must change from 'a' to 'c' |
| 199 | + graph.toMappedNodeId(idFunction.of("c")), |
| 200 | + (nodeA, nodeB, nodeC) -> triangleCount.increment() |
| 201 | + ); |
| 202 | + |
| 203 | + assertThat(triangleCount.intValue()).isEqualTo(1); |
| 204 | + } |
| 205 | + } |
152 | 206 | } |
0 commit comments