Search in sources :

Example 1 with ResolvedFunCall

use of mondrian.mdx.ResolvedFunCall in project mondrian by pentaho.

the class IifFunDefTest method setUp.

@Override
protected void setUp() throws Exception {
    when(trueCaseParamMock.getType()).thenReturn(setTypeMock);
    setListCalc = new SetListCalc(trueCaseParamMock, new Exp[] { args[1] }, compilerMock, ResultStyle.LIST_MUTABLELIST);
    call = new ResolvedFunCall(funDefMock, args, setTypeMock);
    when(compilerMock.compileAs(any(), any(), any())).thenReturn(setListCalc);
}
Also used : ResolvedFunCall(mondrian.mdx.ResolvedFunCall) SetListCalc(mondrian.olap.fun.SetFunDef.SetListCalc) Exp(mondrian.olap.Exp)

Example 2 with ResolvedFunCall

use of mondrian.mdx.ResolvedFunCall 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 3 with ResolvedFunCall

use of mondrian.mdx.ResolvedFunCall in project mondrian by pentaho.

the class ScenarioImpl method forMember.

/**
 * Returns the scenario inside a calculated member in the scenario
 * dimension. For example, applied to [Scenario].[1], returns the Scenario
 * object representing scenario #1.
 *
 * @param member Wrapper member
 * @return Wrapped scenario
 */
static Scenario forMember(final RolapMember member) {
    if (isScenario(member.getHierarchy())) {
        final Formula formula = ((RolapCalculatedMember) member).getFormula();
        final ResolvedFunCall resolvedFunCall = (ResolvedFunCall) formula.getExpression();
        final Calc calc = resolvedFunCall.getFunDef().compileCall(null, null);
        return ((ScenarioCalc) calc).getScenario();
    } else {
        return null;
    }
}
Also used : ResolvedFunCall(mondrian.mdx.ResolvedFunCall) Calc(mondrian.calc.Calc) GenericCalc(mondrian.calc.impl.GenericCalc)

Example 4 with ResolvedFunCall

use of mondrian.mdx.ResolvedFunCall in project mondrian by pentaho.

the class SqlConstraintUtilsTest method testIsSupportedExpressionForCalculatedMember.

// ~ Test methods ----------------------------------------------------------
public void testIsSupportedExpressionForCalculatedMember() {
    Assert.assertEquals("null expression", false, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(null));
    Exp memberExpr = new MemberExpr(Mockito.mock(Member.class));
    Assert.assertEquals("MemberExpr", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(memberExpr));
    Exp nullFunDefExpr = new ResolvedFunCall(new NullFunDef(), new Exp[] {}, new NullType());
    Assert.assertEquals("ResolvedFunCall-NullFunDef", false, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(nullFunDefExpr));
    // ResolvedFunCall arguments
    final Exp argUnsupported = new ResolvedFunCall(new NullFunDef(), new Exp[] {}, new NullType());
    final Exp argSupported = new MemberExpr(Mockito.mock(Member.class));
    Assert.assertEquals(false, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(argUnsupported));
    Assert.assertEquals(true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(argSupported));
    final Exp[] noArgs = new Exp[] {};
    final Exp[] args1Unsupported = new Exp[] { argUnsupported };
    final Exp[] args1Supported = new Exp[] { argSupported };
    final Exp[] args2Different = new Exp[] { argUnsupported, argSupported };
    final ParenthesesFunDef parenthesesFunDef = new ParenthesesFunDef(Category.Member);
    Type parenthesesReturnType = new DecimalType(1, 1);
    Exp parenthesesExpr = new ResolvedFunCall(parenthesesFunDef, noArgs, parenthesesReturnType);
    Assert.assertEquals("ResolvedFunCall-Parentheses()", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(parenthesesExpr));
    parenthesesExpr = new ResolvedFunCall(parenthesesFunDef, args1Unsupported, parenthesesReturnType);
    Assert.assertEquals("ResolvedFunCall-Parentheses(N)", false, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(parenthesesExpr));
    parenthesesExpr = new ResolvedFunCall(parenthesesFunDef, args1Supported, parenthesesReturnType);
    Assert.assertEquals("ResolvedFunCall-Parentheses(Y)", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(parenthesesExpr));
    parenthesesExpr = new ResolvedFunCall(parenthesesFunDef, args2Different, parenthesesReturnType);
    Assert.assertEquals("ResolvedFunCall-Parentheses(N,Y)", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(parenthesesExpr));
    FunDef dummy = Mockito.mock(FunDef.class);
    Mockito.doReturn(Syntax.Function).when(dummy).getSyntax();
    Mockito.doReturn("dummy").when(dummy).getName();
    FunDef aggregateFunDef = new AggregateFunDef(dummy);
    Type aggregateReturnType = new DecimalType(1, 1);
    Exp aggregateExpr = new ResolvedFunCall(aggregateFunDef, noArgs, aggregateReturnType);
    Assert.assertEquals("ResolvedFunCall-Aggregate()", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(aggregateExpr));
    aggregateExpr = new ResolvedFunCall(aggregateFunDef, args1Unsupported, aggregateReturnType);
    Assert.assertEquals("ResolvedFunCall-Aggregate(N)", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(aggregateExpr));
    aggregateExpr = new ResolvedFunCall(aggregateFunDef, args1Supported, aggregateReturnType);
    Assert.assertEquals("ResolvedFunCall-Aggregate(Y)", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(aggregateExpr));
    aggregateExpr = new ResolvedFunCall(aggregateFunDef, args2Different, aggregateReturnType);
    Assert.assertEquals("ResolvedFunCall-Aggregate(N,Y)", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(aggregateExpr));
}
Also used : FunDef(mondrian.olap.FunDef) ParenthesesFunDef(mondrian.olap.fun.ParenthesesFunDef) AggregateFunDef(mondrian.olap.fun.AggregateFunDef) NullFunDef(mondrian.olap.fun.CrossJoinTest.NullFunDef) NullType(mondrian.olap.type.NullType) DecimalType(mondrian.olap.type.DecimalType) TupleType(mondrian.olap.type.TupleType) Type(mondrian.olap.type.Type) NullFunDef(mondrian.olap.fun.CrossJoinTest.NullFunDef) MemberExpr(mondrian.mdx.MemberExpr) ParenthesesFunDef(mondrian.olap.fun.ParenthesesFunDef) DecimalType(mondrian.olap.type.DecimalType) ResolvedFunCall(mondrian.mdx.ResolvedFunCall) AggregateFunDef(mondrian.olap.fun.AggregateFunDef) NullType(mondrian.olap.type.NullType) Exp(mondrian.olap.Exp) Member(mondrian.olap.Member) TestMember(mondrian.olap.fun.TestMember)

Example 5 with ResolvedFunCall

use of mondrian.mdx.ResolvedFunCall 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

ResolvedFunCall (mondrian.mdx.ResolvedFunCall)17 Exp (mondrian.olap.Exp)13 Member (mondrian.olap.Member)8 FunDef (mondrian.olap.FunDef)7 Type (mondrian.olap.type.Type)7 TupleType (mondrian.olap.type.TupleType)6 ArrayList (java.util.ArrayList)5 TupleList (mondrian.calc.TupleList)5 UnaryTupleList (mondrian.calc.impl.UnaryTupleList)5 MemberExpr (mondrian.mdx.MemberExpr)5 NullFunDef (mondrian.olap.fun.CrossJoinTest.NullFunDef)5 NullType (mondrian.olap.type.NullType)5 List (java.util.List)4 Calc (mondrian.calc.Calc)4 AggregateFunDef (mondrian.olap.fun.AggregateFunDef)4 ParenthesesFunDef (mondrian.olap.fun.ParenthesesFunDef)4 TestMember (mondrian.olap.fun.TestMember)4 SetType (mondrian.olap.type.SetType)4 Evaluator (mondrian.olap.Evaluator)3 DecimalType (mondrian.olap.type.DecimalType)3