saffron.rel.java
Class JavaAggregate
java.lang.Object
|
+--saffron.rel.Rel
|
+--saffron.rel.SingleRel
|
+--saffron.rel.Aggregate
|
+--saffron.rel.java.JavaAggregate
- public class JavaAggregate
- extends Aggregate
JavaAggregate
implements the Aggregate
relational operator by generating code. The code looks like
this:
HashMap h = new HashMap();
for each child
HashableArray groups = new HashableArray(
new Object[] {
child.field4,
child.field2});
Object[] aggs = h.get(groups);
if (aggs == null) {
aggs = new Object[<>];
aggs[0] = agg start code;
aggs[1] = agg start code;
h.put(groups, aggs);
}
agg inc code {aggs[0], childRow}
agg inc code {aggs[1], childRow}
end for
Iterator keys = h.keys();
while (keys.hasNext()) {
T row = new T();
HashableArray groups = (HashableArray) keys.next();
row.c0 = groups[0];
row.c1 = groups[1];
Object[] aggs = h.get(groups);
row.c2 = agg result code {aggs[0]}
row.c3 = agg result code {aggs[1]}
emit row to parent
}
Simplifications:
- If there is onle one group column, the
HashableArray
is
simplified to Object
.
- If there is only one aggregate, the
Object[]
are
simplified to Object
.
- todo: Write an efficient implementation if there are no group
columns.
- If there are no aggregations,
JavaDistinct
is
more efficient.
Nested classes inherited from class saffron.rel.Rel |
|
Methods inherited from class saffron.rel.Rel |
computeDigest, getChildExps, getCluster, getCorelVariable, getEnvironment, getId, getInput, getOrCreateCorelVariable, getParentEnv, getQualifier, getQuery, getRelTypeName, getRows, getRowType, getTable, getType, getVariablesStopped, implementExp, implementExps, implementFieldAccess, implementSelf, isAccessTo, isDistinct, onRegister, recomputeDigest, registerCorelVariable, setCorelVariable, toString |
var_h
Variable var_h
JavaAggregate
public JavaAggregate(Cluster cluster,
Rel child,
int groupCount,
Aggregate.Call[] aggCalls)
clone
public Object clone()
- Overrides:
clone
in class Aggregate
getConvention
public CallingConvention getConvention()
- Description copied from class:
Rel
- Returns a value from
CallingConvention
.
- Overrides:
getConvention
in class Rel
computeSelfCost
public Cost computeSelfCost(Planner planner)
- Description copied from class:
Rel
- Returns the cost of this plan (not including children). The base
implementation throws an error; derived classes should override.
- Overrides:
computeSelfCost
in class Aggregate
implement
public Object implement(Implementor implementor,
int ordinal)
- Description copied from class:
Rel
- Create a plan for this expression according to a calling convention.
- Overrides:
implement
in class Rel
- Parameters:
implementor
- implementorordinal
- indicates our position in the pre-, in- and postfix walk
over the tree; ordinal
is -1 when called from the
parent, and i
when called from the
i
th child.