Search in sources :

Example 1 with TupleIterable

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

the class SqlConstraintUtils method expandSetFromCalculatedMember.

public static void expandSetFromCalculatedMember(Evaluator evaluator, Member member, TupleConstraintStruct expandedSet) {
    assert member.getExpression() instanceof ResolvedFunCall;
    ResolvedFunCall fun = (ResolvedFunCall) member.getExpression();
    // Calling the main set evaluator to extend this.
    Exp exp = fun.getArg(0);
    TupleIterable tupleIterable = evaluator.getSetEvaluator(exp, true).evaluateTupleIterable();
    Iterator<List<Member>> tupleIterator = tupleIterable.iterator();
    TupleList tupleList = TupleCollections.materialize(tupleIterable, false);
    boolean disjointSlicerTuple = false;
    if (tupleList != null) {
        disjointSlicerTuple = SqlConstraintUtils.isDisjointTuple(tupleList);
    }
    if (disjointSlicerTuple) {
        if (!tupleList.isEmpty()) {
            expandedSet.addTupleList(tupleList);
        }
    } else {
        while (tupleIterator.hasNext()) {
            expandedSet.addMembers(tupleIterator.next());
        }
    }
}
Also used : TupleList(mondrian.calc.TupleList) TupleIterable(mondrian.calc.TupleIterable) ResolvedFunCall(mondrian.mdx.ResolvedFunCall) List(java.util.List) FilteredIterableList(mondrian.util.FilteredIterableList) ArrayList(java.util.ArrayList) TupleList(mondrian.calc.TupleList) Exp(mondrian.olap.Exp)

Example 2 with TupleIterable

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

the class SqlConstraintUtilsTest method getCalculatedMember.

public TupleConstraintStruct getCalculatedMember(final List<List<Member>> table, int arity) {
    Member memberMock = mock(Member.class);
    Exp[] funCallArgExps = new Exp[0];
    ResolvedFunCall funCallArgMock = new ResolvedFunCall(mock(FunDef.class), funCallArgExps, mock(TupleType.class));
    Exp[] funCallExps = { funCallArgMock };
    ResolvedFunCall funCallMock = new ResolvedFunCall(mock(FunDef.class), funCallExps, mock(TupleType.class));
    when(memberMock.getExpression()).thenReturn(funCallMock);
    Evaluator evaluatorMock = mock(Evaluator.class);
    Evaluator.SetEvaluator setEvaluatorMock = mock(Evaluator.SetEvaluator.class);
    TupleIterable tupleIterableMock = mock(TupleIterable.class);
    when(tupleIterableMock.iterator()).thenReturn(table.iterator());
    when(tupleIterableMock.getArity()).thenReturn(arity);
    AbstractTupleCursor cursor = new AbstractTupleCursor(arity) {

        Iterator<List<Member>> iterator = table.iterator();

        List<Member> curList;

        @Override
        public boolean forward() {
            boolean hasNext = iterator.hasNext();
            if (hasNext) {
                curList = iterator.next();
            } else {
                curList = null;
            }
            return hasNext;
        }

        @Override
        public List<Member> current() {
            return curList;
        }
    };
    when(tupleIterableMock.tupleCursor()).thenReturn(cursor);
    when(setEvaluatorMock.evaluateTupleIterable()).thenReturn(tupleIterableMock);
    when(evaluatorMock.getSetEvaluator(eq(funCallArgMock), anyBoolean())).thenReturn(setEvaluatorMock);
    TupleConstraintStruct constraint = new TupleConstraintStruct();
    SqlConstraintUtils.expandSetFromCalculatedMember(evaluatorMock, memberMock, constraint);
    return constraint;
}
Also used : Evaluator(mondrian.olap.Evaluator) SetEvaluator(mondrian.olap.Evaluator.SetEvaluator) FunDef(mondrian.olap.FunDef) ParenthesesFunDef(mondrian.olap.fun.ParenthesesFunDef) AggregateFunDef(mondrian.olap.fun.AggregateFunDef) NullFunDef(mondrian.olap.fun.CrossJoinTest.NullFunDef) TupleIterable(mondrian.calc.TupleIterable) TupleType(mondrian.olap.type.TupleType) Iterator(java.util.Iterator) ResolvedFunCall(mondrian.mdx.ResolvedFunCall) ArrayList(java.util.ArrayList) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) TupleList(mondrian.calc.TupleList) List(java.util.List) AbstractTupleCursor(mondrian.calc.impl.AbstractTupleCursor) Exp(mondrian.olap.Exp) Member(mondrian.olap.Member) TestMember(mondrian.olap.fun.TestMember) SetEvaluator(mondrian.olap.Evaluator.SetEvaluator)

Example 3 with TupleIterable

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

the class RolapResult method executeAxis.

private TupleIterable executeAxis(Evaluator evaluator, QueryAxis queryAxis, Calc axisCalc, boolean construct, AxisMemberList axisMembers) {
    if (queryAxis == null) {
        // the same as an empty axis).
        return new DelegatingTupleList(0, Collections.singletonList(Collections.<Member>emptyList()));
    }
    final int savepoint = evaluator.savepoint();
    try {
        evaluator.setNonEmpty(queryAxis.isNonEmpty());
        evaluator.setEvalAxes(true);
        final TupleIterable iterable = ((IterCalc) axisCalc).evaluateIterable(evaluator);
        if (axisCalc.getClass().getName().indexOf("OrderFunDef") != -1) {
            queryAxis.setOrdered(true);
        }
        if (iterable instanceof TupleList) {
            TupleList list = (TupleList) iterable;
            if (construct) {
            } else if (axisMembers != null) {
                axisMembers.mergeTupleList(list);
            }
        } else {
            // Iterable
            TupleCursor cursor = iterable.tupleCursor();
            if (construct) {
            } else if (axisMembers != null) {
                axisMembers.mergeTupleIter(cursor);
            }
        }
        return iterable;
    } finally {
        evaluator.restore(savepoint);
    }
}
Also used : ListTupleList(mondrian.calc.impl.ListTupleList) DelegatingTupleList(mondrian.calc.impl.DelegatingTupleList) TupleList(mondrian.calc.TupleList) TupleIterable(mondrian.calc.TupleIterable) IterCalc(mondrian.calc.IterCalc) TupleCursor(mondrian.calc.TupleCursor) Member(mondrian.olap.Member) VisualTotalMember(mondrian.olap.fun.VisualTotalsFunDef.VisualTotalMember) DelegatingTupleList(mondrian.calc.impl.DelegatingTupleList)

Example 4 with TupleIterable

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

the class CompoundPredicateInfo method makeSetPredicate.

private StarPredicate makeSetPredicate(final Exp exp, Evaluator evaluator) {
    TupleIterable evaluatedSet = evaluator.getSetEvaluator(exp, true).evaluateTupleIterable();
    ArrayList<StarPredicate> orList = new ArrayList<StarPredicate>();
    OrPredicate orPredicate = null;
    for (List<Member> complexSetItem : evaluatedSet) {
        List<StarPredicate> andList = new ArrayList<StarPredicate>();
        for (Member singleSetItem : complexSetItem) {
            final List<List<Member>> singleItemList = Collections.singletonList(Collections.singletonList(singleSetItem));
            StarPredicate singlePredicate = predicateFromTupleList(singleItemList, measure, evaluator).getValue();
            andList.add(singlePredicate);
        }
        AndPredicate andPredicate = new AndPredicate(andList);
        orList.add(andPredicate);
        orPredicate = new OrPredicate(orList);
    }
    return orPredicate;
}
Also used : TupleIterable(mondrian.calc.TupleIterable) OrPredicate(mondrian.rolap.agg.OrPredicate) ArrayList(java.util.ArrayList) AndPredicate(mondrian.rolap.agg.AndPredicate) ArrayList(java.util.ArrayList) List(java.util.List) Member(mondrian.olap.Member)

Example 5 with TupleIterable

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

the class RolapNamedSetEvaluator method ensureList.

/**
 * Evaluates and saves the value of this named set, if it has not been evaluated already.
 */
private void ensureList(Evaluator evaluator) {
    if (list != null) {
        if (list == DUMMY_LIST) {
            recursionCount++;
            if (RECURSION_TOLERANCE > 0 && recursionCount > RECURSION_TOLERANCE) {
                throw rrer.result.slicerEvaluator.newEvalException(null, "Illegal attempt to reference value of named set '" + namedSet.getName() + "' while evaluating itself");
            }
        }
        return;
    }
    if (RolapResult.LOGGER.isDebugEnabled()) {
        RolapResult.LOGGER.debug("Named set " + namedSet.getName() + ": starting evaluation");
    }
    // recursion detection
    list = DUMMY_LIST;
    try {
        final Calc calc = rrer.getCompiled(namedSet.getExp(), false, ResultStyle.ITERABLE);
        TupleIterable iterable = (TupleIterable) rrer.result.evaluateExp(calc, rrer.result.slicerEvaluator, evaluator);
        // Axes can be in two forms: list or iterable. If iterable, we
        // need to materialize it, to ensure that all cell values are in
        // cache.
        final TupleList rawList;
        if (iterable instanceof TupleList) {
            rawList = (TupleList) iterable;
        } else {
            rawList = TupleCollections.createList(iterable.getArity());
            TupleCursor cursor = iterable.tupleCursor();
            while (cursor.forward()) {
                rawList.addCurrent(cursor);
            }
        }
        if (RolapResult.LOGGER.isDebugEnabled()) {
            RolapResult.LOGGER.debug(generateDebugMessage(calc, rawList));
        }
        // NamedSets are not supposed to depend on the current evaluation context but the
        // way NamedSet evaluation was implemented in Mondrian, they could...
        // So as a result, the nameset calc has to be profiled at the time of use instead
        // of on close of the statement.
        Util.explain(rrer.statement.getProfileHandler(), "NamedSet (" + namedSet.getName() + "):", calc, evaluator.getTiming());
        // Wrap list so that currentOrdinal is updated whenever the list
        // is accessed. The list is immutable, because we don't override
        // AbstractList.set(int, Object).
        this.list = rawList.withPositionCallback(this);
    } finally {
        if (this.list == DUMMY_LIST) {
            this.list = null;
        }
        recursionCount = 0;
    }
}
Also used : TupleList(mondrian.calc.TupleList) TupleIterable(mondrian.calc.TupleIterable) TupleCursor(mondrian.calc.TupleCursor) Calc(mondrian.calc.Calc)

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