Search in sources :

Example 6 with AbstractMemberCalc

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();
            }
        };
    }
}
Also used : AbstractTupleCalc(mondrian.calc.impl.AbstractTupleCalc) NamedSetExpr(mondrian.mdx.NamedSetExpr) AbstractMemberCalc(mondrian.calc.impl.AbstractMemberCalc)

Example 7 with AbstractMemberCalc

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);
        }
    };
}
Also used : AbstractMemberCalc(mondrian.calc.impl.AbstractMemberCalc) RolapCube(mondrian.rolap.RolapCube) RolapHierarchy(mondrian.rolap.RolapHierarchy) RolapHierarchy(mondrian.rolap.RolapHierarchy) AbstractMemberCalc(mondrian.calc.impl.AbstractMemberCalc)

Aggregations

AbstractMemberCalc (mondrian.calc.impl.AbstractMemberCalc)7 RolapHierarchy (mondrian.rolap.RolapHierarchy)2 AbstractTupleCalc (mondrian.calc.impl.AbstractTupleCalc)1 NamedSetExpr (mondrian.mdx.NamedSetExpr)1 LevelType (mondrian.olap.type.LevelType)1 Type (mondrian.olap.type.Type)1 RolapCube (mondrian.rolap.RolapCube)1