Skip to content

Commit 2817d25

Browse files
Set rootNodeCount after all nodes are loaded
Before we set the rootNodeCount as soon as the first node was added to the LazyIdMapBuilder. However, lead to a bug where the number of pages did not match the node count. Co-authored-by: Paul Horn <paul.horn@neotechnology.com>
1 parent e88834e commit 2817d25

File tree

5 files changed

+5460
-3
lines changed

5 files changed

+5460
-3
lines changed

core/src/main/java/org/neo4j/gds/core/loading/AdjacencyBuffer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ public static AdjacencyBuffer of(
136136

137137
return new AdjacencyBuffer(
138138
importMetaData,
139-
adjacencyCompressorFactory, localBuilders,
139+
adjacencyCompressorFactory,
140+
localBuilders,
140141
compressedAdjacencyLists,
141142
paging,
142143
atLeastOnePropertyToLoad

core/src/main/java/org/neo4j/gds/core/loading/LazyIdMapBuilder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public LazyIdMapBuilder(int concurrency, boolean hasLabelInformation, boolean ha
5151
.build();
5252
}
5353

54+
public void prepareForFlush() {
55+
isEmpty.set(false);
56+
}
57+
5458
public long addNode(long nodeId, NodeLabelToken nodeLabels) {
5559
var intermediateId = this.intermediateIdMapBuilder.toMappedNodeId(nodeId);
5660

@@ -61,7 +65,6 @@ public long addNode(long nodeId, NodeLabelToken nodeLabels) {
6165

6266
intermediateId = this.intermediateIdMapBuilder.addNode(nodeId);
6367

64-
isEmpty.lazySet(false);
6568
this.nodesBuilder.addNode(intermediateId, nodeLabels);
6669

6770
return intermediateId;
@@ -80,7 +83,6 @@ public long addNodeWithProperties(
8083
}
8184

8285
intermediateId = this.intermediateIdMapBuilder.addNode(nodeId);
83-
isEmpty.lazySet(false);
8486
if (properties.isEmpty()) {
8587
this.nodesBuilder.addNode(intermediateId, nodeLabels);
8688
} else {

cypher-aggregation/src/main/java/org/neo4j/gds/projection/CypherAggregation.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ private static double[] loadMultipleRelationshipProperties(
567567
// validate again before doing the heavier graph building
568568
validateGraphName(graphName);
569569

570+
Objects.requireNonNull(idMapBuilder).prepareForFlush();
571+
570572
var graphStoreBuilder = new GraphStoreBuilder()
571573
.concurrency(config.readConcurrency())
572574
.capabilities(ImmutableStaticCapabilities.of(true))

cypher-aggregation/src/test/java/org/neo4j/gds/projection/CypherAggregationTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.neo4j.gds.BaseProcTest;
3232
import org.neo4j.gds.BaseTest;
3333
import org.neo4j.gds.NodeLabel;
34+
import org.neo4j.gds.ResourceUtil;
3435
import org.neo4j.gds.api.DefaultValue;
3536
import org.neo4j.gds.api.Graph;
3637
import org.neo4j.gds.api.GraphStore;
@@ -208,6 +209,28 @@ void testLargerGraphSize() {
208209
}
209210
}
210211

212+
@Nested
213+
class CoraGraphTest extends BaseTest {
214+
@Test
215+
void load_cora_rels() {
216+
List<String> lines = ResourceUtil.lines("cora_rels.csv");
217+
List<long[]> rows = lines.stream().map(i -> {
218+
var values = i.split(",");
219+
return new long[]{Long.parseLong(values[0]), Long.parseLong(values[1])};
220+
}).collect(Collectors.toList());
221+
222+
runQuery(
223+
"UNWIND $data AS data WITH data RETURN gds.alpha.graph.project('g', data[0], data[1], {}, {}, {readConcurrency: 1})",
224+
Map.of("data", rows)
225+
);
226+
227+
assertThat(GraphStoreCatalog.exists("", db.databaseName(), "g")).isTrue();
228+
var graph = GraphStoreCatalog.get("", db.databaseName(), "g").graphStore().getUnion();
229+
assertThat(graph.nodeCount()).isEqualTo(2708);
230+
assertThat(graph.relationshipCount()).isEqualTo(rows.size());
231+
}
232+
}
233+
211234
@Nested
212235
class InverseGraphTest extends BaseTest {
213236

0 commit comments

Comments
 (0)