@@ -592,6 +592,58 @@ private void assertRowMetaData(Map<String, Object> row, long count, long left, l
592592 assertEquals (type .name (), row .get ("type" ));
593593 }
594594
595+ @ Test
596+ public void testOutgoingRelsAreCorrectMetaSchema () {
597+ db .executeTransactionally ("CREATE (:A)-[:HAS]->(:B), (:A)<-[:HAS]-(:B), (:A)<-[:HAS]-(:C), (:D)<-[:HAS]-(:E)" );
598+
599+ testCall (db , "CALL apoc.meta.schema" , (row ) -> {
600+ Map <String , Object > o = (Map <String , Object >) row .get ("value" );
601+ // HAS: count 3, no props, type relationship
602+ // A: count 3. no props, relationship out as B
603+ // B: count 2. no props, relationship out as A
604+ // C: count 1. no props, relationship out as A
605+ // D: count 1. no props, relationship in as E
606+ // E: count 1. no props, relationship out as D
607+ Map <String , Object > relHas = (Map <String , Object >) o .get ("HAS" );
608+ Map <String , Object > nodeA = (Map <String , Object >) o .get ("A" );
609+ Map <String , Object > nodeB = (Map <String , Object >) o .get ("B" );
610+ Map <String , Object > nodeC = (Map <String , Object >) o .get ("C" );
611+ Map <String , Object > nodeD = (Map <String , Object >) o .get ("D" );
612+ Map <String , Object > nodeE = (Map <String , Object >) o .get ("E" );
613+ // Check counts
614+ assertEquals (4L , relHas .get ("count" ));
615+ assertEquals (3L , nodeA .get ("count" ));
616+ assertEquals (2L , nodeB .get ("count" ));
617+ assertEquals (1L , nodeC .get ("count" ));
618+ assertEquals (1L , nodeD .get ("count" ));
619+ assertEquals (1L , nodeE .get ("count" ));
620+
621+ Map <String , Object > nodeARels =
622+ (Map <String , Object >) ((Map <String , Object >) nodeA .get ("relationships" )).get ("HAS" );
623+ Map <String , Object > nodeBRels =
624+ (Map <String , Object >) ((Map <String , Object >) nodeB .get ("relationships" )).get ("HAS" );
625+ Map <String , Object > nodeCRels =
626+ (Map <String , Object >) ((Map <String , Object >) nodeC .get ("relationships" )).get ("HAS" );
627+ Map <String , Object > nodeDRels =
628+ (Map <String , Object >) ((Map <String , Object >) nodeD .get ("relationships" )).get ("HAS" );
629+ Map <String , Object > nodeERels =
630+ (Map <String , Object >) ((Map <String , Object >) nodeE .get ("relationships" )).get ("HAS" );
631+ // Check directions
632+ assertEquals ("out" , nodeARels .get ("direction" ));
633+ assertEquals ("out" , nodeBRels .get ("direction" ));
634+ assertEquals ("out" , nodeCRels .get ("direction" ));
635+ assertEquals ("in" , nodeDRels .get ("direction" ));
636+ assertEquals ("out" , nodeERels .get ("direction" ));
637+
638+ // Check end nodes
639+ assertEquals (List .of ("B" ), nodeARels .get ("labels" ));
640+ assertEquals (List .of ("A" ), nodeBRels .get ("labels" ));
641+ assertEquals (List .of ("A" ), nodeCRels .get ("labels" ));
642+ assertEquals (List .of ("E" ), nodeDRels .get ("labels" ));
643+ assertEquals (List .of ("D" ), nodeERels .get ("labels" ));
644+ });
645+ }
646+
595647 @ Test
596648 public void testMetaSchema () {
597649 db .executeTransactionally ("create index for (n:Movie) on (n.title)" );
0 commit comments