Skip to content

Commit fdda07c

Browse files
Add missing validation for LabProp
1 parent 903f4de commit fdda07c

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

algorithms-compute-business-facade/src/main/java/org/neo4j/gds/community/CommunityComputeBusinessFacade.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.neo4j.gds.core.loading.GraphStoreCatalogService;
4040
import org.neo4j.gds.core.loading.validation.CompoundGraphStoreValidationsBuilder;
4141
import org.neo4j.gds.core.loading.validation.NoAlgorithmValidation;
42+
import org.neo4j.gds.core.loading.validation.NodePropertyAllExistsGraphStoreValidation;
4243
import org.neo4j.gds.core.loading.validation.NodePropertyAnyExistsGraphStoreValidation;
4344
import org.neo4j.gds.core.loading.validation.NodePropertyTypeGraphStoreValidation;
4445
import org.neo4j.gds.core.loading.validation.SeedPropertyGraphStoreValidation;
@@ -322,7 +323,10 @@ public <TR> CompletableFuture<TR> labelPropagation(
322323
graphName,
323324
graphParameters,
324325
relationshipProperty,
325-
SeedPropertyGraphStoreValidation.create(parameters.seedProperty()),
326+
new CompoundGraphStoreValidationsBuilder()
327+
.withGraphStoreValidation(SeedPropertyGraphStoreValidation.create(parameters.seedProperty()))
328+
.withGraphStoreValidation(new NodePropertyAllExistsGraphStoreValidation(parameters.nodeWeightProperty()))
329+
.build(),
326330
Optional.empty(),
327331
user,
328332
databaseId

core/src/main/java/org/neo4j/gds/core/loading/validation/NodePropertyAllExistsGraphStoreValidation.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
import org.neo4j.gds.NodeLabel;
2323
import org.neo4j.gds.RelationshipType;
2424
import org.neo4j.gds.api.GraphStore;
25-
import org.neo4j.gds.utils.StringFormatting;
25+
import org.neo4j.gds.utils.StringJoining;
2626

2727
import java.util.Collection;
28+
import java.util.stream.Collectors;
29+
30+
import static org.neo4j.gds.utils.StringFormatting.formatWithLocale;
2831

2932
public class NodePropertyAllExistsGraphStoreValidation extends GraphStoreValidation {
3033

@@ -45,13 +48,23 @@ void validatePropertyExists(
4548
GraphStore graphStore,
4649
Collection<NodeLabel> selectedLabels
4750
) {
48-
if (!graphStore.nodePropertyKeys(selectedLabels).contains(nodeProperty)) {
49-
throw new IllegalArgumentException(
50-
StringFormatting.formatWithLocale(
51-
"Node property [%s] not found in the graph.",
52-
nodeProperty
53-
)
54-
);
51+
if (nodeProperty!=null){
52+
if (!graphStore.hasNodeProperty(selectedLabels, nodeProperty)) {
53+
var labelsWithMissingProperty = selectedLabels
54+
.stream()
55+
.filter(label -> !graphStore.nodePropertyKeys(label).contains(nodeProperty))
56+
.map(NodeLabel::name)
57+
.collect(Collectors.toList());
58+
59+
throw new IllegalArgumentException(formatWithLocale(
60+
"Node property `%s` is not present for all requested labels. Requested labels: %s. Labels without the property key: %s. Properties available on all requested labels: %s",
61+
nodeProperty,
62+
StringJoining.join(selectedLabels.stream().map(NodeLabel::name)),
63+
StringJoining.join(labelsWithMissingProperty),
64+
StringJoining.join(graphStore.nodePropertyKeys(selectedLabels))
65+
));
5566
}
67+
}
68+
5669
}
5770
}

core/src/test/java/org/neo4j/gds/core/loading/validation/NodePropertyAllExistsGraphStoreValidationTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import static org.assertj.core.api.Assertions.assertThatNoException;
3030
import static org.assertj.core.api.Assertions.assertThatThrownBy;
3131
import static org.mockito.ArgumentMatchers.anySet;
32+
import static org.mockito.ArgumentMatchers.anyString;
3233
import static org.mockito.Mockito.doCallRealMethod;
3334
import static org.mockito.Mockito.mock;
3435
import static org.mockito.Mockito.when;
@@ -39,6 +40,7 @@ class NodePropertyAllExistsGraphStoreValidationTest {
3940
void shouldNotThrowForExistingProperty() {
4041
var graphStore = mock(GraphStore.class);
4142
var collectionString = Set.of("p");
43+
when(graphStore.hasNodeProperty(ArgumentMatchers.anyCollection(),anyString())).thenReturn(true);
4244
when(graphStore.nodePropertyKeys(ArgumentMatchers.any(NodeLabel.class))).thenReturn(collectionString);
4345
doCallRealMethod().when(graphStore).nodePropertyKeys(anySet());
4446

@@ -57,6 +59,8 @@ void shouldThrowForNonexistingPropertyInSomeLabels() {
5759

5860
var nodeLabel1 = NodeLabel.of("Node");
5961
var nodeLabel2 = NodeLabel.of("Node1");
62+
when(graphStore.hasNodeProperty(ArgumentMatchers.anyCollection(),anyString())).thenReturn(false);
63+
6064
when(graphStore.nodePropertyKeys(ArgumentMatchers.eq(nodeLabel1))).thenReturn(collectionString1);
6165
when(graphStore.nodePropertyKeys(ArgumentMatchers.eq(nodeLabel2))).thenReturn(collectionString2);
6266
doCallRealMethod().when(graphStore).nodePropertyKeys(anySet());
@@ -66,7 +70,7 @@ void shouldThrowForNonexistingPropertyInSomeLabels() {
6670
graphStore,
6771
Set.of(nodeLabel1,nodeLabel2)
6872
)).hasMessageContaining(
69-
"Node property [p] not found in the graph"
73+
"Node property `p` is not present for all requested labels. Requested labels: ['Node', 'Node1']. Labels without the property key: ['Node']"
7074
);
7175
}
7276

@@ -77,6 +81,7 @@ void shouldThrowForNonexistingPropertyInEveryLabel() {
7781

7882
var nodeLabel1 = NodeLabel.of("Node");
7983
var nodeLabel2 = NodeLabel.of("Node1");
84+
when(graphStore.hasNodeProperty(ArgumentMatchers.anyCollection(),anyString())).thenReturn(false);
8085
when(graphStore.nodePropertyKeys(ArgumentMatchers.eq(nodeLabel1))).thenReturn(collectionString);
8186
when(graphStore.nodePropertyKeys(ArgumentMatchers.eq(nodeLabel2))).thenReturn(collectionString);
8287
doCallRealMethod().when(graphStore).nodePropertyKeys(anySet());
@@ -86,7 +91,7 @@ void shouldThrowForNonexistingPropertyInEveryLabel() {
8691
graphStore,
8792
Set.of(nodeLabel1,nodeLabel2)
8893
)).hasMessageContaining(
89-
"Node property [p] not found in the graph"
94+
"Node property `p` is not present for all requested labels. Requested labels: ['Node', 'Node1']. Labels without the property key: ['Node', 'Node1']"
9095
);
9196
}
9297

0 commit comments

Comments
 (0)