Skip to content

Commit 120436c

Browse files
s1ckMats-SXjjaderberg
committed
Move tupled version of GraphStore#relationshipPropertyKeys to call site
Co-authored-by: Mats Rydberg <[email protected]> Co-authored-by: Jonatan Jäderberg <[email protected]>
1 parent 745979c commit 120436c

File tree

4 files changed

+29
-33
lines changed

4 files changed

+29
-33
lines changed

compatibility/3.5/neo4j-export-adapter/src/main/java/org/neo4j/graphalgo/core/utils/export/GraphStoreInput.java

+13-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.neo4j.graphalgo.core.utils.export;
2121

2222
import org.eclipse.collections.api.tuple.Pair;
23+
import org.eclipse.collections.impl.tuple.Tuples;
2324
import org.neo4j.graphalgo.api.Graph;
2425
import org.neo4j.graphalgo.api.RelationshipIterator;
2526
import org.neo4j.graphalgo.core.loading.GraphStore;
@@ -42,6 +43,7 @@
4243
import java.util.Set;
4344
import java.util.function.ToIntFunction;
4445
import java.util.stream.Collectors;
46+
import java.util.stream.Stream;
4547

4648
public final class GraphStoreInput implements Input {
4749

@@ -139,13 +141,17 @@ static class RelationshipImporter extends GraphImporter {
139141

140142
RelationshipImporter(GraphStore graphStore, long nodeCount, int batchSize) {
141143
super(nodeCount, batchSize);
142-
relationships = graphStore
143-
.relationshipPropertyKeys()
144-
.stream()
145-
.collect(Collectors.toMap(
146-
relTypeAndProperty -> relTypeAndProperty,
147-
relTypeAndProperty -> graphStore.getGraph(relTypeAndProperty.getOne(), relTypeAndProperty.getTwo())
148-
));
144+
relationships = graphStore.relationshipTypes().stream().flatMap(relType -> {
145+
Set<String> relProperties = graphStore.relationshipPropertyKeys(relType);
146+
if (relProperties.isEmpty()) {
147+
return Stream.of(Tuples.pair(relType, Optional.<String>empty()));
148+
} else {
149+
return relProperties.stream().map(propertyKey -> Tuples.pair(relType, Optional.of(propertyKey)));
150+
}
151+
}).collect(Collectors.toMap(
152+
relTypeAndProperty -> relTypeAndProperty,
153+
relTypeAndProperty -> graphStore.getGraph(relTypeAndProperty.getOne(), relTypeAndProperty.getTwo())
154+
));
149155
}
150156

151157
@Override

compatibility/4.0/neo4j-export-adapter/src/main/java/org/neo4j/graphalgo/core/utils/export/GraphStoreInput.java

+13-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.neo4j.graphalgo.core.utils.export;
2121

2222
import org.eclipse.collections.api.tuple.Pair;
23+
import org.eclipse.collections.impl.tuple.Tuples;
2324
import org.neo4j.graphalgo.api.Graph;
2425
import org.neo4j.graphalgo.api.RelationshipIterator;
2526
import org.neo4j.graphalgo.core.loading.GraphStore;
@@ -41,6 +42,7 @@
4142
import java.util.Set;
4243
import java.util.function.ToIntFunction;
4344
import java.util.stream.Collectors;
45+
import java.util.stream.Stream;
4446

4547
public final class GraphStoreInput implements Input {
4648

@@ -139,13 +141,17 @@ static class RelationshipImporter extends GraphImporter {
139141

140142
RelationshipImporter(GraphStore graphStore, long nodeCount, int batchSize) {
141143
super(nodeCount, batchSize);
142-
relationships = graphStore
143-
.relationshipPropertyKeys()
144-
.stream()
145-
.collect(Collectors.toMap(
146-
relTypeAndProperty -> relTypeAndProperty,
147-
relTypeAndProperty -> graphStore.getGraph(relTypeAndProperty.getOne(), relTypeAndProperty.getTwo())
148-
));
144+
relationships = graphStore.relationshipTypes().stream().flatMap(relType -> {
145+
Set<String> relProperties = graphStore.relationshipPropertyKeys(relType);
146+
if (relProperties.isEmpty()) {
147+
return Stream.of(Tuples.pair(relType, Optional.<String>empty()));
148+
} else {
149+
return relProperties.stream().map(propertyKey -> Tuples.pair(relType, Optional.of(propertyKey)));
150+
}
151+
}).collect(Collectors.toMap(
152+
relTypeAndProperty -> relTypeAndProperty,
153+
relTypeAndProperty -> graphStore.getGraph(relTypeAndProperty.getOne(), relTypeAndProperty.getTwo())
154+
));
149155
}
150156

151157
@Override

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

+2-18
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
package org.neo4j.graphalgo.core.loading;
2121

2222
import com.carrotsearch.hppc.BitSet;
23-
import org.eclipse.collections.api.tuple.Pair;
24-
import org.eclipse.collections.impl.tuple.Tuples;
2523
import org.neo4j.graphalgo.ElementIdentifier;
2624
import org.neo4j.graphalgo.api.Graph;
2725
import org.neo4j.graphalgo.api.IdMapping;
@@ -180,30 +178,16 @@ public long relationshipPropertyCount() {
180178
.sum();
181179
}
182180

183-
public Set<String> availableRelationshipPropertyKeys() {
181+
public Set<String> relationshipPropertyKeys() {
184182
return relationshipProperties
185183
.values()
186184
.stream()
187185
.flatMap(properties -> properties.keySet().stream())
188186
.collect(Collectors.toSet());
189187
}
190188

191-
public Set<Pair<String, Optional<String>>> relationshipPropertyKeys() {
192-
return this.relationshipTypes().stream().flatMap(relType -> {
193-
if (relationshipProperties.containsKey(relType)) {
194-
return relationshipProperties
195-
.get(relType)
196-
.keySet()
197-
.stream()
198-
.map(propertyKey -> Tuples.pair(relType, Optional.of(propertyKey)));
199-
} else {
200-
return Stream.of(Tuples.pair(relType, Optional.<String>empty()));
201-
}
202-
}).collect(Collectors.toSet());
203-
}
204-
205189
public Set<String> relationshipPropertyKeys(String relationshipType) {
206-
return relationshipProperties.get(relationshipType).keySet();
190+
return relationshipProperties.getOrDefault(relationshipType, Collections.emptyMap()).keySet();
207191
}
208192

209193
public synchronized void addRelationshipType(String relationshipType, Optional<String> relationshipProperty, HugeGraph.Relationships relationships) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ private void validate(GraphStoreWithConfig graphStoreWithConfig, CONFIG config)
286286
}
287287
}
288288
if (config instanceof RelationshipWeightConfig) {
289-
Set<String> properties = graphStore.availableRelationshipPropertyKeys();
289+
Set<String> properties = graphStore.relationshipPropertyKeys();
290290

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

0 commit comments

Comments
 (0)