VarDependencies { public AvailableVariables getReachableVars(ClauseId clauseId) { return this.reachableVariables.get(clauseId); } VarDependencies(final Statement statement); List<Var> getUsedVars(ClauseId clauseId); Set<Var> getAllVariables(); List<Var> getUsedAndIndirectUsedVars(ClauseId clauseId); AvailableVariables getReachableVars(ClauseId clauseId); List<Relationship> getRelationships(ClauseId clauseId); List<Expr> getReturnExprs();  }
@Test public void testReachableVariablesMatchMatchWithMatchReturn() { String cypher = "" + "MATCH (a)--(b)\n" + "MATCH (b)\n" + "WITH (a)\n" + "MATCH (b)\n" + "RETURN a.firstName"; Statement st = PassAvailables.parseCypher(cypher); SingleQuery sq = (SingleQuery) st.query.part; VarDependencies dependencies = new VarDependencies(st); Iterator<Clause> iter = sq.clauses.iterator(); AvailableVariables match0 = dependencies.getReachableVars(this.genClauseForASTNode(this.getPatternPart(iter.next()).next())); AvailableVariables match1 = dependencies.getReachableVars(this.genClauseForASTNode(this.getPatternPart(iter.next()).next())); AvailableVariables with2 = dependencies.getReachableVars(this.genClauseForASTNode(iter.next())); AvailableVariables match3 = dependencies.getReachableVars(this.genClauseForASTNode(this.getPatternPart(iter.next()).next())); AvailableVariables ret = dependencies.getReachableVars(this.genClauseForASTNode(iter.next())); Assert.assertTrue(match0.isEmpty()); Assert.assertTrue(match1.get("a").isPresent()); Assert.assertTrue(match1.get("b").isPresent()); Assert.assertTrue(with2.get("a").isPresent()); Assert.assertTrue(with2.get("b").isPresent()); Assert.assertTrue(match3.get("a").isPresent()); Assert.assertFalse(match3.get("b").isPresent()); Assert.assertTrue(ret.get("a").isPresent()); Assert.assertTrue(ret.get("b").isPresent()); }
@Test public void testReachableVarsInOrderBy() { String cypher = "" + "MATCH (a)\n" + "WITH a.firstName AS foo ORDER BY foo\n" + "RETURN foo"; Statement st = PassAvailables.parseCypher(cypher); SingleQuery sq = (SingleQuery) st.query.part; VarDependencies deps = new VarDependencies(st); With with = (With) sq.clauses.get(1); AvailableVariables orderBy = deps.getReachableVars(new ClauseId(with.orderBy.get())); Assert.assertTrue(orderBy.get("foo").isPresent()); }