From 38158596aed72ca3a711af80042c764da193194b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 10 Aug 2021 16:47:07 +0200 Subject: [PATCH] Relationships in apoc.meta.schema can have wrong type result with a relatively small sample (#2125) Fixes #1925 Co-authored-by: Giuseppe Villani --- core/src/main/java/apoc/meta/Meta.java | 5 +---- core/src/test/java/apoc/meta/MetaTest.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/apoc/meta/Meta.java b/core/src/main/java/apoc/meta/Meta.java index d7d2929664..14f029195e 100644 --- a/core/src/main/java/apoc/meta/Meta.java +++ b/core/src/main/java/apoc/meta/Meta.java @@ -750,10 +750,7 @@ private Map collectRelationshipsMetaData(MetaStats metaStats, Ma for(String entityName : metaData.keySet()) { Map entityData = metaData.get(entityName); Map entityProperties = new LinkedHashMap<>(); - if (entityData.isEmpty()) { - continue; - } - boolean isRelationship = true; + boolean isRelationship = metaStats.relTypesCount.containsKey(entityName); for (String entityDataKey : entityData.keySet()) { MetaResult metaResult = entityData.get(entityDataKey); if (!metaResult.elementType.equals("relationship")) { diff --git a/core/src/test/java/apoc/meta/MetaTest.java b/core/src/test/java/apoc/meta/MetaTest.java index 21810bd316..d60e241b2e 100644 --- a/core/src/test/java/apoc/meta/MetaTest.java +++ b/core/src/test/java/apoc/meta/MetaTest.java @@ -444,6 +444,20 @@ public void testMetaSchemaWithNodesAndRelsWithoutProps() { assertEquals(1L, rel2.get("count")); }); } + + @Test + public void testMetaSchemaWithSmallSampleAndRelationships() { + final List labels = List.of("Other", "Foo"); + db.executeTransactionally("CREATE (:Foo), (:Other)-[:REL_0]->(:Other), (:Other)-[:REL_1]->(:Other)<-[:REL_2 {baz: 'baa'}]-(:Other), (:Other {alpha: 'beta'}), (:Other {foo:'bar'})-[:REL_3]->(:Other)"); + testCall(db, "CALL apoc.meta.schema({sample: 2})", + (row) -> ((Map>) row.get("value")).forEach((key, value) -> { + if (labels.contains(key)) { + assertEquals("node", value.get("type")); + } else { + assertEquals("relationship", value.get("type")); + } + })); + } @Test public void testSubGraphNoLimits() throws Exception {