Search in sources :

Example 21 with AbstractListCalc

use of mondrian.calc.impl.AbstractListCalc 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

AbstractListCalc (mondrian.calc.impl.AbstractListCalc)21 Evaluator (mondrian.olap.Evaluator)9 TupleList (mondrian.calc.TupleList)7 UnaryTupleList (mondrian.calc.impl.UnaryTupleList)7 Hierarchy (mondrian.olap.Hierarchy)6 Member (mondrian.olap.Member)6 ArrayList (java.util.ArrayList)5 ListCalc (mondrian.calc.ListCalc)5 List (java.util.List)4 Calc (mondrian.calc.Calc)4 IntegerCalc (mondrian.calc.IntegerCalc)4 SchemaReader (mondrian.olap.SchemaReader)4 Type (mondrian.olap.type.Type)4 LevelCalc (mondrian.calc.LevelCalc)3 Level (mondrian.olap.Level)3 MemberCalc (mondrian.calc.MemberCalc)2 StringCalc (mondrian.calc.StringCalc)2 ValueCalc (mondrian.calc.impl.ValueCalc)2 ResolvedFunCall (mondrian.mdx.ResolvedFunCall)2 Exp (mondrian.olap.Exp)2