Search in sources :

Example 6 with TupleIterable

use of mondrian.calc.TupleIterable in project mondrian by pentaho.

the class ExistingFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final IterCalc setArg = compiler.compileIter(call.getArg(0));
    final Type myType = call.getArg(0).getType();
    return new AbstractListCalc(call, new Calc[] { setArg }) {

        public boolean dependsOn(Hierarchy hierarchy) {
            return myType.usesHierarchy(hierarchy, false);
        }

        public TupleList evaluateList(Evaluator evaluator) {
            TupleIterable setTuples = setArg.evaluateIterable(evaluator);
            TupleList result = TupleCollections.createList(setTuples.getArity());
            List<Member> contextMembers = Arrays.asList(evaluator.getMembers());
            List<Hierarchy> argDims = null;
            List<Hierarchy> contextDims = getHierarchies(contextMembers);
            for (List<Member> tuple : setTuples) {
                if (argDims == null) {
                    argDims = getHierarchies(tuple);
                }
                if (existsInTuple(tuple, contextMembers, argDims, contextDims, evaluator)) {
                    result.add(tuple);
                }
            }
            return result;
        }
    };
}
Also used : TupleList(mondrian.calc.TupleList) Hierarchy(mondrian.olap.Hierarchy) Type(mondrian.olap.type.Type) TupleIterable(mondrian.calc.TupleIterable) IterCalc(mondrian.calc.IterCalc) AbstractListCalc(mondrian.calc.impl.AbstractListCalc) Evaluator(mondrian.olap.Evaluator) Member(mondrian.olap.Member)

Example 7 with TupleIterable

use of mondrian.calc.TupleIterable in project mondrian by pentaho.

the class RolapResult method evaluateExp.

/**
 * Evaluates an expression. Intended for evaluating named sets.
 *
 * <p>
 * Does not modify the contents of the evaluator.
 *
 * @param calc
 *          Compiled expression
 * @param slicerEvaluator
 *          Evaluation context for slicers
 * @param contextEvaluator
 *          Evaluation context (optional)
 * @return Result
 */
Object evaluateExp(Calc calc, RolapEvaluator slicerEvaluator, Evaluator contextEvaluator) {
    int attempt = 0;
    RolapEvaluator evaluator = slicerEvaluator.push();
    if (contextEvaluator != null && contextEvaluator.isEvalAxes()) {
        evaluator.setEvalAxes(true);
    }
    final int savepoint = evaluator.savepoint();
    boolean dirty = batchingReader.isDirty();
    try {
        while (true) {
            evaluator.restore(savepoint);
            evaluator.setCellReader(batchingReader);
            Object preliminaryValue = calc.evaluate(evaluator);
            if (preliminaryValue instanceof TupleIterable) {
                // During the preliminary phase, we have to materialize the
                // tuple lists or the evaluation lower down won't take into
                // account all the tuples.
                TupleIterable iterable = (TupleIterable) preliminaryValue;
                final TupleCursor cursor = iterable.tupleCursor();
                while (cursor.forward()) {
                // ignore
                }
            }
            if (!phase()) {
                break;
            } else {
                // Clear invalid expression result so that the next
                // evaluation will pick up the newly loaded aggregates.
                evaluator.clearExpResultCache(false);
            }
            if (attempt++ > maxEvalDepth) {
                throw Util.newInternal("Failed to load all aggregations after " + maxEvalDepth + "passes; there's probably a cycle");
            }
        }
        // re-evaluate them.
        if (dirty) {
            batchingReader.setDirty(true);
        }
        evaluator.restore(savepoint);
        evaluator.setCellReader(aggregatingReader);
        final Object o = calc.evaluate(evaluator);
        return o;
    } finally {
        evaluator.restore(savepoint);
    }
}
Also used : TupleIterable(mondrian.calc.TupleIterable) TupleCursor(mondrian.calc.TupleCursor)

Example 8 with TupleIterable

use of mondrian.calc.TupleIterable in project mondrian by pentaho.

the class RolapResult method evalExecute.

TupleIterable evalExecute(List<List<Member>> nonAllMembers, int cnt, RolapEvaluator evaluator, QueryAxis queryAxis, Calc calc) {
    final int savepoint = evaluator.savepoint();
    final int arity = calc == null ? 0 : calc.getType().getArity();
    if (cnt < 0) {
        try {
            final TupleIterable axis = executeAxis(evaluator, queryAxis, calc, true, null);
            return axis;
        } finally {
            evaluator.restore(savepoint);
        }
    // No need to clear expression cache here as no new aggregates are
    // loaded(aggregatingReader reads from cache).
    } else {
        try {
            TupleList axisResult = TupleCollections.emptyList(arity);
            for (Member m : nonAllMembers.get(cnt)) {
                evaluator.setContext(m);
                TupleIterable axis = evalExecute(nonAllMembers, cnt - 1, evaluator, queryAxis, calc);
                boolean ordered = false;
                if (queryAxis != null) {
                    ordered = queryAxis.isOrdered();
                }
                axisResult = mergeAxes(axisResult, axis, ordered);
            }
            return axisResult;
        } finally {
            evaluator.restore(savepoint);
        }
    }
}
Also used : ListTupleList(mondrian.calc.impl.ListTupleList) DelegatingTupleList(mondrian.calc.impl.DelegatingTupleList) TupleList(mondrian.calc.TupleList) TupleIterable(mondrian.calc.TupleIterable) Member(mondrian.olap.Member) VisualTotalMember(mondrian.olap.fun.VisualTotalsFunDef.VisualTotalMember)

Example 9 with TupleIterable

use of mondrian.calc.TupleIterable in project mondrian by pentaho.

the class CrossJoinTest method doTupleTupleIterTest.

private void doTupleTupleIterTest(CrossJoinFunDef.CrossJoinIterCalc calc, Execution execution) {
    TupleList l4 = makeListTuple(m4);
    String s4 = toString(l4);
    String e4 = "{[U, V], [W, X], [Y, Z]}";
    Assert.assertEquals(e4, s4);
    TupleList l3 = makeListTuple(m3);
    String s3 = toString(l3);
    String e3 = "{[k, l], [m, n]}";
    Assert.assertEquals(e3, s3);
    String s = Locus.execute(execution, "CrossJoinTest", new Locus.Action<String>() {

        public String execute() {
            TupleIterable iterable = calc.makeIterable(l4, l3);
            return CrossJoinTest.this.toString(iterable);
        }
    });
    String e = "{[U, V, k, l], [U, V, m, n], [W, X, k, l], " + "[W, X, m, n], [Y, Z, k, l], [Y, Z, m, n]}";
    Assert.assertEquals(e, s);
}
Also used : UnaryTupleList(mondrian.calc.impl.UnaryTupleList) ArrayTupleList(mondrian.calc.impl.ArrayTupleList) TupleList(mondrian.calc.TupleList) TupleIterable(mondrian.calc.TupleIterable) Locus(mondrian.server.Locus)

Aggregations

TupleIterable (mondrian.calc.TupleIterable)9 TupleList (mondrian.calc.TupleList)7 Member (mondrian.olap.Member)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 TupleCursor (mondrian.calc.TupleCursor)3 IterCalc (mondrian.calc.IterCalc)2 DelegatingTupleList (mondrian.calc.impl.DelegatingTupleList)2 ListTupleList (mondrian.calc.impl.ListTupleList)2 UnaryTupleList (mondrian.calc.impl.UnaryTupleList)2 ResolvedFunCall (mondrian.mdx.ResolvedFunCall)2 Evaluator (mondrian.olap.Evaluator)2 Exp (mondrian.olap.Exp)2 VisualTotalMember (mondrian.olap.fun.VisualTotalsFunDef.VisualTotalMember)2 Iterator (java.util.Iterator)1 Calc (mondrian.calc.Calc)1 AbstractListCalc (mondrian.calc.impl.AbstractListCalc)1 AbstractTupleCursor (mondrian.calc.impl.AbstractTupleCursor)1 ArrayTupleList (mondrian.calc.impl.ArrayTupleList)1 SetEvaluator (mondrian.olap.Evaluator.SetEvaluator)1