Search in sources :

Example 1 with RolapHierarchy

use of mondrian.rolap.RolapHierarchy in project mondrian by pentaho.

the class DimensionsNumericFunDef method nthHierarchy.

RolapHierarchy nthHierarchy(Evaluator evaluator, int n) {
    RolapCube cube = (RolapCube) evaluator.getCube();
    List<RolapHierarchy> hierarchies = cube.getHierarchies();
    if (n >= hierarchies.size() || n < 0) {
        throw newEvalException(this, "Index '" + n + "' out of bounds");
    }
    return hierarchies.get(n);
}
Also used : RolapCube(mondrian.rolap.RolapCube) RolapHierarchy(mondrian.rolap.RolapHierarchy)

Example 2 with RolapHierarchy

use of mondrian.rolap.RolapHierarchy in project mondrian by pentaho.

the class LastPeriodsFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    // Member defaults to [Time].currentmember
    Exp[] args = call.getArgs();
    final MemberCalc memberCalc;
    if (args.length == 1) {
        final RolapHierarchy timeHierarchy = ((RolapCube) compiler.getEvaluator().getCube()).getTimeHierarchy(getName());
        memberCalc = new HierarchyCurrentMemberFunDef.FixedCalcImpl(call, timeHierarchy);
    } else {
        memberCalc = compiler.compileMember(args[1]);
    }
    // Numeric Expression.
    final IntegerCalc indexValueCalc = compiler.compileInteger(args[0]);
    return new AbstractListCalc(call, new Calc[] { memberCalc, indexValueCalc }) {

        public TupleList evaluateList(Evaluator evaluator) {
            Member member = memberCalc.evaluateMember(evaluator);
            int indexValue = indexValueCalc.evaluateInteger(evaluator);
            return new UnaryTupleList(lastPeriods(member, evaluator, indexValue));
        }
    };
}
Also used : AbstractListCalc(mondrian.calc.impl.AbstractListCalc) RolapCube(mondrian.rolap.RolapCube) RolapHierarchy(mondrian.rolap.RolapHierarchy) UnaryTupleList(mondrian.calc.impl.UnaryTupleList)

Example 3 with RolapHierarchy

use of mondrian.rolap.RolapHierarchy in project mondrian by pentaho.

the class OpeningClosingPeriodFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final Exp[] args = call.getArgs();
    final LevelCalc levelCalc;
    final MemberCalc memberCalc;
    RolapHierarchy defaultTimeHierarchy = null;
    switch(args.length) {
        case 0:
            defaultTimeHierarchy = ((RolapCube) compiler.getEvaluator().getCube()).getTimeHierarchy(getName());
            memberCalc = new HierarchyCurrentMemberFunDef.FixedCalcImpl(new DummyExp(MemberType.forHierarchy(defaultTimeHierarchy)), defaultTimeHierarchy);
            levelCalc = null;
            break;
        case 1:
            defaultTimeHierarchy = ((RolapCube) compiler.getEvaluator().getCube()).getTimeHierarchy(getName());
            levelCalc = compiler.compileLevel(call.getArg(0));
            memberCalc = new HierarchyCurrentMemberFunDef.FixedCalcImpl(new DummyExp(MemberType.forHierarchy(defaultTimeHierarchy)), defaultTimeHierarchy);
            break;
        default:
            levelCalc = compiler.compileLevel(call.getArg(0));
            memberCalc = compiler.compileMember(call.getArg(1));
            break;
    }
    // Make sure the member and the level come from the same dimension.
    if (levelCalc != null) {
        final Dimension memberDimension = memberCalc.getType().getDimension();
        final Dimension levelDimension = levelCalc.getType().getDimension();
        if (!memberDimension.equals(levelDimension)) {
            throw MondrianResource.instance().FunctionMbrAndLevelHierarchyMismatch.ex(opening ? "OpeningPeriod" : "ClosingPeriod", levelDimension.getUniqueName(), memberDimension.getUniqueName());
        }
    }
    return new AbstractMemberCalc(call, new Calc[] { levelCalc, memberCalc }) {

        public Member evaluateMember(Evaluator evaluator) {
            Member member = memberCalc.evaluateMember(evaluator);
            // If the level argument is present, use it. Otherwise use the
            // level immediately after that of the member argument.
            Level level;
            if (levelCalc == null) {
                int targetDepth = member.getLevel().getDepth() + 1;
                Level[] levels = member.getHierarchy().getLevels();
                if (levels.length <= targetDepth) {
                    return member.getHierarchy().getNullMember();
                }
                level = levels[targetDepth];
            } else {
                level = levelCalc.evaluateLevel(evaluator);
            }
            // Shortcut if the level is above the member.
            if (level.getDepth() < member.getLevel().getDepth()) {
                return member.getHierarchy().getNullMember();
            }
            // Shortcut if the level is the same as the member
            if (level == member.getLevel()) {
                return member;
            }
            return getDescendant(evaluator.getSchemaReader(), member, level, opening);
        }
    };
}
Also used : AbstractMemberCalc(mondrian.calc.impl.AbstractMemberCalc) RolapHierarchy(mondrian.rolap.RolapHierarchy) AbstractMemberCalc(mondrian.calc.impl.AbstractMemberCalc)

Example 4 with RolapHierarchy

use of mondrian.rolap.RolapHierarchy in project mondrian by pentaho.

the class PeriodsToDateFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final LevelCalc levelCalc = call.getArgCount() > 0 ? compiler.compileLevel(call.getArg(0)) : null;
    final MemberCalc memberCalc = call.getArgCount() > 1 ? compiler.compileMember(call.getArg(1)) : null;
    final RolapHierarchy timeHierarchy = levelCalc == null ? ((RolapCube) compiler.getEvaluator().getCube()).getTimeHierarchy(getName()) : null;
    return new AbstractListCalc(call, new Calc[] { levelCalc, memberCalc }) {

        public TupleList evaluateList(Evaluator evaluator) {
            final Member member;
            final Level level;
            if (levelCalc == null) {
                member = evaluator.getContext(timeHierarchy);
                level = member.getLevel().getParentLevel();
            } else {
                level = levelCalc.evaluateLevel(evaluator);
                if (memberCalc == null) {
                    member = evaluator.getContext(level.getHierarchy());
                } else {
                    member = memberCalc.evaluateMember(evaluator);
                }
            }
            return new UnaryTupleList(periodsToDate(evaluator, level, member));
        }

        public boolean dependsOn(Hierarchy hierarchy) {
            if (super.dependsOn(hierarchy)) {
                return true;
            }
            if (memberCalc != null) {
                return false;
            } else if (levelCalc != null) {
                return levelCalc.getType().usesHierarchy(hierarchy, true);
            } else {
                return hierarchy == timeHierarchy;
            }
        }
    };
}
Also used : RolapHierarchy(mondrian.rolap.RolapHierarchy) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) AbstractListCalc(mondrian.calc.impl.AbstractListCalc) RolapHierarchy(mondrian.rolap.RolapHierarchy)

Example 5 with RolapHierarchy

use of mondrian.rolap.RolapHierarchy in project mondrian by pentaho.

the class AbstractCalc method simplifyEvaluator.

/**
 * Returns a simplified evalator whose context is the same for every
 * dimension which an expression depends on, and the default member for
 * every dimension which it does not depend on.
 *
 * <p>The default member is often the 'all' member, so this evaluator is
 * usually the most efficient context in which to evaluate the expression.
 *
 * @param calc
 * @param evaluator
 */
public static Evaluator simplifyEvaluator(Calc calc, Evaluator evaluator) {
    if (evaluator.isNonEmpty()) {
        // 'NonEmptyCrossJoin'.
        return evaluator;
    }
    int changeCount = 0;
    Evaluator ev = evaluator;
    final List<RolapHierarchy> hierarchies = ((RolapEvaluator) evaluator).getCube().getHierarchies();
    for (RolapHierarchy hierarchy : hierarchies) {
        final Member member = ev.getContext(hierarchy);
        if (member.isAll()) {
            continue;
        }
        if (calc.dependsOn(hierarchy)) {
            continue;
        }
        final Member unconstrainedMember = member.getHierarchy().getDefaultMember();
        if (member == unconstrainedMember) {
            // is already the default member.
            continue;
        }
        if (changeCount++ == 0) {
            ev = evaluator.push();
        }
        ev.setContext(unconstrainedMember);
    }
    return ev;
}
Also used : RolapEvaluator(mondrian.rolap.RolapEvaluator) RolapHierarchy(mondrian.rolap.RolapHierarchy)

Aggregations

RolapHierarchy (mondrian.rolap.RolapHierarchy)8 RolapCube (mondrian.rolap.RolapCube)5 AbstractListCalc (mondrian.calc.impl.AbstractListCalc)2 AbstractMemberCalc (mondrian.calc.impl.AbstractMemberCalc)2 UnaryTupleList (mondrian.calc.impl.UnaryTupleList)2 RolapEvaluator (mondrian.rolap.RolapEvaluator)1