Skip to content

Commit 8275283

Browse files
authored
SURF 1040: Fix Zero/inaccurate relationships count from apoc.meta.schema (#935)
1 parent 39a296d commit 8275283

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

core/src/main/java/apoc/meta/MetaRestricted.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ private Map<String, Object> collectNodesMetaData(
759759
"direction",
760760
"out",
761761
"count",
762-
metaItem.rightCount,
762+
metaItem.leftCount,
763763
"labels",
764764
metaItem.other,
765765
"properties",

core/src/test/java/apoc/meta/MetaTest.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import static org.neo4j.graphdb.traversal.Evaluators.toDepth;
3737

3838
import apoc.HelperProcedures;
39+
import apoc.example.Examples;
3940
import apoc.graph.Graphs;
4041
import apoc.nodes.Nodes;
4142
import apoc.util.MapUtil;
@@ -104,7 +105,13 @@ void configure(TestDatabaseManagementServiceBuilder builder) {
104105
@BeforeAll
105106
void setUp() {
106107
TestUtil.registerProcedure(
107-
db, Meta.class, MetaRestricted.class, Graphs.class, Nodes.class, HelperProcedures.class);
108+
db,
109+
Meta.class,
110+
MetaRestricted.class,
111+
Graphs.class,
112+
Nodes.class,
113+
HelperProcedures.class,
114+
Examples.class);
108115
}
109116

110117
public static boolean hasRecordMatching(List<Map<String, Object>> records, Map<String, Object> record) {
@@ -666,6 +673,39 @@ private void assertRowMetaData(Map<String, Object> row, long count, long left, l
666673
assertEquals(type.name(), row.get("type"));
667674
}
668675

676+
@Test
677+
void testMetaSchemaOutgoingRelCountBug() {
678+
db.executeTransactionally("CALL apoc.example.movies()");
679+
testCall(db, "CALL apoc.meta.schema()", (row) -> {
680+
Map<String, Object> schema = (Map<String, Object>) row.get("value");
681+
682+
Map<String, Object> actorRels =
683+
(Map<String, Object>) ((Map<String, Object>) schema.get("Person")).get("relationships");
684+
Map<String, Object> movieRels =
685+
(Map<String, Object>) ((Map<String, Object>) schema.get("Movie")).get("relationships");
686+
687+
assertRelationship(actorRels, "DIRECTED", "out", 44);
688+
assertRelationship(actorRels, "ACTED_IN", "out", 172);
689+
assertRelationship(actorRels, "REVIEWED", "out", 8);
690+
assertRelationship(actorRels, "PRODUCED", "out", 14);
691+
assertRelationship(actorRels, "WROTE", "out", 9);
692+
693+
assertRelationship(movieRels, "DIRECTED", "in", 44);
694+
assertRelationship(movieRels, "ACTED_IN", "in", 172);
695+
assertRelationship(movieRels, "REVIEWED", "in", 8);
696+
assertRelationship(movieRels, "PRODUCED", "in", 14);
697+
assertRelationship(movieRels, "WROTE", "in", 9);
698+
});
699+
}
700+
701+
private void assertRelationship(Map<String, Object> relationships, String relType, String direction, long count) {
702+
Map<String, Object> rel = (Map<String, Object>) relationships.get(relType);
703+
704+
assertNotNull(rel, "Relationship " + relType + " should not be null");
705+
assertEquals(direction, rel.get("direction"));
706+
assertEquals(count, (long) rel.get("count"));
707+
}
708+
669709
@Test
670710
void testOutgoingRelsAreCorrectMetaSchema() {
671711
db.executeTransactionally("CREATE (:A)-[:HAS]->(:B), (:A)<-[:HAS]-(:B), (:A)<-[:HAS]-(:C), (:D)<-[:HAS]-(:E)");

0 commit comments

Comments
 (0)