Search in sources :

Example 1 with Evaluator

use of mondrian.olap.Evaluator in project mondrian by pentaho.

the class SqlConstraintUtilsTest method testExpandSupportedCalculatedMember_calculated_memberExpr.

public void testExpandSupportedCalculatedMember_calculated_memberExpr() {
    Evaluator evaluator = Mockito.mock(Evaluator.class);
    Member resultMember = makeNoncalculatedMember("0");
    Member member = makeMemberExprMember(resultMember);
    // tested call
    TupleConstraintStruct constraint = new TupleConstraintStruct();
    SqlConstraintUtils.expandSupportedCalculatedMember(member, evaluator, constraint);
    List<Member> r = constraint.getMembers();
    // test
    Assert.assertNotNull(r);
    Assert.assertEquals(1, r.size());
    Assert.assertSame(resultMember, r.get(0));
}
Also used : Evaluator(mondrian.olap.Evaluator) SetEvaluator(mondrian.olap.Evaluator.SetEvaluator) Member(mondrian.olap.Member) TestMember(mondrian.olap.fun.TestMember)

Example 2 with Evaluator

use of mondrian.olap.Evaluator in project mondrian by pentaho.

the class SqlConstraintUtilsTest method testExpandSupportedCalculatedMember_calculated_parentheses.

public void testExpandSupportedCalculatedMember_calculated_parentheses() {
    Evaluator evaluator = Mockito.mock(Evaluator.class);
    Member resultMember = Mockito.mock(Member.class);
    Member member = this.makeParenthesesExprMember(evaluator, resultMember, "0");
    // tested call
    TupleConstraintStruct constraint = new TupleConstraintStruct();
    SqlConstraintUtils.expandSupportedCalculatedMember(member, evaluator, constraint);
    List<Member> r = constraint.getMembers();
    // test
    Assert.assertNotNull(r);
    Assert.assertEquals(1, r.size());
    Assert.assertSame(resultMember, r.get(0));
}
Also used : Evaluator(mondrian.olap.Evaluator) SetEvaluator(mondrian.olap.Evaluator.SetEvaluator) Member(mondrian.olap.Member) TestMember(mondrian.olap.fun.TestMember)

Example 3 with Evaluator

use of mondrian.olap.Evaluator 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 4 with Evaluator

use of mondrian.olap.Evaluator in project mondrian by pentaho.

the class SqlConstraintUtilsTest method testExpandSupportedCalculatedMember_calculated_unsupported.

public void testExpandSupportedCalculatedMember_calculated_unsupported() {
    Evaluator evaluator = Mockito.mock(Evaluator.class);
    Member member = makeUnsupportedCalculatedMember("0");
    // tested call
    TupleConstraintStruct constraint = new TupleConstraintStruct();
    SqlConstraintUtils.expandSupportedCalculatedMember(member, evaluator, constraint);
    List<Member> r = constraint.getMembers();
    // test
    Assert.assertNotNull(r);
    Assert.assertEquals(1, r.size());
    Assert.assertSame(member, r.get(0));
}
Also used : Evaluator(mondrian.olap.Evaluator) SetEvaluator(mondrian.olap.Evaluator.SetEvaluator) Member(mondrian.olap.Member) TestMember(mondrian.olap.fun.TestMember)

Example 5 with Evaluator

use of mondrian.olap.Evaluator in project mondrian by pentaho.

the class SqlConstraintUtilsTest method testExpandSupportedCalculatedMembers.

public void testExpandSupportedCalculatedMembers() {
    Evaluator evaluator = Mockito.mock(Evaluator.class);
    Member endMember0 = Mockito.mock(Member.class);
    Member endMember1 = Mockito.mock(Member.class);
    Member endMember2 = Mockito.mock(Member.class);
    Member endMember3 = Mockito.mock(Member.class);
    Member argMember0 = null;
    Member argMember1 = null;
    Member[] argMembers = null;
    Member[] expectedMembers = null;
    // ()
    argMembers = new Member[] {};
    expectedMembers = new Member[] {};
    assertEveryExpandSupportedCalculatedMembers("()", expectedMembers, argMembers, evaluator);
    // (0, 2)
    argMember0 = endMember0;
    argMember1 = endMember2;
    argMembers = new Member[] { argMember0, argMember1 };
    expectedMembers = new Member[] { endMember0, endMember2 };
    assertEveryExpandSupportedCalculatedMembers("(0, 2)", expectedMembers, argMembers, evaluator);
    // (Aggr(0, 1), 2)
    argMember0 = makeAggregateExprMember(evaluator, Arrays.asList(new Member[] { endMember0, endMember1 }));
    argMember1 = endMember2;
    argMembers = new Member[] { argMember0, argMember1 };
    expectedMembers = new Member[] { endMember0, endMember1, endMember2 };
    assertEveryExpandSupportedCalculatedMembers("(Aggr(0, 1), 2)", expectedMembers, argMembers, evaluator);
    // (Aggr(0, 1), Aggr(3, 2))
    argMember0 = makeAggregateExprMember(evaluator, Arrays.asList(new Member[] { endMember0, endMember1 }));
    argMember1 = makeAggregateExprMember(evaluator, Arrays.asList(new Member[] { endMember3, endMember2 }));
    argMember1 = endMember2;
    argMembers = new Member[] { argMember0, argMember1 };
    expectedMembers = new Member[] { endMember0, endMember1, endMember2 };
    assertEveryExpandSupportedCalculatedMembers("(Aggr(0, 1), Aggr(3, 2))", expectedMembers, argMembers, evaluator);
}
Also used : Evaluator(mondrian.olap.Evaluator) SetEvaluator(mondrian.olap.Evaluator.SetEvaluator) Member(mondrian.olap.Member) TestMember(mondrian.olap.fun.TestMember)

Aggregations

Evaluator (mondrian.olap.Evaluator)15 Member (mondrian.olap.Member)11 SetEvaluator (mondrian.olap.Evaluator.SetEvaluator)7 TestMember (mondrian.olap.fun.TestMember)7 AbstractListCalc (mondrian.calc.impl.AbstractListCalc)4 Result (mondrian.olap.Result)3 NonEmptyResult (mondrian.rolap.RolapConnection.NonEmptyResult)3 MemberChildrenConstraint (mondrian.rolap.sql.MemberChildrenConstraint)3 TupleIterable (mondrian.calc.TupleIterable)2 TupleList (mondrian.calc.TupleList)2 Level (mondrian.olap.Level)2 TupleConstraint (mondrian.rolap.sql.TupleConstraint)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 IterCalc (mondrian.calc.IterCalc)1 AbstractStringCalc (mondrian.calc.impl.AbstractStringCalc)1 AbstractTupleCursor (mondrian.calc.impl.AbstractTupleCursor)1 UnaryTupleList (mondrian.calc.impl.UnaryTupleList)1 ResolvedFunCall (mondrian.mdx.ResolvedFunCall)1