Search in sources :

Example 1 with WinAggResultContextImpl

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;
}
Also used : BinaryExpression(org.apache.calcite.linq4j.tree.BinaryExpression) Expression(org.apache.calcite.linq4j.tree.Expression) ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) WinAggResultContextImpl(org.apache.calcite.adapter.enumerable.impl.WinAggResultContextImpl)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 WinAggResultContextImpl (org.apache.calcite.adapter.enumerable.impl.WinAggResultContextImpl)1 BinaryExpression (org.apache.calcite.linq4j.tree.BinaryExpression)1 Expression (org.apache.calcite.linq4j.tree.Expression)1 ParameterExpression (org.apache.calcite.linq4j.tree.ParameterExpression)1