use of mondrian.calc.Calc in project mondrian by pentaho.
the class CaseMatchFunDef method compileCall.
public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
final Exp[] args = call.getArgs();
final List<Calc> calcList = new ArrayList<Calc>();
final Calc valueCalc = compiler.compileScalar(args[0], true);
calcList.add(valueCalc);
final int matchCount = (args.length - 1) / 2;
final Calc[] matchCalcs = new Calc[matchCount];
final Calc[] exprCalcs = new Calc[matchCount];
for (int i = 0, j = 1; i < exprCalcs.length; i++) {
matchCalcs[i] = compiler.compileScalar(args[j++], true);
calcList.add(matchCalcs[i]);
exprCalcs[i] = compiler.compile(args[j++]);
calcList.add(exprCalcs[i]);
}
final Calc defaultCalc = args.length % 2 == 0 ? compiler.compile(args[args.length - 1]) : ConstantCalc.constantNull(call.getType());
calcList.add(defaultCalc);
final Calc[] calcs = calcList.toArray(new Calc[calcList.size()]);
return new GenericCalc(call) {
public Object evaluate(Evaluator evaluator) {
Object value = valueCalc.evaluate(evaluator);
for (int i = 0; i < matchCalcs.length; i++) {
Object match = matchCalcs[i].evaluate(evaluator);
if (match.equals(value)) {
return exprCalcs[i].evaluate(evaluator);
}
}
return defaultCalc.evaluate(evaluator);
}
public Calc[] getCalcs() {
return calcs;
}
};
}
use of mondrian.calc.Calc in project mondrian by pentaho.
the class CoalesceEmptyFunDef method compileCall.
public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
final Exp[] args = call.getArgs();
final Calc[] calcs = new Calc[args.length];
for (int i = 0; i < args.length; i++) {
calcs[i] = compiler.compileScalar(args[i], true);
}
return new GenericCalc(call) {
public Object evaluate(Evaluator evaluator) {
for (Calc calc : calcs) {
final Object o = calc.evaluate(evaluator);
if (o != null) {
return o;
}
}
return null;
}
public Calc[] getCalcs() {
return calcs;
}
};
}
use of mondrian.calc.Calc in project mondrian by pentaho.
the class RolapEvaluator method evaluateCurrent.
public final Object evaluateCurrent() {
// Get the member in the current context which is (a) calculated, and
// (b) has the highest solve order. If there are no calculated members,
// go ahead and compute the cell.
RolapCalculation maxSolveMember;
switch(calculationCount) {
case 0:
final Object o = cellReader.get(this);
if (o == Util.nullValue) {
return null;
}
return o;
case 1:
maxSolveMember = calculations[0];
break;
default:
switch(root.solveOrderMode) {
case ABSOLUTE:
maxSolveMember = getAbsoluteMaxSolveOrder();
break;
case SCOPED:
maxSolveMember = getScopedMaxSolveOrder();
break;
default:
throw Util.unexpected(root.solveOrderMode);
}
}
final int savepoint = savepoint();
maxSolveMember.setContextIn(this);
final Calc calc = maxSolveMember.getCompiledExpression(root);
final Object o;
try {
o = calc.evaluate(this);
} finally {
restore(savepoint);
}
if (o == Util.nullValue) {
return null;
}
return o;
}
use of mondrian.calc.Calc 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;
}
}
use of mondrian.calc.Calc in project mondrian by pentaho.
the class IifFunDefTest method testGetResultType.
public void testGetResultType() {
ResultStyle actualResStyle = null;
ResultStyle expectedResStyle = setListCalc.getResultStyle();
// Compile calculation for IIf function for (<Logical Expression>, <SetType>, <SetType>) params
Calc calc = IifFunDef.SET_INSTANCE.compileCall(call, compilerMock);
try {
actualResStyle = calc.getResultStyle();
} catch (Exception e) {
fail("Should not have thrown any exception.");
}
assertNotNull(actualResStyle);
assertEquals(expectedResStyle, actualResStyle);
}
Aggregations