Paths { @UserFunction @Description("apoc.path.combine(path1, path2) - combines the paths into one if the connecting node matches") public Path combine(@Name("first") Path first, @Name("second") Path second) { if (first == null) return second; if (second == null) return first; if (!first.endNode().equals(second.startNode())) throw new IllegalArgumentException("Paths don't connect on their end and start-nodes "+first+ " with "+second); PathImpl.Builder builder = new PathImpl.Builder(first.startNode()); for (Relationship rel : first.relationships()) builder = builder.push(rel); for (Relationship rel : second.relationships()) builder = builder.push(rel); return builder.build(); }  @UserFunction @Description("apoc.path.create(startNode,[rels]) - creates a path instance of the given elements") Path create(@Name("startNode") Node startNode, @Name(value = "rels", defaultValue = "[]") List<Relationship> rels); @UserFunction @Description("apoc.path.slice(path, [offset], [length]) - creates a sub-path with the given offset and length") Path slice(@Name("path") Path path, @Name(value = "offset", defaultValue = "0") long offset,@Name(value = "length", defaultValue = "-1") long length); @UserFunction @Description("apoc.path.combine(path1, path2) - combines the paths into one if the connecting node matches") Path combine(@Name("first") Path first, @Name("second") Path second); @UserFunction @Description("apoc.path.elements(path) - returns a list of node-relationship-node-...") List<Object> elements(@Name("path") Path path);  }
@Test public void combine() throws Exception { TestUtil.testCall(db, "MATCH p1 = (a:A)-[:NEXT]->(b:B), p2 = (b)-[:NEXT]->() RETURN apoc.path.combine(p1,p2) as p",(row) -> assertPath(row, 2, "A", "C")); TestUtil.testCall(db, "MATCH p1 = (a:A)-[:NEXT]->(b:B) RETURN apoc.path.combine(p1,null) as p",(row) -> assertPath(row, 1, "A", "B")); TestUtil.testCall(db, "MATCH p1 = (a:A)-[:NEXT]->(b:B) RETURN apoc.path.combine(null,p1) as p",(row) -> assertPath(row, 1, "A", "B")); }