Skip to content

Commit

Permalink
apoc.meta.data count adoc/test (#2904) (#3067)
Browse files Browse the repository at this point in the history
* apoc.meta.data count adoc/test
* changes review
* changed counts implementation
* removed leftCount and rightCount from docs / results
* small review changes adoc
  • Loading branch information
vga91 authored Jul 25, 2022
1 parent ccc6305 commit b058516
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 99 deletions.
122 changes: 63 additions & 59 deletions core/src/main/java/apoc/meta/Meta.java

Large diffs are not rendered by default.

106 changes: 89 additions & 17 deletions core/src/test/java/apoc/meta/MetaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -339,20 +339,92 @@ public void testMetaGraph2() throws Exception {
}

@Test
public void testMetaData() throws Exception {
public void testMetaData() {
db.executeTransactionally("create index on :Movie(title)");
db.executeTransactionally("create constraint on (a:Actor) assert a.name is unique");
db.executeTransactionally("CREATE (:Actor {name:'Tom Hanks'})-[:ACTED_IN {roles:'Forrest'}]->(:Movie {title:'Forrest Gump'}) ");
TestUtil.testResult(db, "CALL apoc.meta.data()",
(r) -> {
int count = 0;
while (r.hasNext()) {
Map<String, Object> row = r.next();
// todo more assertions
count ++;
}
assertEquals(5,count);
});
db.executeTransactionally("CREATE (actor1:Actor {name:'Tom Hanks'})-[:ACTED_IN {roles:'Forrest'}]->(movie1:Movie {title:'Forrest Gump'}), \n" +
"(actor2:Actor {name: 'Bruce Lee'})-[:ACTED_IN {roles:'FooBaz'}]->(movie1),\n" +
"(actor1)-[:ACTED_IN {roles:'Movie2Role'}]->(movie2:Movie {title:'Movie2'}), (actor1)-[:ACTED_IN {roles:'Movie3Role'}]->(movie3:Movie {title:'Movie3'}),\n" +
"(actor1)-[:DIRECTED {foo: 'first'}]->(movie2), (actor1)-[:DIRECTED {foo: 'second'}]->(:Movie {title:'Movie4'}),\n" +
"(:Studio {name: 'Pixar'})-[:ANIMATED {bar: 'alpha'}]->(movie2)");
TestUtil.testResult(db, "CALL apoc.meta.data() \n" +
"YIELD label, property, count, unique, index, existence, type, array, left, right, other, otherLabels, elementType\n" +
"RETURN * ORDER BY elementType, property", (r) -> {
Map<String, Object> row = r.next();
assertEquals("node", row.get("elementType"));
assertEquals("ACTED_IN", row.get("property"));
assertEquals("Actor", row.get("label"));
assertRelationshipActedInMetaData(row);
row = r.next();
assertEquals("node", row.get("elementType"));
assertEquals("ANIMATED", row.get("property"));
assertEquals("Studio", row.get("label"));
assertRelationshipsAnimatedMetaData(row);
row = r.next();
assertEquals("node", row.get("elementType"));
assertEquals("DIRECTED", row.get("property"));
assertEquals("Actor", row.get("label"));
assertRelationshipsDirectedMetaData(row);
row = r.next();
assertEquals("node", row.get("elementType"));
assertPropertiesMetaData(row);
row = r.next();
assertEquals("node", row.get("elementType"));
assertPropertiesMetaData(row);
row = r.next();
assertEquals("node", row.get("elementType"));
assertPropertiesMetaData(row);
row = r.next();
assertEquals("relationship", row.get("elementType"));
assertEquals("ACTED_IN", row.get("label"));
assertEquals("Actor", row.get("property"));
assertRelationshipActedInMetaData(row);
row = r.next();
assertEquals("relationship", row.get("elementType"));
assertEquals("DIRECTED", row.get("label"));
assertEquals("Actor", row.get("property"));
assertRelationshipsDirectedMetaData(row);
row = r.next();
assertEquals("relationship", row.get("elementType"));
assertEquals("ANIMATED", row.get("label"));
assertEquals("Studio", row.get("property"));
assertRelationshipsAnimatedMetaData(row);
row = r.next();
assertEquals("relationship", row.get("elementType"));
assertPropertiesMetaData(row);
row = r.next();
assertEquals("relationship", row.get("elementType"));
assertPropertiesMetaData(row);
row = r.next();
assertEquals("relationship", row.get("elementType"));
assertPropertiesMetaData(row);
assertFalse(r.hasNext());
});
}

private void assertRelationshipsDirectedMetaData(Map<String, Object> row) {
assertRowMetaData(row, 1L, 2L, 0L, Meta.Types.RELATIONSHIP);
}

private void assertRelationshipsAnimatedMetaData(Map<String, Object> row) {
assertRowMetaData(row, 1L,1L, 0L, Meta.Types.RELATIONSHIP);
}

private void assertRelationshipActedInMetaData(Map<String, Object> row) {
assertRowMetaData(row, 2L, 2L, 0L, Meta.Types.RELATIONSHIP);
}

private void assertPropertiesMetaData(Map<String, Object> row) {
assertRowMetaData(row, 0L, 0L, 0L, Meta.Types.STRING);
}

private void assertRowMetaData(Map<String, Object> row,
long count, long left, long right,
Meta.Types type) {
assertEquals(count, row.get("count"));
assertEquals(left, row.get("left"));
assertEquals(right, row.get("right"));
assertEquals(type.name(), row.get("type"));
}

@Test
Expand Down Expand Up @@ -1430,11 +1502,11 @@ public void testMetaDataOf() throws Exception {
db.executeTransactionally("CREATE (p:Person {name:'Tom Hanks'}), (m:Movie {title:'Forrest Gump'}), (pr:Product{name: 'Awesome Product'}), " +
"(p)-[:VIEWED]->(m), (p)-[:BOUGHT{quantity: 10}]->(pr)");
Set<Map<String, Object>> expectedResult = new HashSet<>();
expectedResult.add(MapUtil.map("other",List.of(),"count",0L,"existence",false,"index",false,"label","BOUGHT","right",0L,"type","INTEGER","sample",null,"rightCount",0L,"leftCount",0L,"array",false,"left",0L,"unique",false,"property","quantity","elementType","relationship","otherLabels",List.of()));
expectedResult.add(MapUtil.map("other",List.of(),"count",0L,"existence",false,"index",false,"label","Product","right",0L,"type","STRING","sample",null,"rightCount",0L,"leftCount",0L,"array",false,"left",0L,"unique",false,"property","name","elementType","node","otherLabels",List.of()));
expectedResult.add(MapUtil.map("other",List.of("Product"),"count",1L,"existence",false,"index",false,"label","BOUGHT","right",1L,"type","RELATIONSHIP","sample",null,"rightCount",1L,"leftCount",1L,"array",false,"left",1L,"unique",false,"property","Person","elementType","relationship","otherLabels",List.of()));
expectedResult.add(MapUtil.map("other",List.of("Product"),"count",1L,"existence",false,"index",false,"label","Person","right",1L,"type","RELATIONSHIP","sample",null,"rightCount",1L,"leftCount",1L,"array",false,"left",1L,"unique",false,"property","BOUGHT","elementType","node","otherLabels",List.of()));
expectedResult.add(MapUtil.map("other",List.of(),"count",0L,"existence",false,"index",false,"label","Person","right",0L,"type","STRING","sample",null,"rightCount",0L,"leftCount",0L,"array",false,"left",0L,"unique",false,"property","name","elementType","node","otherLabels",List.of()));
expectedResult.add(MapUtil.map("other",List.of(),"count",0L,"existence",false,"index",false,"label","BOUGHT","right",0L,"type","INTEGER","sample",null,"array",false,"left",0L,"unique",false,"property","quantity","elementType","relationship","otherLabels",List.of()));
expectedResult.add(MapUtil.map("other",List.of(),"count",0L,"existence",false,"index",false,"label","Product","right",0L,"type","STRING","sample",null,"array",false,"left",0L,"unique",false,"property","name","elementType","node","otherLabels",List.of()));
expectedResult.add(MapUtil.map("other",List.of("Product"),"count",1L,"existence",false,"index",false,"label","BOUGHT","right",0L,"type","RELATIONSHIP","sample",null,"array",false,"left",1L,"unique",false,"property","Person","elementType","relationship","otherLabels",List.of()));
expectedResult.add(MapUtil.map("other",List.of("Product"),"count",1L,"existence",false,"index",false,"label","Person","right",0L,"type","RELATIONSHIP","sample",null,"array",false,"left",1L,"unique",false,"property","BOUGHT","elementType","node","otherLabels",List.of()));
expectedResult.add(MapUtil.map("other",List.of(),"count",0L,"existence",false,"index",false,"label","Person","right",0L,"type","STRING","sample",null,"array",false,"left",0L,"unique",false,"property","name","elementType","node","otherLabels",List.of()));

String keys = expectedResult.stream()
.findAny()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
¦signature
¦apoc.meta.data(config = {} :: MAP?) :: (label :: STRING?, property :: STRING?, count :: INTEGER?, unique :: BOOLEAN?, index :: BOOLEAN?, existence :: BOOLEAN?, type :: STRING?, array :: BOOLEAN?, sample :: LIST? OF ANY?, leftCount :: INTEGER?, rightCount :: INTEGER?, left :: INTEGER?, right :: INTEGER?, other :: LIST? OF STRING?, otherLabels :: LIST? OF STRING?, elementType :: STRING?)
¦apoc.meta.data(config = {} :: MAP?) :: (label :: STRING?, property :: STRING?, count :: INTEGER?, unique :: BOOLEAN?, index :: BOOLEAN?, existence :: BOOLEAN?, type :: STRING?, array :: BOOLEAN?, sample :: LIST? OF ANY?, left :: INTEGER?, right :: INTEGER?, other :: LIST? OF STRING?, otherLabels :: LIST? OF STRING?, elementType :: STRING?)
¦apoc.meta.data.of(graph :: ANY?, config = {} :: MAP?) :: (label :: STRING?, property :: STRING?, count :: INTEGER?, unique :: BOOLEAN?, index :: BOOLEAN?, existence :: BOOLEAN?, type :: STRING?, array :: BOOLEAN?, sample :: LIST? OF ANY?, left :: INTEGER?, right :: INTEGER?, other :: LIST? OF STRING?, otherLabels :: LIST? OF STRING?, elementType :: STRING?)
¦apoc.meta.graph(config = {} :: MAP?) :: (nodes :: LIST? OF NODE?, relationships :: LIST? OF RELATIONSHIP?)
¦apoc.meta.graphSample(config = {} :: MAP?) :: (nodes :: LIST? OF NODE?, relationships :: LIST? OF RELATIONSHIP?)
¦apoc.meta.nodeTypeProperties(config = {} :: MAP?) :: (nodeType :: STRING?, nodeLabels :: LIST? OF STRING?, propertyName :: STRING?, propertyTypes :: LIST? OF STRING?, mandatory :: BOOLEAN?, propertyObservations :: INTEGER?, totalObservations :: INTEGER?)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
¦signature
¦apoc.meta.data(config = {} :: MAP?) :: (label :: STRING?, property :: STRING?, count :: INTEGER?, unique :: BOOLEAN?, index :: BOOLEAN?, existence :: BOOLEAN?, type :: STRING?, array :: BOOLEAN?, sample :: LIST? OF ANY?, leftCount :: INTEGER?, rightCount :: INTEGER?, left :: INTEGER?, right :: INTEGER?, other :: LIST? OF STRING?, otherLabels :: LIST? OF STRING?, elementType :: STRING?)
¦apoc.meta.data(config = {} :: MAP?) :: (label :: STRING?, property :: STRING?, count :: INTEGER?, unique :: BOOLEAN?, index :: BOOLEAN?, existence :: BOOLEAN?, type :: STRING?, array :: BOOLEAN?, sample :: LIST? OF ANY?, left :: INTEGER?, right :: INTEGER?, other :: LIST? OF STRING?, otherLabels :: LIST? OF STRING?, elementType :: STRING?)
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
¦signature
¦apoc.meta.data.of(graph :: ANY?, config = {} :: MAP?) :: (label :: STRING?, property :: STRING?, count :: INTEGER?, unique :: BOOLEAN?, index :: BOOLEAN?, existence :: BOOLEAN?, type :: STRING?, array :: BOOLEAN?, sample :: LIST? OF ANY?, leftCount :: INTEGER?, rightCount :: INTEGER?, left :: INTEGER?, right :: INTEGER?, other :: LIST? OF STRING?, otherLabels :: LIST? OF STRING?, elementType :: STRING?)
¦apoc.meta.data.of(graph :: ANY?, config = {} :: MAP?) :: (label :: STRING?, property :: STRING?, count :: INTEGER?, unique :: BOOLEAN?, index :: BOOLEAN?, existence :: BOOLEAN?, type :: STRING?, array :: BOOLEAN?, sample :: LIST? OF ANY?, left :: INTEGER?, right :: INTEGER?, other :: LIST? OF STRING?, otherLabels :: LIST? OF STRING?, elementType :: STRING?)
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
¦type¦qualified name¦signature¦description
¦procedure¦apoc.meta.data.of¦apoc.meta.data.of(graph = {} :: ANY?, config = {} :: MAP?) :: (label :: STRING?, property :: STRING?, count :: INTEGER?, unique :: BOOLEAN?, index :: BOOLEAN?, existence :: BOOLEAN?, type :: STRING?, array :: BOOLEAN?, sample :: LIST? OF ANY?, leftCount :: INTEGER?, rightCount :: INTEGER?, left :: INTEGER?, right :: INTEGER?, other :: LIST? OF STRING?, otherLabels :: LIST? OF STRING?, elementType :: STRING?)¦apoc.meta.data.of(\{graph}, \{config}) - examines a subset of the graph to provide a tabular meta information
¦procedure¦apoc.meta.data.of¦apoc.meta.data.of(graph = {} :: ANY?, config = {} :: MAP?) :: (label :: STRING?, property :: STRING?, count :: INTEGER?, unique :: BOOLEAN?, index :: BOOLEAN?, existence :: BOOLEAN?, type :: STRING?, array :: BOOLEAN?, sample :: LIST? OF ANY?, left :: INTEGER?, right :: INTEGER?, other :: LIST? OF STRING?, otherLabels :: LIST? OF STRING?, elementType :: STRING?)¦apoc.meta.data.of(\{graph}, \{config}) - examines a subset of the graph to provide a tabular meta information
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@
¦procedure¦apoc.merge.node.eager¦apoc.merge.node.eager(label :: LIST? OF STRING?, identProps :: MAP?, props = {} :: MAP?, onMatchProps = {} :: MAP?) :: (node :: NODE?)¦apoc.merge.node.eager(['Label'], identProps:{key:value, ...}, onCreateProps:{key:value,...}, onMatchProps:{key:value,...}}) - merge nodes eagerly, with dynamic labels, with support for setting properties ON CREATE or ON MATCH¦true¦xref::graph-updates/data-creation.adoc
¦procedure¦apoc.merge.relationship¦apoc.merge.relationship(startNode :: NODE?, relationshipType :: STRING?, identProps :: MAP?, props :: MAP?, endNode :: NODE?, onMatchProps = {} :: MAP?) :: (rel :: RELATIONSHIP?)¦apoc.merge.relationship(startNode, relType, identProps:{key:value, ...}, onCreateProps:{key:value, ...}, endNode, onMatchProps:{key:value, ...}) - merge relationship with dynamic type, with support for setting properties ON CREATE or ON MATCH¦true¦xref::graph-updates/data-creation.adoc
¦procedure¦apoc.merge.relationship.eager¦apoc.merge.relationship.eager(startNode :: NODE?, relationshipType :: STRING?, identProps :: MAP?, props :: MAP?, endNode :: NODE?, onMatchProps = {} :: MAP?) :: (rel :: RELATIONSHIP?)¦apoc.merge.relationship(startNode, relType, identProps:{key:value, ...}, onCreateProps:{key:value, ...}, endNode, onMatchProps:{key:value, ...}) - merge relationship with dynamic type, with support for setting properties ON CREATE or ON MATCH¦true¦xref::graph-updates/data-creation.adoc
¦procedure¦apoc.meta.data¦apoc.meta.data(config = {} :: MAP?) :: (label :: STRING?, property :: STRING?, count :: INTEGER?, unique :: BOOLEAN?, index :: BOOLEAN?, existence :: BOOLEAN?, type :: STRING?, array :: BOOLEAN?, sample :: LIST? OF ANY?, leftCount :: INTEGER?, rightCount :: INTEGER?, left :: INTEGER?, right :: INTEGER?, other :: LIST? OF STRING?, otherLabels :: LIST? OF STRING?, elementType :: STRING?)¦apoc.meta.data(\{config}) - examines a subset of the graph to provide a tabular meta information¦true¦
¦procedure¦apoc.meta.data.of¦apoc.meta.data.of(graph :: ANY?, config = {} :: MAP?) :: (label :: STRING?, property :: STRING?, count :: INTEGER?, unique :: BOOLEAN?, index :: BOOLEAN?, existence :: BOOLEAN?, type :: STRING?, array :: BOOLEAN?, sample :: LIST? OF ANY?, leftCount :: INTEGER?, rightCount :: INTEGER?, left :: INTEGER?, right :: INTEGER?, other :: LIST? OF STRING?, otherLabels :: LIST? OF STRING?, elementType :: STRING?)¦apoc.meta.data.of(\{graph}, \{config}) - examines a subset of the graph to provide a tabular meta information¦true¦
¦procedure¦apoc.meta.data¦apoc.meta.data(config = {} :: MAP?) :: (label :: STRING?, property :: STRING?, count :: INTEGER?, unique :: BOOLEAN?, index :: BOOLEAN?, existence :: BOOLEAN?, type :: STRING?, array :: BOOLEAN?, sample :: LIST? OF ANY?, left :: INTEGER?, right :: INTEGER?, other :: LIST? OF STRING?, otherLabels :: LIST? OF STRING?, elementType :: STRING?)¦apoc.meta.data(\{config}) - examines a subset of the graph to provide a tabular meta information¦true¦
¦procedure¦apoc.meta.data.of¦apoc.meta.data.of(graph :: ANY?, config = {} :: MAP?) :: (label :: STRING?, property :: STRING?, count :: INTEGER?, unique :: BOOLEAN?, index :: BOOLEAN?, existence :: BOOLEAN?, type :: STRING?, array :: BOOLEAN?, sample :: LIST? OF ANY?, left :: INTEGER?, right :: INTEGER?, other :: LIST? OF STRING?, otherLabels :: LIST? OF STRING?, elementType :: STRING?)¦apoc.meta.data.of(\{graph}, \{config}) - examines a subset of the graph to provide a tabular meta information¦true¦
¦procedure¦apoc.meta.graph¦apoc.meta.graph(config = {} :: MAP?) :: (nodes :: LIST? OF NODE?, relationships :: LIST? OF RELATIONSHIP?)¦apoc.meta.graph - examines the full graph to create the meta-graph¦true¦
¦procedure¦apoc.meta.graph.of¦apoc.meta.graph.of(graph = {} :: ANY?, config = {} :: MAP?) :: (nodes :: LIST? OF NODE?, relationships :: LIST? OF RELATIONSHIP?)¦apoc.meta.graph.of(\{graph}, \{config}) - examines a subset of the graph to provide a graph meta information¦true¦
¦procedure¦apoc.meta.graphSample¦apoc.meta.graphSample(config = {} :: MAP?) :: (nodes :: LIST? OF NODE?, relationships :: LIST? OF RELATIONSHIP?)¦apoc.meta.graphSample() - examines the database statistics to build the meta graph, very fast, might report extra relationships¦true¦
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apoc.meta.data(\{config}) - examines a subset of the graph to provide a tabular

[source]
----
apoc.meta.data(config = {} :: MAP?) :: (label :: STRING?, property :: STRING?, count :: INTEGER?, unique :: BOOLEAN?, index :: BOOLEAN?, existence :: BOOLEAN?, type :: STRING?, array :: BOOLEAN?, sample :: LIST? OF ANY?, leftCount :: INTEGER?, rightCount :: INTEGER?, left :: INTEGER?, right :: INTEGER?, other :: LIST? OF STRING?, otherLabels :: LIST? OF STRING?, elementType :: STRING?)
apoc.meta.data(config = {} :: MAP?) :: (label :: STRING?, property :: STRING?, count :: INTEGER?, unique :: BOOLEAN?, index :: BOOLEAN?, existence :: BOOLEAN?, type :: STRING?, array :: BOOLEAN?, sample :: LIST? OF ANY?, left :: INTEGER?, right :: INTEGER?, other :: LIST? OF STRING?, otherLabels :: LIST? OF STRING?, elementType :: STRING?)
----

== Input parameters
Expand All @@ -40,8 +40,6 @@ include::partial$usage/config/apoc.meta.data.adoc[]
|type|STRING?
|array|BOOLEAN?
|sample|LIST? OF ANY?
|leftCount|INTEGER?
|rightCount|INTEGER?
|left|INTEGER?
|right|INTEGER?
|other|LIST? OF STRING?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apoc.meta.data.of(\{graph}, \{config}) - examines a subset of the graph to prov

[source]
----
apoc.meta.data.of(graph :: ANY?, config = {} :: MAP?) :: (label :: STRING?, property :: STRING?, count :: INTEGER?, unique :: BOOLEAN?, index :: BOOLEAN?, existence :: BOOLEAN?, type :: STRING?, array :: BOOLEAN?, sample :: LIST? OF ANY?, leftCount :: INTEGER?, rightCount :: INTEGER?, left :: INTEGER?, right :: INTEGER?, other :: LIST? OF STRING?, otherLabels :: LIST? OF STRING?, elementType :: STRING?)
apoc.meta.data.of(graph :: ANY?, config = {} :: MAP?) :: (label :: STRING?, property :: STRING?, count :: INTEGER?, unique :: BOOLEAN?, index :: BOOLEAN?, existence :: BOOLEAN?, type :: STRING?, array :: BOOLEAN?, sample :: LIST? OF ANY?, left :: INTEGER?, right :: INTEGER?, other :: LIST? OF STRING?, otherLabels :: LIST? OF STRING?, elementType :: STRING?)
----

== Input parameters
Expand All @@ -41,8 +41,6 @@ include::partial$usage/config/apoc.meta.data.of.adoc[]
|type|STRING?
|array|BOOLEAN?
|sample|LIST? OF ANY?
|leftCount|INTEGER?
|rightCount|INTEGER?
|left|INTEGER?
|right|INTEGER?
|other|LIST? OF STRING?
Expand Down
Loading

0 comments on commit b058516

Please sign in to comment.