Skip to content

Commit debf2be

Browse files
committed
Normalize SingleTypeRelationshipImportResult on creation
1 parent 2bb2e19 commit debf2be

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

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

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

22-
import org.immutables.value.Value;
2322
import org.neo4j.gds.annotation.ValueClass;
2423

2524
import java.util.Collection;
@@ -32,6 +31,10 @@ public interface RelationshipPropertyStore {
3231

3332
Map<String, RelationshipProperty> relationshipProperties();
3433

34+
default boolean isEmpty() {
35+
return relationshipProperties().isEmpty();
36+
}
37+
3538
default RelationshipProperty get(String propertyKey) {
3639
return relationshipProperties().get(propertyKey);
3740
}
@@ -48,13 +51,6 @@ default boolean containsKey(String propertyKey) {
4851
return relationshipProperties().containsKey(propertyKey);
4952
}
5053

51-
@Value.Check
52-
default void validate() {
53-
if (relationshipProperties().isEmpty()) {
54-
throw new IllegalStateException("Relationship property store must not be empty.");
55-
}
56-
}
57-
5854
static Builder builder() {
5955
// need to initialize with empty map due to `deferCollectionAllocation = true`
6056
return new Builder().relationshipProperties(Collections.emptyMap());

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
package org.neo4j.gds.core.loading;
2121

22+
import org.immutables.value.Value;
2223
import org.neo4j.gds.annotation.ValueClass;
2324
import org.neo4j.gds.api.RelationshipPropertyStore;
2425
import org.neo4j.gds.api.Relationships;
@@ -42,6 +43,17 @@ public interface SingleTypeRelationshipImportResult {
4243

4344
Optional<RelationshipPropertyStore> inverseProperties();
4445

46+
@Value.Check
47+
default SingleTypeRelationshipImportResult normalize() {
48+
if (properties().map(RelationshipPropertyStore::isEmpty).orElse(false)) {
49+
return builder().from(this).properties(Optional.empty()).build();
50+
}
51+
if (inverseProperties().map(RelationshipPropertyStore::isEmpty).orElse(false)) {
52+
return builder().from(this).inverseProperties(Optional.empty()).build();
53+
}
54+
return this;
55+
}
56+
4557
static ImmutableSingleTypeRelationshipImportResult.Builder builder() {
4658
return ImmutableSingleTypeRelationshipImportResult.builder();
4759
}

0 commit comments

Comments
 (0)