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);
}
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());
}
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();
}
Aggregations