Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1952: apoc.meta.stats for 4.1.0.8 fails whereas 4.1.0.3 succeeds when a rel is back ticked #1963

Merged
merged 1 commit into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Iterator;

import static apoc.export.cypher.formatter.CypherFormatterUtils.cypherNode;
import static apoc.util.Util.quote;

public class DatabaseSubGraph implements SubGraph
{
Expand Down Expand Up @@ -85,15 +86,15 @@ public Iterable<Label> getAllLabelsInUse() {
public long countsForRelationship(Label start, RelationshipType type, Label end) {
String startNode = cypherNode(start);
String endNode = cypherNode(end);
String relationship = String.format("[r:%s]", type.name());
String relationship = String.format("[r:%s]", quote(type.name()));
return transaction.execute(String.format("MATCH %s-%s->%s RETURN count(r) AS count", startNode, relationship, endNode))
.<Long>columnAs("count")
.next();
}

@Override
public long countsForNode(Label label) {
return transaction.execute(String.format("MATCH (n:%s) RETURN count(n) AS count", label.name()))
return transaction.execute(String.format("MATCH (n:%s) RETURN count(n) AS count", quote(label.name())))
.<Long>columnAs("count")
.next();
}
Expand Down
16 changes: 16 additions & 0 deletions core/src/test/java/apoc/meta/MetaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1073,4 +1073,20 @@ public void testMetaGraphOf() throws Exception {
"RETURN *",
assertResult);
}

@Test
public void testMetaStatsWithTwoDots() {
db.executeTransactionally("CREATE (n:`My:Label` {id:1})-[r:`http://www.w3.org/2000/01/rdf-schema#isDefinedBy` {alpha: 'beta'}]->(s:Another)");
TestUtil.testCall(db, "CALL apoc.meta.stats()", row -> {
assertEquals(map("My:Label", 1L, "Another", 1L), row.get("labels"));
assertEquals(2L, row.get("labelCount"));
assertEquals(map("http://www.w3.org/2000/01/rdf-schema#isDefinedBy", 1L), row.get("relTypesCount"));
assertEquals(2L, row.get("propertyKeyCount"));
assertEquals(map("()-[:http://www.w3.org/2000/01/rdf-schema#isDefinedBy]->(:Another)", 1L,
"()-[:http://www.w3.org/2000/01/rdf-schema#isDefinedBy]->()", 1L,
"(:My:Label)-[:http://www.w3.org/2000/01/rdf-schema#isDefinedBy]->()",1L),
row.get("relTypes"));
});

}
}