use of mondrian.calc.impl.AbstractMemberCalc in project mondrian by pentaho.
the class NamedSetCurrentFunDef method compileCall.
public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
final Exp arg0 = call.getArg(0);
assert arg0 instanceof NamedSetExpr : "checked this in createCall";
final NamedSetExpr namedSetExpr = (NamedSetExpr) arg0;
if (arg0.getType().getArity() == 1) {
return new AbstractMemberCalc(call, new Calc[0]) {
public Member evaluateMember(Evaluator evaluator) {
return namedSetExpr.getEval(evaluator).currentMember();
}
};
} else {
return new AbstractTupleCalc(call, new Calc[0]) {
public Member[] evaluateTuple(Evaluator evaluator) {
return namedSetExpr.getEval(evaluator).currentTuple();
}
};
}
}
use of mondrian.calc.impl.AbstractMemberCalc in project mondrian by pentaho.
the class ParallelPeriodFunDef method compileCall.
public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
// Member defaults to [Time].currentmember
Exp[] args = call.getArgs();
// Numeric Expression defaults to 1.
final IntegerCalc lagValueCalc = (args.length >= 2) ? compiler.compileInteger(args[1]) : ConstantCalc.constantInteger(1);
// If level is not specified, we compute it from
// member at runtime.
final LevelCalc ancestorLevelCalc = args.length >= 1 ? compiler.compileLevel(args[0]) : null;
final MemberCalc memberCalc;
switch(args.length) {
case 3:
memberCalc = compiler.compileMember(args[2]);
break;
case 1:
final Hierarchy hierarchy = args[0].getType().getHierarchy();
if (hierarchy != null) {
// For some functions, such as Levels(<string expression>),
// the dimension cannot be determined at compile time.
memberCalc = new HierarchyCurrentMemberFunDef.FixedCalcImpl(call, hierarchy);
} else {
memberCalc = null;
}
break;
default:
final RolapHierarchy timeHierarchy = ((RolapCube) compiler.getEvaluator().getCube()).getTimeHierarchy(getName());
memberCalc = new HierarchyCurrentMemberFunDef.FixedCalcImpl(call, timeHierarchy);
break;
}
return new AbstractMemberCalc(call, new Calc[] { memberCalc, lagValueCalc, ancestorLevelCalc }) {
public Member evaluateMember(Evaluator evaluator) {
Member member;
int lagValue = lagValueCalc.evaluateInteger(evaluator);
Level ancestorLevel;
if (ancestorLevelCalc != null) {
ancestorLevel = ancestorLevelCalc.evaluateLevel(evaluator);
if (memberCalc == null) {
member = evaluator.getContext(ancestorLevel.getHierarchy());
} else {
member = memberCalc.evaluateMember(evaluator);
}
} else {
member = memberCalc.evaluateMember(evaluator);
Member parent = member.getParentMember();
if (parent == null) {
// so there is no parallelperiod.
return member.getHierarchy().getNullMember();
}
ancestorLevel = parent.getLevel();
}
return parallelPeriod(member, ancestorLevel, evaluator, lagValue);
}
};
}
Aggregations