On 6/19/13 9:47 AM, venu wrote:
Hi Rick,
I took 10.10 branch code and able to resolve all issues related with group
by.
I have some doubts could you please help me on these things.
1. I can see FromList and Groupbylist but can not find OrderByList node.
Hi Venu,
Using the following query...
select tablename from sys.systables where tablename is null order by
tablename
...I see the ORDER BY list in the output from both TreeWalker and
ASTParser. TreeWalker shows this it as a
org.apache.derby.impl.sql.compile.OrderByColumn node. ASTParser clearly
labels it as an orderByList. Can you be more specific about the problem
you are seeing with ORDER BY lists?
2. When I provide any function then the node tree will be like this.
Ex:
expression:
org.apache.derby.impl.sql.compile.JavaToSQLValueNode@6460029d
dataTypeServices: null
javaNode:
org.apache.derby.impl.sql.compile.StaticMethodCallNode@5b4bc4e6
javaClassName: null
methodName: TO_CHAR
methodParms[0] :
org.apache.derby.impl.sql.compile.SQLToJavaValueNode@4b6c06dd
value:
org.apache.derby.impl.sql.compile.ColumnReference@2136bdda
columnName: TIME
tableNumber: -1
columnNumber: 0
replacesAggregate: false
replacesWindowFunctionCall:
false
tableName: null
nestingLevel: -1
sourceLevel: -1
dataTypeServices: null
Here I want to get value node of SQLToJavaValueNode object. But, there is no
such method for getting sub node or value node SQLToJavaValueNode.
I'm afraid I don't understand what's missing. In the above summary, I
see a call to the function TO_CHAR, taking one argument, a column called
TIME, whose table is not resolved yet.
3. How can I get having clause from the select node.
When I run the following query...
select tablename, max( tableid ) from sys.systables group by tablename
having max( tableid ) is null
...I see the HAVING clause in the output of both TreeWalker and
ASTParser. For TreeWalker, it appears as an
org.apache.derby.impl.sql.compile.IsNullNode node. For ASTParser, it is
clearly labelled as a havingClause.
I'm beginning to sense that TreeWalker and ASTParser are very general
diagnostic tools which you may not be able to press into service to do
the sophisticated query analysis you need to perform. At this point, I
recommend that you study TreeWalker to see how to extract the AST from
the query. I'm afraid that you may need to walk the AST in your own code
in order to perform sophisticated analysis which is specific to your
application.
Of course, you can always write your own Visitor for this purpose. But
using a Visitor to analyze something like a HAVING clause is going to be
tricky. That is because the Visitor does not have enough context to know
when a ValueNode represents a HAVING clause. That knowledge is in the
SelectNode itself.
Hope this helps,
-Rick
Thanks,
Venu.
--
View this message in context:
http://apache-database.10148.n7.nabble.com/Using-ASTParser-and-TreeWalker-for-parsing-SQL-query-tp131219p131603.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.