|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.sf.saffron.oj.xlat.QueryInfo
A QueryInfo
holds all the information about a QueryExpression
while it is being translated into a collection of SaffronRel
s.
Those SaffronRel
s 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 count th 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 |
ArrayList leaves
Environment env
OJQueryExpander expander
QueryInfo parent
VolcanoCluster cluster
private SaffronRel root
final JavaRexBuilder rexBuilder
Constructor Detail |
QueryInfo(QueryInfo parent, Environment env, OJQueryExpander expander, Expression exp)
QueryInfo
env
- environment of the query that this expression was contained
in - gives us access to the from list of that queryMethod Detail |
public RexNode convertExpToInternal(Expression exp)
exp
- expression to translate
public RexNode convertExpToInternal(Expression exp, SaffronRel[] inputs)
public RexNode convertGroupExpToInternal(Expression exp, Expression[] groups, ArrayList aggInputList, Vector aggCallVector)
aggList
, if they are not already present.
exp
- expression to translategroups
- expressions from the group by
clauseaggInputList
- expressions inside aggregations; expressions are
added to this list if an aggregate needs one and it is not
presentaggCallVector
- calls to aggregates; AggregateRel.Call
s are added to this list if they
are needed but are not presentstatic VolcanoCluster createCluster(QueryInfo queryInfo, Environment env)
void setRoot(SaffronRel root)
SaffronRel getRoot()
SaffronRel convertFromExpToRel(Expression exp)
ExpressionReaderRel
. Leaf nodes are
registered in leaves
.
exp
- the expression to convert
private static int convertJoinType(int saffronJoinType)
SaffronRel convertQueryToRel(QueryExpression queryExp)
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.
int countColumns(SaffronRel rel)
QueryInfo.LookupResult lookup(int offset, SaffronRel[] inputs, boolean isParent, String varName)
expression
,
whose offset in its from-list is offset
.
Expression removeSubqueries(Expression exp)
in
or
exists
). If it finds one, it joins the query to the from
clause, replaces the condition, and returns true. Examples:
exists
becomes a reference to a indicator query:
becomesselect from dept where dept.location.equals("SF") && exists ( select from emp where emp.deptno == dept.deptno && emp.gender.equals("F"))
select from dept cross join ( select distinct from emp where emp.deptno == dept.deptno && emp.gender.equals("F")) where dept.location.equals("SF") && indicator != null
The reference to 'dept' from within a join query is illegal -- but we haven't de-correlated yet.
in
becomes a test to see whether an outer-joined query met
the join condition:
becomesselect from emp where emp.deptno in ( select dept.deptno from dept where dept.location.equals("SF")) && emp.gender.equals("F")
Optimization #1: If theselect from emp left join ( select dept.deptno from dept where dept.location.equals("SF")) q1 on emp.deptno == q1.deptno where q1 is not null && emp.gender.equals("F")
in
condition is
&&
ed into the where clause, then make the join
into a full join, and omit the condition. Hence,
select from emp join ( select dept.deptno from dept where dept.location.equals("SF")) q1 on emp.deptno == q1.deptno where emp.gender.equals("F")
exp
- Expression
private SaffronRel findLeaf(SaffronRel rel, int count, int[] seen, ArrayList path, int depth)
count
th leaf (SaffronRel
which
implements a from-list item) below this one.
rel
- relation to start fromcount
- leaf number we wantseen
- seen[0]
contains the number of leaves we have
seen so farpath
- List containing the rel at each depthdepth
- Current depthprivate ArrayList flatten(SaffronRel[] rels)
private void flatten(SaffronRel[] rels, ArrayList list)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |