net.sf.saffron.oj.xlat
Class QueryInfo

java.lang.Object
  |
  +--net.sf.saffron.oj.xlat.QueryInfo

class QueryInfo
extends Object

A QueryInfo holds all the information about a QueryExpression while it is being translated into a collection of SaffronRels.

Those SaffronRels will all belong to the same VolcanoCluster, but VolcanoCluster is much simpler. Please put the stuff which is only needed at translation time into QueryInfo, and keep VolcanoCluster simple.


Nested Class Summary
(package private) static class QueryInfo.CorrelLookupResult
           
(package private) static class QueryInfo.LocalLookupResult
           
(package private) static class QueryInfo.LookupResult
           
 
Field Summary
(package private)  VolcanoCluster cluster
           
(package private)  Environment env
           
(package private)  OJQueryExpander expander
           
(package private)  ArrayList leaves
           
(package private)  QueryInfo parent
           
(package private)  JavaRexBuilder rexBuilder
           
private  SaffronRel root
           
 
Constructor Summary
(package private) QueryInfo(QueryInfo parent, Environment env, OJQueryExpander expander, Expression exp)
          Creates a QueryInfo
 
Method Summary
 RexNode convertExpToInternal(Expression exp)
          Translates an expression into one which references only internal variables.
 RexNode convertExpToInternal(Expression exp, SaffronRel[] inputs)
           
(package private)  SaffronRel convertFromExpToRel(Expression exp)
          Converts an expression into a relational expression.
 RexNode convertGroupExpToInternal(Expression exp, Expression[] groups, ArrayList aggInputList, Vector aggCallVector)
          Translates an aggregate expression into one which references only variables.
private static int convertJoinType(int saffronJoinType)
           
(package private)  SaffronRel convertQueryToRel(QueryExpression queryExp)
          Converts a QueryExpression into a SaffronRel.
(package private)  int countColumns(SaffronRel rel)
          Returns the number of columns in this input.
(package private) static VolcanoCluster createCluster(QueryInfo queryInfo, Environment env)
           
private  SaffronRel findLeaf(SaffronRel rel, int count, int[] seen, ArrayList path, int depth)
          Returns the countth leaf (SaffronRel which implements a from-list item) below this one.
private  ArrayList flatten(SaffronRel[] rels)
           
private  void flatten(SaffronRel[] rels, ArrayList list)
           
(package private)  SaffronRel getRoot()
           
(package private)  QueryInfo.LookupResult lookup(int offset, SaffronRel[] inputs, boolean isParent, String varName)
          Creates an expression with which to reference expression, whose offset in its from-list is offset.
(package private)  Expression removeSubqueries(Expression exp)
          Goes through an expression looking for sub-queries (in or exists).
(package private)  void setRoot(SaffronRel root)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

leaves

ArrayList leaves

env

Environment env

expander

OJQueryExpander expander

parent

QueryInfo parent

cluster

VolcanoCluster cluster

root

private SaffronRel root

rexBuilder

final JavaRexBuilder rexBuilder
Constructor Detail

QueryInfo

QueryInfo(QueryInfo parent,
          Environment env,
          OJQueryExpander expander,
          Expression exp)
Creates a QueryInfo

Parameters:
env - environment of the query that this expression was contained in - gives us access to the from list of that query
Method Detail

convertExpToInternal

public RexNode convertExpToInternal(Expression exp)
Translates an expression into one which references only internal variables. Clones the expression first.

Parameters:
exp - expression to translate
Returns:
converted expression

convertExpToInternal

public RexNode convertExpToInternal(Expression exp,
                                    SaffronRel[] inputs)

convertGroupExpToInternal

public RexNode convertGroupExpToInternal(Expression exp,
                                         Expression[] groups,
                                         ArrayList aggInputList,
                                         Vector aggCallVector)
Translates an aggregate expression into one which references only variables. Expressions inside aggregate functions are added to aggList, if they are not already present.

Parameters:
exp - expression to translate
groups - expressions from the group by clause
aggInputList - expressions inside aggregations; expressions are added to this list if an aggregate needs one and it is not present
aggCallVector - calls to aggregates; AggregateRel.Calls are added to this list if they are needed but are not present

createCluster

static VolcanoCluster createCluster(QueryInfo queryInfo,
                                    Environment env)

setRoot

void setRoot(SaffronRel root)

getRoot

SaffronRel getRoot()

convertFromExpToRel

SaffronRel convertFromExpToRel(Expression exp)
Converts an expression into a relational expression. For example, an array becomes an ExpressionReaderRel. Leaf nodes are registered in leaves.

Parameters:
exp - the expression to convert
Returns:
the equivalent relational expression

convertJoinType

private static int convertJoinType(int saffronJoinType)

convertQueryToRel

SaffronRel convertQueryToRel(QueryExpression queryExp)
Converts a QueryExpression into a SaffronRel. Capture occurs when a query is converted into relational expressions. The scalar expressions in the query reference (a) rows from their own query, (b) rows from an enclosing query, (c) variables from the enclosing environment. We have already dealt with (a), and we can leave environmental references (c) as they are. So, we deal with references to rows in this query now. References to queries inside or outside this query will happen in due course.


countColumns

int countColumns(SaffronRel rel)
Returns the number of columns in this input.


lookup

QueryInfo.LookupResult lookup(int offset,
                              SaffronRel[] inputs,
                              boolean isParent,
                              String varName)
Creates an expression with which to reference expression, whose offset in its from-list is offset.


removeSubqueries

Expression removeSubqueries(Expression exp)
Goes through an expression looking for sub-queries (in or exists). If it finds one, it joins the query to the from clause, replaces the condition, and returns true. Examples:

Parameters:
exp - Expression
Returns:
expression with subqueries removed

findLeaf

private SaffronRel findLeaf(SaffronRel rel,
                            int count,
                            int[] seen,
                            ArrayList path,
                            int depth)
Returns the countth leaf (SaffronRel which implements a from-list item) below this one.

Parameters:
rel - relation to start from
count - leaf number we want
seen - seen[0] contains the number of leaves we have seen so far
path - List containing the rel at each depth
depth - Current depth

flatten

private ArrayList flatten(SaffronRel[] rels)

flatten

private void flatten(SaffronRel[] rels,
                     ArrayList list)

SourceForge.net_Logo