-
Hi there. A simple test is to parse the two queries and see the difference in the data structures. I am dumping out ID + value if present as follows void MyDump(SimpleNode n, int level) { for ( int i = 0; i < level; ++i) System.out.print(' '); if (n.jjtGetValue() != null) System.out.println(n.getId() + n.jjtGetValue().toString()); else System.out.println(); for (int i = 0; i < n.jjtGetNumChildren(); ++i) { MyDump((SimpleNode)n.jjtGetChild(i), level + 1); } } My problem: 6 SELECT director FROM movie WHERE YEAR = 1999 OR YEAR = 2000 9 director 19 4 director 5 movie 13 14 YEAR = 1999 19 4 YEAR 19 14 YEAR = 2000 19 4 YEAR 19 (Side question: Are these IDs defined in CCJQLParserConstants?) From the tree alone it is not possible to distinguish what kind of expression is performed. Is it possible that this type of information is in the actual instances uses to construct the expression Ideally the data that one can traverse in the AST tree would differentiate between both cases. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Greetings.
Statement statement = CCJSqlParserUtil.parse(sql);
if (statement instanceof Select) {
Select stmt = (Select) statement;
if (stmt.getSelectBody() instanceof PlainSelect) {
PlainSelect ps = (PlainSelect) stmt.getSelectBody();
OracleHint hint = ps.getOracleHint();
assertNotNull(hint);
assertEquals(hints[0], hint.getValue());
} else
if (stmt.getSelectBody() instanceof SetOperationList) {
SetOperationList setop = (SetOperationList) stmt.getSelectBody();
for (int i = 0; i < setop.getSelects().size(); i++) {
PlainSelect pselect = (PlainSelect) setop.getSelects().get(i);
OracleHint hint = pselect.getOracleHint();
if (hints[i] == null) {
Assert.assertNull(hint);
} else {
assertNotNull(hint);
assertEquals(hints[i], hint.getValue());
}
}
}
}
|
Beta Was this translation helpful? Give feedback.
-
As @manticore-projects mentioned, the access to the parse tree is done using the visitor pattern. @ghbakir Your test uses the more basic AST tree of the parser. Maybe there is a bit of a confusion (https://stackoverflow.com/questions/5026517/whats-the-difference-between-parse-trees-and-abstract-syntax-trees-asts). However, since the nodes returned for this AST are not complete due to performance issues you see no difference in your output. For instance, the AndExpression has no representing node in the returned AST tree, while it has a representation in the parse tree as an AndExpression object. |
Beta Was this translation helpful? Give feedback.
As @manticore-projects mentioned, the access to the parse tree is done using the visitor pattern. @ghbakir Your test uses the more basic AST tree of the parser. Maybe there is a bit of a confusion (https://stackoverflow.com/questions/5026517/whats-the-difference-between-parse-trees-and-abstract-syntax-trees-asts).
However, since the nodes returned for this AST are not complete due to performance issues you see no difference in your output. For instance, the AndExpression has no representing node in the returned AST tree, while it has a representation in the parse tree as an AndExpression object.