Skip to content

Commit 77d1e01

Browse files
committed
Add test for non-uniform node properties/labels in Cypher Aggregation
1 parent cb38708 commit 77d1e01

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

cypher-aggregation/src/test/java/org/neo4j/gds/projection/CypherAggregationTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,53 @@ void testArbitraryIds() {
162162
}
163163
}
164164

165+
@Test
166+
void testDifferentPropertySchemas() {
167+
var query = "UNWIND [" +
168+
" [0, 1, 'a', {}, 'rel', {}], " +
169+
" [2, 3, 'b', {x:1}, 'rel2', {weight: 0.1}]," +
170+
" [5, 6, 'c', {y:1}, 'rel3', {hq: 0.1}]" +
171+
"] AS data" +
172+
" RETURN gds.alpha.graph.project(" +
173+
" 'g'," +
174+
" data[0]," +
175+
" data[1]," +
176+
" {sourceNodeLabels: data[2], sourceNodeProperties: data[3]}," +
177+
" {relationshipType: data[4], properties: data[5]}," +
178+
" {}" +
179+
")";
180+
181+
runQuery(query);
182+
183+
var graph = GraphStoreCatalog.get("", db.databaseName(), "g").graphStore().getUnion();
184+
185+
// these fail to separate the property schemas
186+
assertThat(graph.schema().nodeSchema().get(NodeLabel.of("a")).properties().keySet()).isEmpty();
187+
assertThat(graph.schema().nodeSchema().get(NodeLabel.of("b")).properties().keySet()).containsExactly("x");
188+
assertThat(graph.schema().nodeSchema().get(NodeLabel.of("c")).properties().keySet()).containsExactly("y");
189+
190+
// these also fail like that, but if one of them has no props (like rel does) no properties are retained at all
191+
// so 2 problems to fix
192+
assertThat(graph
193+
.schema()
194+
.relationshipSchema()
195+
.get(org.neo4j.gds.RelationshipType.of("rel"))
196+
.properties()
197+
.keySet()).isEmpty();
198+
assertThat(graph
199+
.schema()
200+
.relationshipSchema()
201+
.get(org.neo4j.gds.RelationshipType.of("rel2"))
202+
.properties()
203+
.keySet()).containsExactly("weight");
204+
assertThat(graph
205+
.schema()
206+
.relationshipSchema()
207+
.get(org.neo4j.gds.RelationshipType.of("rel3"))
208+
.properties()
209+
.keySet()).containsExactly("hq");
210+
}
211+
165212
@ParameterizedTest
166213
@CsvSource({"13.37, Double", "true, Boolean", "false, Boolean", "null, NO_VALUE", "\"42\", String", "[42], List", "[13.37], List", "{foo:42}, Map", "{foo:13.37}, Map"})
167214
void testInvalidArbitraryIds(String idLiteral, String invalidType) {

0 commit comments

Comments
 (0)