Skip to content

Commit 745979c

Browse files
knutwalkers1ck
authored andcommitted
Validate nodeProperties against properties in graph
Co-Authored-By: Martin Junghanns <[email protected]>
1 parent b2b7e79 commit 745979c

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

core/src/main/java/org/neo4j/graphalgo/core/loading/GraphStore.java

+8
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ public long relationshipPropertyCount() {
180180
.sum();
181181
}
182182

183+
public Set<String> availableRelationshipPropertyKeys() {
184+
return relationshipProperties
185+
.values()
186+
.stream()
187+
.flatMap(properties -> properties.keySet().stream())
188+
.collect(Collectors.toSet());
189+
}
190+
183191
public Set<Pair<String, Optional<String>>> relationshipPropertyKeys() {
184192
return this.relationshipTypes().stream().flatMap(relType -> {
185193
if (relationshipProperties.containsKey(relType)) {

proc/src/main/java/org/neo4j/graphalgo/AlgoBaseProc.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ private void validate(GraphStoreWithConfig graphStoreWithConfig, CONFIG config)
263263
return;
264264
}
265265
if (config instanceof SeedConfig) {
266-
Set<String> nodeProperties = graphCreateConfig.nodeProjections().allProperties();
266+
Set<String> nodeProperties = graphStore.nodePropertyKeys();
267267
String seedProperty = ((SeedConfig) config).seedProperty();
268268
if (seedProperty != null && !nodeProperties.contains(seedProperty)) {
269269
throw new IllegalArgumentException(String.format(
@@ -274,7 +274,7 @@ private void validate(GraphStoreWithConfig graphStoreWithConfig, CONFIG config)
274274
}
275275
}
276276
if (config instanceof NodeWeightConfig) {
277-
Set<String> properties = new HashSet<>(graphCreateConfig.nodeProjections().allProperties());
277+
Set<String> properties = graphStore.nodePropertyKeys();
278278

279279
String weightProperty = ((NodeWeightConfig) config).nodeWeightProperty();
280280
if (weightProperty != null && !properties.contains(weightProperty)) {
@@ -286,7 +286,7 @@ private void validate(GraphStoreWithConfig graphStoreWithConfig, CONFIG config)
286286
}
287287
}
288288
if (config instanceof RelationshipWeightConfig) {
289-
Set<String> properties = new HashSet<>(graphCreateConfig.relationshipProjections().allProperties());
289+
Set<String> properties = graphStore.availableRelationshipPropertyKeys();
290290

291291
String weightProperty = ((RelationshipWeightConfig) config).relationshipWeightProperty();
292292
if (weightProperty != null && !properties.contains(weightProperty)) {

proc/src/test/java/org/neo4j/graphalgo/catalog/GraphMutateProcIntegrationTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,10 @@ void runPipeline() {
146146
.explicitCreation(TEST_GRAPH)
147147
.algo("labelPropagation")
148148
.mutateMode()
149+
.addParameter("nodeWeightProperty", "pageRank")
149150
.addParameter("mutateProperty", "louvain")
150151
.yields();
151-
String lovainQuery = GdsCypher
152+
String louvainQuery = GdsCypher
152153
.call()
153154
.explicitCreation(TEST_GRAPH)
154155
.algo("louvain")
@@ -167,7 +168,7 @@ void runPipeline() {
167168
runQuery(pageRankQuery);
168169
runQuery(wccQuery);
169170
runQuery(labelPropagationQuery);
170-
runQuery(lovainQuery);
171+
runQuery(louvainQuery);
171172
runQuery(nodeSimilarityQuery);
172173

173174
assertGraphEquals(EXPECTED_GRAPH, GraphStoreCatalog.get(getUsername(), TEST_GRAPH).graphStore().getUnion());

0 commit comments

Comments
 (0)