use of mondrian.rolap.RolapCube in project mondrian by pentaho.
the class LastPeriodsFunDef method getResultType.
public Type getResultType(Validator validator, Exp[] args) {
if (args.length == 1) {
// If Member is not specified,
// it is Time.CurrentMember.
RolapHierarchy defaultTimeHierarchy = ((RolapCube) validator.getQuery().getCube()).getTimeHierarchy(getName());
return new SetType(MemberType.forHierarchy(defaultTimeHierarchy));
} else {
Type type = args[1].getType();
Type memberType = TypeUtil.toMemberOrTupleType(type);
return new SetType(memberType);
}
}
use of mondrian.rolap.RolapCube 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);
}
};
}
use of mondrian.rolap.RolapCube in project mondrian by pentaho.
the class PeriodsToDateFunDef method getResultType.
public Type getResultType(Validator validator, Exp[] args) {
if (args.length == 0) {
// With no args, the default implementation cannot
// guess the hierarchy.
RolapHierarchy defaultTimeHierarchy = ((RolapCube) validator.getQuery().getCube()).getTimeHierarchy(getName());
return new SetType(MemberType.forHierarchy(defaultTimeHierarchy));
}
if (args.length >= 2) {
Type hierarchyType = args[0].getType();
MemberType memberType = (MemberType) args[1].getType();
if (memberType.getHierarchy() != null && hierarchyType.getHierarchy() != null && memberType.getHierarchy() != hierarchyType.getHierarchy()) {
throw Util.newError("Type mismatch: member must belong to hierarchy " + hierarchyType.getHierarchy().getUniqueName());
}
}
// tell us the type.
return super.getResultType(validator, args);
}
Aggregations