Search in sources :

Example 6 with Calc

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

the class CastFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final Type targetType = call.getType();
    final Exp arg = call.getArg(0);
    final Calc calc = compiler.compileScalar(arg, false);
    return new CalcImpl(arg, calc, targetType);
}
Also used : Type(mondrian.olap.type.Type) Calc(mondrian.calc.Calc) GenericCalc(mondrian.calc.impl.GenericCalc)

Example 7 with Calc

use of mondrian.calc.Calc 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 8 with Calc

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

the class RolapEvaluator method getFormatString.

/**
 * Returns the format string for this cell. This is computed by evaluating
 * the format expression in the current context, and therefore different
 * cells may have different format strings.
 *
 * @post return != null
 */
public final String getFormatString() {
    final Exp formatExp = (Exp) getProperty(Property.FORMAT_EXP_PARSED.name, null);
    if (formatExp == null) {
        return "Standard";
    }
    final Calc formatCalc = root.getCompiled(formatExp, true, null);
    final Object o = formatCalc.evaluate(this);
    if (o == null) {
        return "Standard";
    }
    return o.toString();
}
Also used : Calc(mondrian.calc.Calc)

Aggregations

Calc (mondrian.calc.Calc)8 GenericCalc (mondrian.calc.impl.GenericCalc)4 ArrayList (java.util.ArrayList)2 ResolvedFunCall (mondrian.mdx.ResolvedFunCall)2 ResultStyle (mondrian.calc.ResultStyle)1 TupleList (mondrian.calc.TupleList)1 ArrayTupleList (mondrian.calc.impl.ArrayTupleList)1 ConstantCalc (mondrian.calc.impl.ConstantCalc)1 UnaryTupleList (mondrian.calc.impl.UnaryTupleList)1 Exp (mondrian.olap.Exp)1 FunDef (mondrian.olap.FunDef)1 Member (mondrian.olap.Member)1 SetListCalc (mondrian.olap.fun.SetFunDef.SetListCalc)1 SetType (mondrian.olap.type.SetType)1 Type (mondrian.olap.type.Type)1