use of apoc.result.RelationshipResult in project neo4j-apoc-procedures by neo4j-contrib.
the class SubgraphTest method testSubgraphAllShouldContainExpectedNodesAndRels.
@Test
public void testSubgraphAllShouldContainExpectedNodesAndRels() throws Throwable {
String controlQuery = "MATCH path = (:Person {name: 'Keanu Reeves'})-[*0..3]-(subgraphNode) " + "with collect(distinct subgraphNode) as subgraph " + "call apoc.algo.cover([node in subgraph | id(node)]) yield rel " + "return subgraph, collect(rel) as relationships";
final List<NodeResult> subgraph;
final List<RelationshipResult> relationships;
try (Transaction tx = db.beginTx()) {
Result result = db.execute(controlQuery);
Map<String, Object> row = result.next();
subgraph = (List<NodeResult>) row.get("subgraph");
relationships = (List<RelationshipResult>) row.get("relationships");
}
String query = "MATCH (k:Person {name: 'Keanu Reeves'}) " + "CALL apoc.path.subgraphAll(k,{maxLevel:3}) yield nodes, relationships " + "return nodes as subgraphNodes, relationships as subgraphRelationships";
TestUtil.testCall(db, query, (row) -> {
List<NodeResult> subgraphNodes = (List<NodeResult>) row.get("subgraphNodes");
List<RelationshipResult> subgraphRelationships = (List<RelationshipResult>) row.get("subgraphRelationships");
assertEquals(subgraph.size(), subgraphNodes.size());
assertTrue(subgraph.containsAll(subgraphNodes));
assertEquals(relationships.size(), subgraphRelationships.size());
assertTrue(relationships.containsAll(subgraphRelationships));
});
}
use of apoc.result.RelationshipResult in project neo4j-apoc-procedures by neo4j-contrib.
the class GraphRefactoring method mergeRelationships.
/**
* Merges the relationships onto the first relationship and delete them.
* All relationships must have the same starting node and ending node.
*/
@Procedure(mode = Mode.WRITE)
@Description("apoc.refactor.mergeRelationships([rel1,rel2]) merge relationships onto first in list")
public Stream<RelationshipResult> mergeRelationships(@Name("rels") List<Relationship> relationships, @Name(value = "config", defaultValue = "") Map<String, Object> config) {
if (relationships == null || relationships.isEmpty())
return Stream.empty();
RefactorConfig conf = new RefactorConfig(config);
Iterator<Relationship> it = relationships.iterator();
Relationship first = it.next();
while (it.hasNext()) {
Relationship other = it.next();
if (first.getStartNode().equals(other.getStartNode()) && first.getEndNode().equals(other.getEndNode()))
mergeRels(other, first, true, conf);
else
throw new RuntimeException("All Relationships must have the same start and end nodes.");
}
return Stream.of(new RelationshipResult(first));
}
Aggregations