Skip to content

Commit f3bb3a4

Browse files
authored
Merge pull request #6587 from s1ck/idx-inc-scanning-relationships-importer
[IdxInc] Project inverse list in native projection
2 parents 7e7bafa + 3f9ffa2 commit f3bb3a4

File tree

18 files changed

+504
-116
lines changed

18 files changed

+504
-116
lines changed

core/src/main/java/org/neo4j/gds/api/CSRGraphStoreFactory.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import org.neo4j.gds.core.loading.CSRGraphStore;
2626
import org.neo4j.gds.core.loading.Capabilities;
2727
import org.neo4j.gds.core.loading.GraphStoreBuilder;
28-
import org.neo4j.gds.core.loading.IdMapAndProperties;
29-
import org.neo4j.gds.core.loading.RelationshipsAndProperties;
28+
import org.neo4j.gds.core.loading.NodeImportResult;
29+
import org.neo4j.gds.core.loading.RelationshipImportResult;
3030
import org.neo4j.gds.mem.MemoryUsage;
3131

3232
import static org.neo4j.gds.utils.StringFormatting.formatWithLocale;
@@ -43,17 +43,17 @@ public CSRGraphStoreFactory(
4343
}
4444

4545
protected CSRGraphStore createGraphStore(
46-
IdMapAndProperties idMapAndProperties,
47-
RelationshipsAndProperties relationshipsAndProperties
46+
NodeImportResult nodeImportResult,
47+
RelationshipImportResult relationshipImportResult
4848
) {
4949
return new GraphStoreBuilder()
5050
.databaseId(DatabaseId.of(loadingContext.graphDatabaseService()))
5151
.capabilities(capabilities)
52-
.schema(computeGraphSchema(idMapAndProperties, relationshipsAndProperties))
53-
.nodes(idMapAndProperties.idMap())
54-
.nodePropertyStore(idMapAndProperties.properties())
55-
.relationships(relationshipsAndProperties.relationships())
56-
.relationshipPropertyStores(relationshipsAndProperties.properties())
52+
.schema(computeGraphSchema(nodeImportResult, relationshipImportResult))
53+
.nodes(nodeImportResult.idMap())
54+
.nodePropertyStore(nodeImportResult.properties())
55+
.relationships(relationshipImportResult.relationships())
56+
.relationshipPropertyStores(relationshipImportResult.properties())
5757
.concurrency(graphProjectConfig.readConcurrency())
5858
.build();
5959
}
@@ -64,5 +64,8 @@ protected void logLoadingSummary(GraphStore graphStore) {
6464
progressTracker.logInfo(formatWithLocale("Actual memory usage of the loaded graph: %s", memoryUsage));
6565
}
6666

67-
protected abstract GraphSchema computeGraphSchema(IdMapAndProperties idMapAndProperties, RelationshipsAndProperties relationshipsAndProperties);
67+
protected abstract GraphSchema computeGraphSchema(
68+
NodeImportResult nodeImportResult,
69+
RelationshipImportResult relationshipImportResult
70+
);
6871
}

core/src/main/java/org/neo4j/gds/api/Relationships.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
package org.neo4j.gds.api;
2121

22+
import org.immutables.value.Value;
2223
import org.jetbrains.annotations.Nullable;
2324
import org.neo4j.gds.annotation.ValueClass;
2425

@@ -52,7 +53,7 @@ static Relationships of(
5253
@Nullable AdjacencyProperties adjacencyProperties,
5354
double defaultPropertyValue
5455
) {
55-
Topology topology = ImmutableTopology.of(
56+
var topology = ImmutableTopology.of(
5657
adjacencyList,
5758
relationshipCount,
5859
isMultiGraph
@@ -72,6 +73,9 @@ static Relationships of(
7273
interface Topology {
7374
AdjacencyList adjacencyList();
7475

76+
@Value.Parameter(false)
77+
Optional<AdjacencyList> inverseAdjacencyList();
78+
7579
long elementCount();
7680

7781
boolean isMultiGraph();
@@ -82,6 +86,11 @@ public AdjacencyList adjacencyList() {
8286
return AdjacencyList.EMPTY;
8387
}
8488

89+
@Override
90+
public Optional<AdjacencyList> inverseAdjacencyList() {
91+
return Optional.empty();
92+
}
93+
8594
@Override
8695
public long elementCount() {
8796
return 0;

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,14 @@ public static RelationshipPropertyStore buildRelationshipPropertyStore(
231231
}
232232

233233
public static GraphSchema computeGraphSchema(
234-
IdMapAndProperties idMapAndProperties,
234+
NodeImportResult nodeImportResult,
235235
Function<NodeLabel, Collection<String>> propertiesByLabel,
236-
RelationshipsAndProperties relationshipsAndProperties
236+
RelationshipImportResult relationshipImportResult
237237
) {
238-
var properties = idMapAndProperties.properties().properties();
238+
var properties = nodeImportResult.properties().properties();
239239

240240
var nodeSchema = NodeSchema.empty();
241-
for (var label : idMapAndProperties.idMap().availableNodeLabels()) {
241+
for (var label : nodeImportResult.idMap().availableNodeLabels()) {
242242
var entry = nodeSchema.getOrCreateLabel(label);
243243
for (var propertyKey : propertiesByLabel.apply(label)) {
244244
entry.addProperty(
@@ -247,15 +247,15 @@ public static GraphSchema computeGraphSchema(
247247
);
248248
}
249249
}
250-
idMapAndProperties.idMap().availableNodeLabels().forEach(nodeSchema::getOrCreateLabel);
250+
nodeImportResult.idMap().availableNodeLabels().forEach(nodeSchema::getOrCreateLabel);
251251

252252
var relationshipSchema = RelationshipSchema.empty();
253-
relationshipsAndProperties
253+
relationshipImportResult
254254
.properties()
255255
.forEach((relType, propertyStore) -> {
256256
var entry = relationshipSchema.getOrCreateRelationshipType(
257257
relType,
258-
relationshipsAndProperties.directions().get(relType)
258+
relationshipImportResult.directions().get(relType)
259259
);
260260

261261
propertyStore
@@ -266,13 +266,13 @@ public static GraphSchema computeGraphSchema(
266266
));
267267
});
268268

269-
relationshipsAndProperties
269+
relationshipImportResult
270270
.relationships()
271271
.keySet()
272272
.forEach(type -> {
273273
relationshipSchema.getOrCreateRelationshipType(
274274
type,
275-
relationshipsAndProperties.directions().get(type)
275+
relationshipImportResult.directions().get(type)
276276
);
277277
});
278278

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ public GraphDimensions estimationDimensions() {
120120

121121
@Override
122122
protected GraphSchema computeGraphSchema(
123-
IdMapAndProperties idMapAndProperties, RelationshipsAndProperties relationshipsAndProperties
123+
NodeImportResult nodeImportResult, RelationshipImportResult relationshipImportResult
124124
) {
125125
return CSRGraphStoreUtil.computeGraphSchema(
126-
idMapAndProperties,
127-
(__) -> idMapAndProperties.properties().keySet(),
128-
relationshipsAndProperties
126+
nodeImportResult,
127+
(__) -> nodeImportResult.properties().keySet(),
128+
relationshipImportResult
129129
);
130130
}
131131

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import java.util.stream.Collectors;
3535

3636
@Value.Enclosing
37-
class CypherNodeLoader extends CypherRecordLoader<IdMapAndProperties> {
37+
class CypherNodeLoader extends CypherRecordLoader<NodeImportResult> {
3838

3939
private final long nodeCount;
4040
private final ProgressTracker progressTracker;
@@ -97,13 +97,13 @@ void updateCounts(BatchLoadResult result) {
9797
}
9898

9999
@Override
100-
IdMapAndProperties result() {
100+
NodeImportResult result() {
101101
var idMapAndProperties = nodesBuilder.build(highestNodeId);
102102
var idMap = idMapAndProperties.idMap();
103103
var nodeProperties = idMapAndProperties.nodeProperties().orElseGet(Map::of);
104104
var nodePropertiesWithPropertyMappings = propertiesWithPropertyMappings(nodeProperties);
105105

106-
return IdMapAndProperties.of(idMap, nodePropertiesWithPropertyMappings);
106+
return NodeImportResult.of(idMap, nodePropertiesWithPropertyMappings);
107107
}
108108

109109
@Override

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import java.util.stream.Collectors;
4646

4747
@Value.Enclosing
48-
class CypherRelationshipLoader extends CypherRecordLoader<RelationshipsAndProperties> {
48+
class CypherRelationshipLoader extends CypherRecordLoader<RelationshipImportResult> {
4949

5050
private final IdMap idMap;
5151
private final Context loaderContext;
@@ -133,16 +133,16 @@ BatchLoadResult loadSingleBatch(InternalTransaction tx, int bufferSize) {
133133
void updateCounts(BatchLoadResult result) {}
134134

135135
@Override
136-
RelationshipsAndProperties result() {
136+
RelationshipImportResult result() {
137137
var relationshipsByType = loaderContext.relationshipBuildersByType.entrySet().stream().collect(Collectors.toMap(
138138
entry -> {
139139
var projection = projectionBuilder.type(entry.getKey().name).build();
140-
return RelationshipsAndProperties.RelationshipTypeAndProjection.of(entry.getKey(), projection);
140+
return RelationshipImportResult.RelationshipTypeAndProjection.of(entry.getKey(), projection);
141141
},
142142
entry -> entry.getValue().buildAll()
143143
));
144144

145-
return RelationshipsAndProperties.of(relationshipsByType);
145+
return RelationshipImportResult.of(relationshipsByType);
146146
}
147147

148148
@Override

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@ protected ProgressTracker initProgressTracker() {
227227

228228
@Override
229229
protected GraphSchema computeGraphSchema(
230-
IdMapAndProperties idMapAndProperties, RelationshipsAndProperties relationshipsAndProperties
230+
NodeImportResult nodeImportResult, RelationshipImportResult relationshipImportResult
231231
) {
232232
return CSRGraphStoreUtil.computeGraphSchema(
233-
idMapAndProperties,
233+
nodeImportResult,
234234
(label) -> storeConfig.nodeProjections().projections().get(label).properties().propertyKeys(),
235-
relationshipsAndProperties
235+
relationshipImportResult
236236
);
237237
}
238238

@@ -243,8 +243,8 @@ public CSRGraphStore build() {
243243
int concurrency = graphProjectConfig.readConcurrency();
244244
try {
245245
progressTracker.beginSubTask();
246-
IdMapAndProperties nodes = loadNodes(concurrency);
247-
RelationshipsAndProperties relationships = loadRelationships(nodes.idMap(), concurrency);
246+
NodeImportResult nodes = loadNodes(concurrency);
247+
RelationshipImportResult relationships = loadRelationships(nodes.idMap(), concurrency);
248248
CSRGraphStore graphStore = createGraphStore(nodes, relationships);
249249

250250
logLoadingSummary(graphStore);
@@ -255,7 +255,7 @@ public CSRGraphStore build() {
255255
}
256256
}
257257

258-
private IdMapAndProperties loadNodes(int concurrency) {
258+
private NodeImportResult loadNodes(int concurrency) {
259259
var scanningNodesImporter = new ScanningNodesImporterBuilder()
260260
.concurrency(concurrency)
261261
.graphProjectConfig(graphProjectConfig)
@@ -272,7 +272,7 @@ private IdMapAndProperties loadNodes(int concurrency) {
272272
}
273273
}
274274

275-
private RelationshipsAndProperties loadRelationships(IdMap idMap, int concurrency) {
275+
private RelationshipImportResult loadRelationships(IdMap idMap, int concurrency) {
276276
var scanningRelationshipsImporter = new ScanningRelationshipsImporterBuilder()
277277
.idMap(idMap)
278278
.graphProjectConfig(graphProjectConfig)

core/src/main/java/org/neo4j/gds/core/loading/IdMapAndProperties.java renamed to core/src/main/java/org/neo4j/gds/core/loading/NodeImportResult.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
import java.util.Map;
3131

3232
@ValueClass
33-
public interface IdMapAndProperties {
33+
public interface NodeImportResult {
3434

3535
IdMap idMap();
3636

3737
NodePropertyStore properties();
3838

39-
static IdMapAndProperties of(IdMap idMap, Map<PropertyMapping, NodePropertyValues> properties) {
39+
static NodeImportResult of(IdMap idMap, Map<PropertyMapping, NodePropertyValues> properties) {
4040
NodePropertyStore.Builder builder = NodePropertyStore.builder();
4141
properties.forEach((mapping, nodeProperties) -> builder.putProperty(
4242
mapping.propertyKey(),
@@ -49,6 +49,6 @@ static IdMapAndProperties of(IdMap idMap, Map<PropertyMapping, NodePropertyValue
4949
: nodeProperties.valueType().fallbackValue()
5050
)
5151
));
52-
return ImmutableIdMapAndProperties.of(idMap, builder.build());
52+
return ImmutableNodeImportResult.of(idMap, builder.build());
5353
}
5454
}

0 commit comments

Comments
 (0)