Skip to content

Commit

Permalink
Relationships in apoc.meta.schema can have wrong type result with a r…
Browse files Browse the repository at this point in the history
…elatively small sample (#2125)

Fixes #1925

Co-authored-by: Giuseppe Villani <[email protected]>
  • Loading branch information
2 people authored and conker84 committed Aug 10, 2021
1 parent b6970ab commit 3815859
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 1 addition & 4 deletions core/src/main/java/apoc/meta/Meta.java
Original file line number Diff line number Diff line change
Expand Up @@ -750,10 +750,7 @@ private Map<String, Object> collectRelationshipsMetaData(MetaStats metaStats, Ma
for(String entityName : metaData.keySet()) {
Map<String, MetaResult> entityData = metaData.get(entityName);
Map<String, Object> 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")) {
Expand Down
14 changes: 14 additions & 0 deletions core/src/test/java/apoc/meta/MetaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,20 @@ public void testMetaSchemaWithNodesAndRelsWithoutProps() {
assertEquals(1L, rel2.get("count"));
});
}

@Test
public void testMetaSchemaWithSmallSampleAndRelationships() {
final List<String> 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<String, Map<String, Object>>) 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 {
Expand Down

0 comments on commit 3815859

Please sign in to comment.