@Test public void testParamFinder() throws SqlParseException { SqlParser sqlParser1 = SqlParser.create("POWER($0, $1) + AVG(LN($3)) + EXP($5)"); SqlNode sqlPattern = sqlParser1.parseExpression(); SqlParser sqlParser2 = SqlParser.create("POWER(3, POWER(2, POWER(2, 3))) + AVG(LN(EXP(4))) + EXP(CAST('2018-03-22' AS DATE))"); SqlNode sqlCall = sqlParser2.parseExpression(); SqlParamsFinder sqlParamsFinder = new SqlParamsFinder((SqlCall)sqlPattern, (SqlCall)sqlCall); Map<Integer, SqlNode> paramNodes = sqlParamsFinder.getParamNodes(); Assert.assertEquals("3", paramNodes.get(0).toString()); Assert.assertEquals("POWER(2, POWER(2, 3))", paramNodes.get(1).toString()); Assert.assertEquals("EXP(4)", paramNodes.get(3).toString()); Assert.assertEquals("CAST('2018-03-22' AS DATE)", paramNodes.get(5).toString()); }
public Map<Integer, SqlNode> getParamNodes() { paramPath = SqlParamsFinder.PATH_CACHE.getIfPresent(this.sourceTmpl); if (paramPath == null) { this.paramPath = new TreeMap<>(); genParamPath(this.sourceTmpl, new ArrayList<Integer>()); SqlParamsFinder.PATH_CACHE.put(this.sourceTmpl, this.paramPath); } Map<Integer, SqlNode> sqlNodes = new HashMap<>(); for (Map.Entry<Integer, List<Integer>> entry : paramPath.entrySet()) { List<Integer> path = entry.getValue(); sqlNodes.put(entry.getKey(), getParamNode(path, sqlCall, 0)); } return sqlNodes; }
SqlParamsFinder { public Map<Integer, SqlNode> getParamNodes() { paramPath = SqlParamsFinder.PATH_CACHE.getIfPresent(this.sourceTmpl); if (paramPath == null) { this.paramPath = new TreeMap<>(); genParamPath(this.sourceTmpl, new ArrayList<Integer>()); SqlParamsFinder.PATH_CACHE.put(this.sourceTmpl, this.paramPath); } Map<Integer, SqlNode> sqlNodes = new HashMap<>(); for (Map.Entry<Integer, List<Integer>> entry : paramPath.entrySet()) { List<Integer> path = entry.getValue(); sqlNodes.put(entry.getKey(), getParamNode(path, sqlCall, 0)); } return sqlNodes; } }
SqlParamsFinder { public Map<Integer, SqlNode> getParamNodes() { paramPath = SqlParamsFinder.PATH_CACHE.getIfPresent(this.sourceTmpl); if (paramPath == null) { this.paramPath = new TreeMap<>(); genParamPath(this.sourceTmpl, new ArrayList<Integer>()); SqlParamsFinder.PATH_CACHE.put(this.sourceTmpl, this.paramPath); } Map<Integer, SqlNode> sqlNodes = new HashMap<>(); for (Map.Entry<Integer, List<Integer>> entry : paramPath.entrySet()) { List<Integer> path = entry.getValue(); sqlNodes.put(entry.getKey(), getParamNode(path, sqlCall, 0)); } return sqlNodes; } SqlParamsFinder(SqlCall sourceTmpl, SqlCall sqlCall); }
SqlParamsFinder { public Map<Integer, SqlNode> getParamNodes() { paramPath = SqlParamsFinder.PATH_CACHE.getIfPresent(this.sourceTmpl); if (paramPath == null) { this.paramPath = new TreeMap<>(); genParamPath(this.sourceTmpl, new ArrayList<Integer>()); SqlParamsFinder.PATH_CACHE.put(this.sourceTmpl, this.paramPath); } Map<Integer, SqlNode> sqlNodes = new HashMap<>(); for (Map.Entry<Integer, List<Integer>> entry : paramPath.entrySet()) { List<Integer> path = entry.getValue(); sqlNodes.put(entry.getKey(), getParamNode(path, sqlCall, 0)); } return sqlNodes; } SqlParamsFinder(SqlCall sourceTmpl, SqlCall sqlCall); Map<Integer, SqlNode> getParamNodes(); static SqlParamsFinder newInstance(SqlCall sourceTmpl, final SqlCall sqlCall, boolean isWindowCall); }
SqlParamsFinder { public Map<Integer, SqlNode> getParamNodes() { paramPath = SqlParamsFinder.PATH_CACHE.getIfPresent(this.sourceTmpl); if (paramPath == null) { this.paramPath = new TreeMap<>(); genParamPath(this.sourceTmpl, new ArrayList<Integer>()); SqlParamsFinder.PATH_CACHE.put(this.sourceTmpl, this.paramPath); } Map<Integer, SqlNode> sqlNodes = new HashMap<>(); for (Map.Entry<Integer, List<Integer>> entry : paramPath.entrySet()) { List<Integer> path = entry.getValue(); sqlNodes.put(entry.getKey(), getParamNode(path, sqlCall, 0)); } return sqlNodes; } SqlParamsFinder(SqlCall sourceTmpl, SqlCall sqlCall); Map<Integer, SqlNode> getParamNodes(); static SqlParamsFinder newInstance(SqlCall sourceTmpl, final SqlCall sqlCall, boolean isWindowCall);  }