|
25 | 25 | import net.jqwik.api.constraints.LongRange; |
26 | 26 | import org.jetbrains.annotations.NotNull; |
27 | 27 | import org.junit.jupiter.api.Test; |
| 28 | +import org.neo4j.gds.NodeLabel; |
28 | 29 | import org.neo4j.gds.RelationshipType; |
29 | 30 | import org.neo4j.gds.TestSupport; |
30 | 31 | import org.neo4j.gds.api.Graph; |
|
34 | 35 |
|
35 | 36 | import java.util.ArrayList; |
36 | 37 | import java.util.List; |
| 38 | +import java.util.Map; |
| 39 | +import java.util.Optional; |
37 | 40 | import java.util.concurrent.ConcurrentHashMap; |
38 | 41 | import java.util.stream.StreamSupport; |
39 | 42 |
|
@@ -110,6 +113,43 @@ void iterator( |
110 | 113 | assertThat(actual).isEqualTo(expected); |
111 | 114 | } |
112 | 115 |
|
| 116 | + @Test |
| 117 | + void filteredGraph() { |
| 118 | + var graphStore = TestSupport.graphStoreFromGDL("(a:A)-->(b:A)-->(c:B)-->(d:A)-->(e:A)-->(f:B)"); |
| 119 | + var graph = graphStore.getGraph( |
| 120 | + NodeLabel.of("A"), |
| 121 | + RelationshipType.ALL_RELATIONSHIPS, |
| 122 | + Optional.empty() |
| 123 | + ); |
| 124 | + assertThat(graph.nodeCount()).isEqualTo(4); |
| 125 | + assertThat(graph.relationshipCount()).isEqualTo(2); |
| 126 | + |
| 127 | + var actual = new ConcurrentHashMap<Long, List<Relationship>>(); |
| 128 | + var allRelationshipsIterator = new AllRelationshipsSpliterator(graph, 0.0); |
| 129 | + |
| 130 | + var iterator = StreamSupport.stream(allRelationshipsIterator, true).iterator(); |
| 131 | + |
| 132 | + while (iterator.hasNext()) { |
| 133 | + var relationshipCursor = iterator.next(); |
| 134 | + actual.computeIfAbsent(relationshipCursor.sourceId(), __ -> new ArrayList<>()) |
| 135 | + .add(new Relationship( |
| 136 | + relationshipCursor.targetId(), |
| 137 | + relationshipCursor.property() |
| 138 | + )); |
| 139 | + } |
| 140 | + |
| 141 | + assertThat(actual).isEqualTo(Map.of( |
| 142 | + 0L, List.of(new Relationship(1L, 0.0)), |
| 143 | + 2L, List.of(new Relationship(3L, 0.0)) |
| 144 | + )); |
| 145 | + |
| 146 | + // returned node ids are filtered node ids |
| 147 | + assertThat(graph.toOriginalNodeId(0)).isEqualTo(0); |
| 148 | + assertThat(graph.toOriginalNodeId(1)).isEqualTo(1); |
| 149 | + assertThat(graph.toOriginalNodeId(2)).isEqualTo(3); |
| 150 | + assertThat(graph.toOriginalNodeId(3)).isEqualTo(4); |
| 151 | + } |
| 152 | + |
113 | 153 | private static @NotNull HugeGraph generateGraph( |
114 | 154 | long nodeCount, |
115 | 155 | int averageDegree, |
|
0 commit comments