db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rick Hillegas (JIRA)" <j...@apache.org>
Subject [jira] Updated: (DERBY-3946) Provide support for using the Derby parser to generate Abstract Syntax Trees
Date Fri, 14 Nov 2008 15:24:46 GMT

     [ https://issues.apache.org/jira/browse/DERBY-3946?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Rick Hillegas updated DERBY-3946:
---------------------------------

    Attachment: TreeWalker.java

Hi Christian,

I have posted a reply to a similar question on your original email thread. Hopefully you will
be able to see that soon.

1) It's useful to build the engine javadoc (ant -quiet javadoc) and browse the javadoc for
the package org.apache.derby.impl.sql.compile. In particular, you will see that the AST nodes
are the classes indented under QueryTreeNode in the tree view.

2) The nodes themselves implement Visitable so you can write you own Visitor to explore the
AST graph. Visitable has one method, accept(), and by looking at the implementations of that
method, you will understand how the nodes snap together into a graph.

I've attached a simple Visitor (TreeWalker), which shows you some classes in the graph. That
may help explain the AST a bit more. When I run

  java TreeWalker "select a from t, s where t.a = s.a"

I get the following graph:

    org.apache.derby.impl.sql.compile.CursorNode
        org.apache.derby.impl.sql.compile.SelectNode
            org.apache.derby.impl.sql.compile.ResultColumnList
                org.apache.derby.impl.sql.compile.ResultColumn
                    org.apache.derby.impl.sql.compile.ColumnReference
            org.apache.derby.impl.sql.compile.FromBaseTable
            org.apache.derby.impl.sql.compile.FromBaseTable
            org.apache.derby.impl.sql.compile.BinaryRelationalOperatorNode
                org.apache.derby.impl.sql.compile.ColumnReference
                org.apache.derby.impl.sql.compile.ColumnReference

Let me try to explain this tree a bit:

The SelectNode has the following children:

i) The columns in the SELECT list. The whole SELECT list is represented by a ResultColumnList
and there is only one ResultColumn (representing "a") in that list.

ii) The tables in the FROM list. There are two of these, each represented by its own FromBaseTable.

iii) The WHERE clause. This is a BinaryRelationalOperatorNode (representing the "=" operator).
This operator node has a left child and a right child, "t.a" and "s.a" respectively.

So to answer your specific questions:

Q) What tables are in the query? 
A) Look for FromBaseTables in the graph.

Q) Which fields in the tables are accessed?
A) The column references can appear in the SELECT list (the ResultColumnList) or in the WHERE
clause (under the BinaryRelationalOperatorNode). Note, however, that the columns are not matched
up to tables yet. This isn't done by the parser. That kind of name resolution happens during
Derby's bind() phase and it requires metadata so that Derby knows the structure of the tables.
Unless you create the tables in Derby, there will be no way to move forward to the bind()
phase. If you don't provide this information to Derby, then you will have to write your own
name-resolution phase.

Q) What are the table aliases, if any?
A) FromBaseTable.getExposedName() will give you the name of the table (or the alias name if
you specified an alias)

Hope this helps,
-Rick


> Provide support for using the Derby parser to generate Abstract Syntax Trees
> ----------------------------------------------------------------------------
>
>                 Key: DERBY-3946
>                 URL: https://issues.apache.org/jira/browse/DERBY-3946
>             Project: Derby
>          Issue Type: New Feature
>          Components: SQL
>    Affects Versions: 10.5.0.0
>            Reporter: Rick Hillegas
>             Fix For: 10.5.0.0
>
>         Attachments: ASTParser.java, derby-3946-01-aa-standaloneParser.diff, TreeWalker.java
>
>
> Users would like to be able to use the Derby parser to produce query trees without actually
running the queries on Derby.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message