Search in sources :

Example 11 with RolapCube

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

Example 12 with RolapCube

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

Example 13 with RolapCube

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

Aggregations

RolapCube (mondrian.rolap.RolapCube)13 RolapHierarchy (mondrian.rolap.RolapHierarchy)5 UnaryTupleList (mondrian.calc.impl.UnaryTupleList)2 AbstractListCalc (mondrian.calc.impl.AbstractListCalc)1 AbstractMemberCalc (mondrian.calc.impl.AbstractMemberCalc)1 ArrayTupleList (mondrian.calc.impl.ArrayTupleList)1 Result (mondrian.olap.Result)1 RolapConnection (mondrian.rolap.RolapConnection)1 RolapCubeDimension (mondrian.rolap.RolapCubeDimension)1 RolapSchema (mondrian.rolap.RolapSchema)1 Execution (mondrian.server.Execution)1 Dialect (mondrian.spi.Dialect)1 CellSet (org.olap4j.CellSet)1