|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--net.sf.saffron.oj.xlat.ExtenderAggregation
ExtenderAggregation is an aggregation which works by
instantiating a user-defined aggregation (AggregationExtender), as opposed to generating custom
code.
Two bugs with the current implementation of implementStart(net.sf.saffron.opt.RelImplementor, net.sf.saffron.rel.SaffronRel, int[]) etc.
First, the aggregation expression should be evaluated only once -- when
the query starts -- and stored in a variable. I guess it should be added
to the environment holding the query.
Second, we pass real expressions as the values of the dummy arguments to
implementStart(net.sf.saffron.opt.RelImplementor, net.sf.saffron.rel.SaffronRel, int[]) and implementResult(openjava.ptree.Expression). This is inefficient,
but moreover, it is conceivable that the expressions will not be valid in
the scope where start and result are executed.
| Field Summary | |
(package private) OJClass |
aggClazz
|
(package private) Expression |
aggExp
|
(package private) OJMethod |
aggregateMethod
|
(package private) OJClass[] |
argTypes
|
(package private) OJMethod |
mergeMethod
|
(package private) OJMethod |
nextMethod
|
(package private) OJMethod |
resultMethod
|
(package private) OJMethod |
startMethod
|
| Constructor Summary | |
(package private) |
ExtenderAggregation(Expression aggExp,
Environment env,
OJClass[] argTypes)
|
| Method Summary | |
boolean |
canMerge()
Whether this aggregation can merge together two accumulators. |
private static OJMethod |
findMethod(OJClass aggClazz,
String name,
OJClass[] argTypes,
int extra,
OJClass desiredType,
boolean fail)
|
SaffronType[] |
getParameterTypes(SaffronTypeFactory typeFactory)
|
SaffronType |
getReturnType(SaffronTypeFactory typeFactory)
|
void |
implementMerge(RelImplementor implementor,
SaffronRel rel,
Expression accumulator,
Expression otherAccumulator)
Generates (into the current statement list, gleaned by calling implementor's RelImplementor.getStatementList() method) code to
merge two accumulators. |
void |
implementNext(RelImplementor implementor,
SaffronRel rel,
Expression accumulator,
int[] args)
Generates (into the current statement list, gleaned by calling implementor's RelImplementor.getStatementList() method) the piece of code
which gets called each time an extra row is seen. |
Expression |
implementResult(Expression accumulator)
Generates the expression which gets called when a total is complete. |
Expression |
implementStart(RelImplementor implementor,
SaffronRel rel,
int[] args)
Generates the expression which gets called when a new total is created. |
Expression |
implementStartAndNext(RelImplementor implementor,
SaffronRel rel,
int[] args)
Generates code to create a new total and to add the first value. |
static boolean |
matches(OJClass aggClazz,
OJClass[] argTypes)
Returns whether this aggregation has an overloading which matches the given name and argument types. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
Expression aggExp
OJClass aggClazz
OJMethod aggregateMethod
OJMethod mergeMethod
OJMethod nextMethod
OJMethod resultMethod
OJMethod startMethod
OJClass[] argTypes
| Constructor Detail |
ExtenderAggregation(Expression aggExp,
Environment env,
OJClass[] argTypes)
| Method Detail |
public SaffronType[] getParameterTypes(SaffronTypeFactory typeFactory)
getParameterTypes in interface Aggregationpublic SaffronType getReturnType(SaffronTypeFactory typeFactory)
getReturnType in interface Aggregation
public static boolean matches(OJClass aggClazz,
OJClass[] argTypes)
public boolean canMerge()
Aggregationcount can (you just add the accumulators);
avg and Nth cannot.
canMerge in interface Aggregation
public void implementMerge(RelImplementor implementor,
SaffronRel rel,
Expression accumulator,
Expression otherAccumulator)
Aggregationimplementor's RelImplementor.getStatementList() method) code to
merge two accumulators. For sum(x), this looks like
((saffron.runtime.Holder.int_Holder) accumulator).value +=
((saffron.runtime.Holder.int_Holder) other).value.
The method is only called if Aggregation.canMerge() returns
true.
implementMerge in interface Aggregationimplementor - a callback object which knows how to generate thingsrel - the relational expression which is generating this codeaccumulator - the expression which holds the totalotherAccumulator - accumulator to merge in
public void implementNext(RelImplementor implementor,
SaffronRel rel,
Expression accumulator,
int[] args)
Aggregationimplementor's RelImplementor.getStatementList() method) the piece of code
which gets called each time an extra row is seen. For
sum(x), this looks like
((net.sf.saffron.runtime.Holder.int_Holder) accumulator).value +=
x.
implementNext in interface Aggregationimplementor - a callback object which knows how to generate thingsrel - the relational expression which is generating this codeaccumulator - the expression which holds the totalargs - the ordinals of the fields of the child row which are
arguments to this aggregationpublic Expression implementResult(Expression accumulator)
Aggregationsum(x), this looks like
((saffron.runtime.Holder.int_Holder) accumulator).value.
implementResult in interface Aggregation
public Expression implementStart(RelImplementor implementor,
SaffronRel rel,
int[] args)
Aggregationsum(x), this looks like new
saffron.runtime.Holder.int_Holder(0).
implementStart in interface Aggregation
public Expression implementStartAndNext(RelImplementor implementor,
SaffronRel rel,
int[] args)
Aggregationsum(x), this looks like new
saffron.runtime.Holder.int_Holder(x).
implementStartAndNext in interface Aggregation
private static OJMethod findMethod(OJClass aggClazz,
String name,
OJClass[] argTypes,
int extra,
OJClass desiredType,
boolean fail)
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||