use of org.apache.calcite.adapter.enumerable.impl.WinAggResultContextImpl in project calcite by apache.
the class EnumerableWindow method implementResult.
private boolean implementResult(List<AggImpState> aggs, final BlockBuilder builder, final Function<BlockBuilder, WinAggFrameResultContext> frame, final Function<AggImpState, List<RexNode>> rexArguments, boolean cachedBlock) {
boolean nonEmpty = false;
for (final AggImpState agg : aggs) {
boolean needCache = true;
if (agg.implementor instanceof WinAggImplementor) {
WinAggImplementor imp = (WinAggImplementor) agg.implementor;
needCache = imp.needCacheWhenFrameIntact();
}
if (needCache ^ cachedBlock) {
// the same. Ths
continue;
}
nonEmpty = true;
Expression res = agg.implementor.implementResult(agg.context, new WinAggResultContextImpl(builder, agg.state, frame) {
public List<RexNode> rexArguments() {
return rexArguments.apply(agg);
}
});
// Several count(a) and count(b) might share the result
Expression aggRes = builder.append("a" + agg.aggIdx + "res", RexToLixTranslator.convert(res, agg.result.getType()));
builder.add(Expressions.statement(Expressions.assign(agg.result, aggRes)));
}
return nonEmpty;
}
Aggregations