Search in sources :

Example 11 with ResolvedFunCall

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

the class UnionFunDefTest method testMondrian2250.

/**
 * Test for MONDRIAN-2250 issue.
 * Tests that the result is independent on the hashCode.
 * For this purpose MemberForTest with rewritten hashCode is used.
 *
 * Tuples are gotten from customer attachments.
 */
public void testMondrian2250() {
    Member[] dates = new Member[4];
    for (int i = 25; i < 29; i++) {
        dates[i - 25] = new MemberForTest("[Consumption Date.Calendar].[2014-07-" + i + "]");
    }
    List<Member> list = Arrays.asList(dates);
    UnaryTupleList unaryTupleList = new UnaryTupleList(list);
    Member consumptionMethod = new MemberForTest("[Consumption Method].[PVR]");
    Member measuresAverageTimeshift = new MemberForTest("[Measures].[Average Timeshift]");
    String[] hours = { "00", "14", "15", "16", "23" };
    Member[] times = new Member[5];
    for (int i = 0; i < hours.length; i++) {
        times[i] = new MemberForTest("[Consumption Time.Time].[" + hours[i] + ":00]");
    }
    int arity = 3;
    ArrayTupleList arrayTupleList = new ArrayTupleList(arity);
    for (Member time : times) {
        List<Member> currentList = new ArrayList(3);
        currentList.add(consumptionMethod);
        currentList.add(measuresAverageTimeshift);
        currentList.add(time);
        arrayTupleList.add(currentList);
    }
    CrossJoinFunDef crossJoinFunDef = new CrossJoinFunDef(new CrossJoinTest.NullFunDef());
    Exp[] expMock = new Exp[1];
    expMock[0] = mock(Exp.class);
    ResolvedFunCall resolvedFunCall = new ResolvedFunCall(mock(FunDef.class), expMock, mock(SetType.class));
    Calc[] calcs = new Calc[1];
    calcs[0] = Mockito.mock(Calc.class);
    CrossJoinFunDef.ImmutableListCalc immutableListCalc = crossJoinFunDef.new ImmutableListCalc(resolvedFunCall, calcs);
    TupleList listForUnion1 = immutableListCalc.makeList(unaryTupleList, arrayTupleList);
    List<Member> list2 = Arrays.asList(dates);
    UnaryTupleList unaryTupleList2 = new UnaryTupleList(list2);
    Member measuresTotalViewingTime = new MemberForTest("[Measures].[Total Viewing Time]");
    ArrayTupleList arrayTupleList2 = new ArrayTupleList(arity);
    for (Member time : times) {
        List<Member> currentList = new ArrayList(3);
        currentList.add(consumptionMethod);
        currentList.add(measuresTotalViewingTime);
        currentList.add(time);
        arrayTupleList2.add(currentList);
    }
    TupleList listForUnion2 = immutableListCalc.makeList(unaryTupleList2, arrayTupleList2);
    UnionFunDef unionFunDefMock = Mockito.mock(UnionFunDef.class);
    doCallRealMethod().when(unionFunDefMock).union(any(TupleList.class), any(TupleList.class), anyBoolean());
    TupleList tupleList = unionFunDefMock.union(listForUnion1, listForUnion2, false);
    System.out.println(tupleList);
    assertEquals(40, tupleList.size());
}
Also used : ArrayList(java.util.ArrayList) Calc(mondrian.calc.Calc) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) TupleList(mondrian.calc.TupleList) ArrayTupleList(mondrian.calc.impl.ArrayTupleList) FunDef(mondrian.olap.FunDef) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) ArrayTupleList(mondrian.calc.impl.ArrayTupleList) SetType(mondrian.olap.type.SetType) ResolvedFunCall(mondrian.mdx.ResolvedFunCall) Exp(mondrian.olap.Exp) Member(mondrian.olap.Member)

Example 12 with ResolvedFunCall

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

the class CompoundPredicateInfo method makeCalculatedMemberPredicate.

private StarPredicate makeCalculatedMemberPredicate(RolapCubeMember member, RolapCube baseCube, Evaluator evaluator) {
    assert member.getExpression() instanceof ResolvedFunCall;
    ResolvedFunCall fun = (ResolvedFunCall) member.getExpression();
    final Exp exp = fun.getArg(0);
    final Type type = exp.getType();
    if (type instanceof SetType) {
        return makeSetPredicate(exp, evaluator);
    } else if (type.getArity() == 1) {
        return makeUnaryPredicate(member, baseCube, evaluator);
    } else {
        throw MondrianResource.instance().UnsupportedCalculatedMember.ex(member.getName(), null);
    }
}
Also used : Type(mondrian.olap.type.Type) SetType(mondrian.olap.type.SetType) SetType(mondrian.olap.type.SetType) ResolvedFunCall(mondrian.mdx.ResolvedFunCall) Exp(mondrian.olap.Exp)

Example 13 with ResolvedFunCall

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

the class SqlContextConstraint method findMeasures.

/**
 * Extracts the stored measures referenced in an expression
 *
 * @param exp expression
 * @param baseCubes set of base cubes
 */
private static void findMeasures(Exp exp, Set<RolapCube> baseCubes, List<RolapCube> baseCubeList) {
    if (exp instanceof MemberExpr) {
        MemberExpr memberExpr = (MemberExpr) exp;
        Member member = memberExpr.getMember();
        if (member instanceof RolapStoredMeasure) {
            addMeasure((RolapStoredMeasure) member, baseCubes, baseCubeList);
        } else if (member instanceof RolapCalculatedMember) {
            findMeasures(member.getExpression(), baseCubes, baseCubeList);
        }
    } else if (exp instanceof ResolvedFunCall) {
        ResolvedFunCall funCall = (ResolvedFunCall) exp;
        Exp[] args = funCall.getArgs();
        for (Exp arg : args) {
            findMeasures(arg, baseCubes, baseCubeList);
        }
    }
}
Also used : MemberExpr(mondrian.mdx.MemberExpr) ResolvedFunCall(mondrian.mdx.ResolvedFunCall) MultiCardinalityDefaultMember(mondrian.rolap.RestrictedMemberReader.MultiCardinalityDefaultMember) LimitedRollupMember(mondrian.rolap.RolapHierarchy.LimitedRollupMember)

Example 14 with ResolvedFunCall

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

the class AbstractCalc method getName.

/**
 * Returns the name of this expression type, used when serializing an
 * expression to a string.
 *
 * <p>The default implementation tries to extract a name from a function
 * call, if any, then prints the last part of the class name.
 */
protected String getName() {
    String name = lastSegment(getClass());
    if (isDigits(name) && exp instanceof ResolvedFunCall) {
        ResolvedFunCall funCall = (ResolvedFunCall) exp;
        name = funCall.getFunDef().getName();
    }
    return name;
}
Also used : ResolvedFunCall(mondrian.mdx.ResolvedFunCall)

Aggregations

ResolvedFunCall (mondrian.mdx.ResolvedFunCall)14 Exp (mondrian.olap.Exp)9 FunDef (mondrian.olap.FunDef)5 Member (mondrian.olap.Member)5 NullFunDef (mondrian.olap.fun.CrossJoinTest.NullFunDef)5 NullType (mondrian.olap.type.NullType)5 Type (mondrian.olap.type.Type)5 MemberExpr (mondrian.mdx.MemberExpr)4 AggregateFunDef (mondrian.olap.fun.AggregateFunDef)4 ParenthesesFunDef (mondrian.olap.fun.ParenthesesFunDef)4 TestMember (mondrian.olap.fun.TestMember)4 TupleType (mondrian.olap.type.TupleType)4 ArrayList (java.util.ArrayList)3 TupleList (mondrian.calc.TupleList)3 UnaryTupleList (mondrian.calc.impl.UnaryTupleList)3 DecimalType (mondrian.olap.type.DecimalType)3 List (java.util.List)2 Calc (mondrian.calc.Calc)2 TupleIterable (mondrian.calc.TupleIterable)2 SetEvaluator (mondrian.olap.Evaluator.SetEvaluator)2