Search in sources :

Example 1 with AbstractTupleCursor

use of mondrian.calc.impl.AbstractTupleCursor 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)

Aggregations

ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 TupleIterable (mondrian.calc.TupleIterable)1 TupleList (mondrian.calc.TupleList)1 AbstractTupleCursor (mondrian.calc.impl.AbstractTupleCursor)1 UnaryTupleList (mondrian.calc.impl.UnaryTupleList)1 ResolvedFunCall (mondrian.mdx.ResolvedFunCall)1 Evaluator (mondrian.olap.Evaluator)1 SetEvaluator (mondrian.olap.Evaluator.SetEvaluator)1 Exp (mondrian.olap.Exp)1 FunDef (mondrian.olap.FunDef)1 Member (mondrian.olap.Member)1 AggregateFunDef (mondrian.olap.fun.AggregateFunDef)1 NullFunDef (mondrian.olap.fun.CrossJoinTest.NullFunDef)1 ParenthesesFunDef (mondrian.olap.fun.ParenthesesFunDef)1 TestMember (mondrian.olap.fun.TestMember)1 TupleType (mondrian.olap.type.TupleType)1