Search in sources :

Example 1 with LevelType

use of mondrian.olap.type.LevelType in project mondrian by pentaho.

the class AbstractExpCompiler method compileHierarchy.

public HierarchyCalc compileHierarchy(Exp exp) {
    final Type type = exp.getType();
    if (type instanceof DimensionType) {
        // <Dimension> --> unique Hierarchy else error
        // Resolve at compile time if constant
        final Dimension dimension = type.getDimension();
        if (dimension != null) {
            final Hierarchy hierarchy = FunUtil.getDimensionDefaultHierarchy(dimension);
            if (hierarchy != null) {
                return (HierarchyCalc) ConstantCalc.constantHierarchy(hierarchy);
            } else {
                // cell) but we prefer to give an error at validate time.
                throw MondrianResource.instance().CannotImplicitlyConvertDimensionToHierarchy.ex(dimension.getName());
            }
        }
        final DimensionCalc dimensionCalc = compileDimension(exp);
        return new DimensionHierarchyCalc(new DummyExp(HierarchyType.forType(type)), dimensionCalc);
    }
    if (type instanceof MemberType) {
        // <Member> --> <Member>.Hierarchy
        final MemberCalc memberCalc = compileMember(exp);
        return new MemberHierarchyFunDef.CalcImpl(new DummyExp(HierarchyType.forType(type)), memberCalc);
    }
    if (type instanceof LevelType) {
        // <Level> --> <Level>.Hierarchy
        final LevelCalc levelCalc = compileLevel(exp);
        return new LevelHierarchyFunDef.CalcImpl(new DummyExp(HierarchyType.forType(type)), levelCalc);
    }
    assert type instanceof HierarchyType;
    return (HierarchyCalc) compile(exp);
}
Also used : DimensionType(mondrian.olap.type.DimensionType) LevelType(mondrian.olap.type.LevelType) LevelType(mondrian.olap.type.LevelType) DimensionType(mondrian.olap.type.DimensionType)

Example 2 with LevelType

use of mondrian.olap.type.LevelType in project mondrian by pentaho.

the class AncestorFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final MemberCalc memberCalc = compiler.compileMember(call.getArg(0));
    final Type type1 = call.getArg(1).getType();
    if (type1 instanceof LevelType) {
        final LevelCalc levelCalc = compiler.compileLevel(call.getArg(1));
        return new AbstractMemberCalc(call, new Calc[] { memberCalc, levelCalc }) {

            public Member evaluateMember(Evaluator evaluator) {
                Level level = levelCalc.evaluateLevel(evaluator);
                Member member = memberCalc.evaluateMember(evaluator);
                int distance = member.getLevel().getDepth() - level.getDepth();
                return ancestor(evaluator, member, distance, level);
            }
        };
    } else {
        final IntegerCalc distanceCalc = compiler.compileInteger(call.getArg(1));
        return new AbstractMemberCalc(call, new Calc[] { memberCalc, distanceCalc }) {

            public Member evaluateMember(Evaluator evaluator) {
                int distance = distanceCalc.evaluateInteger(evaluator);
                Member member = memberCalc.evaluateMember(evaluator);
                return ancestor(evaluator, member, distance, null);
            }
        };
    }
}
Also used : Type(mondrian.olap.type.Type) LevelType(mondrian.olap.type.LevelType) LevelType(mondrian.olap.type.LevelType) AbstractMemberCalc(mondrian.calc.impl.AbstractMemberCalc) AbstractMemberCalc(mondrian.calc.impl.AbstractMemberCalc)

Example 3 with LevelType

use of mondrian.olap.type.LevelType in project mondrian by pentaho.

the class AncestorsFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final MemberCalc memberCalc = compiler.compileMember(call.getArg(0));
    final Type type1 = call.getArg(1).getType();
    if (type1 instanceof LevelType) {
        final LevelCalc levelCalc = compiler.compileLevel(call.getArg(1));
        return new AbstractListCalc(call, new Calc[] { memberCalc, levelCalc }) {

            public TupleList evaluateList(Evaluator evaluator) {
                Level level = levelCalc.evaluateLevel(evaluator);
                Member member = memberCalc.evaluateMember(evaluator);
                int distance = member.getDepth() - level.getDepth();
                List<Member> ancestors = new ArrayList<Member>();
                for (int curDist = 1; curDist <= distance; curDist++) {
                    ancestors.add(ancestor(evaluator, member, curDist, null));
                }
                return TupleCollections.asTupleList(ancestors);
            }
        };
    } else {
        final IntegerCalc distanceCalc = compiler.compileInteger(call.getArg(1));
        return new AbstractListCalc(call, new Calc[] { memberCalc, distanceCalc }) {

            public TupleList evaluateList(Evaluator evaluator) {
                Member member = memberCalc.evaluateMember(evaluator);
                int distance = distanceCalc.evaluateInteger(evaluator);
                List<Member> ancestors = new ArrayList<Member>();
                for (int curDist = 1; curDist <= distance; curDist++) {
                    ancestors.add(ancestor(evaluator, member, curDist, null));
                }
                return TupleCollections.asTupleList(ancestors);
            }
        };
    }
}
Also used : Type(mondrian.olap.type.Type) LevelType(mondrian.olap.type.LevelType) LevelType(mondrian.olap.type.LevelType) ArrayList(java.util.ArrayList) AbstractListCalc(mondrian.calc.impl.AbstractListCalc)

Aggregations

LevelType (mondrian.olap.type.LevelType)3 Type (mondrian.olap.type.Type)2 ArrayList (java.util.ArrayList)1 AbstractListCalc (mondrian.calc.impl.AbstractListCalc)1 AbstractMemberCalc (mondrian.calc.impl.AbstractMemberCalc)1 DimensionType (mondrian.olap.type.DimensionType)1