Skip to content

Commit 7cf6c92

Browse files
s1ckknutwalker
andcommitted
Expose indexInverse in RelationshipProjection
Co-Authored-By: Paul Horn <paul.horn@neotechnology.com>
1 parent 06f891c commit 7cf6c92

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

graph-projection-api/src/main/java/org/neo4j/gds/RelationshipProjection.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public Aggregation aggregation() {
5151
return Aggregation.DEFAULT;
5252
}
5353

54+
@Value.Default
55+
public boolean indexInverse() {
56+
return false;
57+
}
58+
5459
@Value.Default
5560
@Value.Parameter(false)
5661
@Override
@@ -66,6 +71,7 @@ public boolean projectAll() {
6671
public static final String TYPE_KEY = "type";
6772
public static final String ORIENTATION_KEY = "orientation";
6873
public static final String AGGREGATION_KEY = "aggregation";
74+
public static final String INDEX_INVERSE_KEY = "indexInverse";
6975

7076
public static RelationshipProjection fromMap(Map<String, Object> map, RelationshipType relationshipType) {
7177
RelationshipProjection.Builder builder = RelationshipProjection.builder();
@@ -77,6 +83,10 @@ public static RelationshipProjection fromMap(Map<String, Object> map, Relationsh
7783
if (map.containsKey(ORIENTATION_KEY)) {
7884
builder.orientation(Orientation.parse(nonEmptyString(map, ORIENTATION_KEY)));
7985
}
86+
if (map.containsKey(INDEX_INVERSE_KEY)) {
87+
boolean indexInverse = (boolean) map.get(INDEX_INVERSE_KEY);
88+
builder.indexInverse(indexInverse);
89+
}
8090
if (map.containsKey(AGGREGATION_KEY)) {
8191
Aggregation aggregation = Aggregation.parse(nonEmptyString(map, AGGREGATION_KEY));
8292
builder.aggregation(aggregation);
@@ -138,6 +148,7 @@ void writeToObject(Map<String, Object> value) {
138148
value.put(TYPE_KEY, type());
139149
value.put(ORIENTATION_KEY, orientation().name());
140150
value.put(AGGREGATION_KEY, aggregation().name());
151+
value.put(INDEX_INVERSE_KEY, indexInverse());
141152
}
142153

143154
@Override
@@ -170,7 +181,13 @@ private static RelationshipProjection create(
170181
}
171182

172183
private static void validateConfigKeys(Map<String, Object> map) {
173-
ConfigKeyValidation.requireOnlyKeysFrom(List.of(TYPE_KEY, ORIENTATION_KEY, AGGREGATION_KEY, PROPERTIES_KEY), map.keySet());
184+
ConfigKeyValidation.requireOnlyKeysFrom(List.of(
185+
TYPE_KEY,
186+
ORIENTATION_KEY,
187+
AGGREGATION_KEY,
188+
PROPERTIES_KEY,
189+
INDEX_INVERSE_KEY
190+
), map.keySet());
174191
}
175192

176193
@org.immutables.builder.Builder.AccessibleFields

graph-projection-api/src/test/java/org/neo4j/gds/RelationshipProjectionsTest.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@
3838
import static org.hamcrest.MatcherAssert.assertThat;
3939
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
4040
import static org.hamcrest.text.MatchesPattern.matchesPattern;
41+
import static org.junit.jupiter.api.Assertions.assertFalse;
4142
import static org.junit.jupiter.api.Assertions.assertThrows;
43+
import static org.junit.jupiter.api.Assertions.assertTrue;
4244
import static org.neo4j.gds.ElementProjection.PROPERTIES_KEY;
45+
import static org.neo4j.gds.RelationshipProjection.INDEX_INVERSE_KEY;
4346
import static org.neo4j.gds.RelationshipProjection.ORIENTATION_KEY;
4447
import static org.neo4j.gds.RelationshipProjection.TYPE_KEY;
4548
import static org.neo4j.gds.RelationshipType.ALL_RELATIONSHIPS;
@@ -54,7 +57,8 @@ void shouldParse() {
5457
"MY_TYPE", Map.of(
5558
"type", "T",
5659
"orientation", "NATURAL",
57-
"aggregation", "SINGLE"
60+
"aggregation", "SINGLE",
61+
"indexInverse", true
5862
));
5963
noProperties.put(
6064
"ANOTHER", Map.of(
@@ -69,13 +73,20 @@ void shouldParse() {
6973
assertThat(projections.allProjections(), hasSize(2));
7074
assertThat(
7175
projections.getFilter(RelationshipType.of("MY_TYPE")),
72-
equalTo(RelationshipProjection.of("T", Orientation.NATURAL, SINGLE))
73-
);
76+
equalTo(RelationshipProjection
77+
.builder()
78+
.type("T")
79+
.aggregation(SINGLE)
80+
.orientation(Orientation.NATURAL)
81+
.indexInverse(true)
82+
.build()
83+
));
7484
assertThat(
7585
projections.getFilter(RelationshipType.of("ANOTHER")),
7686
equalTo(RelationshipProjection
7787
.builder()
7888
.type("FOO")
89+
.indexInverse(false)
7990
.properties(PropertyMappings
8091
.builder()
8192
.addMapping(PropertyMapping.of("prop1", DefaultValue.DEFAULT))
@@ -221,6 +232,19 @@ void shouldSupportCaseInsensitiveConfigKeys() {
221232
assertThat(projections.typeFilter(), equalTo("T|FOO"));
222233
}
223234

235+
@Test
236+
void shouldHandleIndexInverse() {
237+
// default
238+
var projection = RelationshipProjection.fromMap(Map.of(), RelationshipType.of("FOO"));
239+
assertFalse(projection.indexInverse());
240+
// explicitly set
241+
projection = RelationshipProjection.fromMap(Map.of(INDEX_INVERSE_KEY, true), RelationshipType.of("FOO"));
242+
assertTrue(projection.indexInverse());
243+
// explicitly unset
244+
projection = RelationshipProjection.fromMap(Map.of(INDEX_INVERSE_KEY, false), RelationshipType.of("FOO"));
245+
assertFalse(projection.indexInverse());
246+
}
247+
224248
static Stream<Arguments> syntacticSugarsSimple() {
225249
return Stream.of(
226250
Arguments.of(

0 commit comments

Comments
 (0)