Search in sources :

Example 1 with AbstractIntegerCalc

use of mondrian.calc.impl.AbstractIntegerCalc in project mondrian by pentaho.

the class CountFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final Calc calc = compiler.compileAs(call.getArg(0), null, ResultStyle.ITERABLE_ANY);
    final boolean includeEmpty = call.getArgCount() < 2 || ((Literal) call.getArg(1)).getValue().equals("INCLUDEEMPTY");
    return new AbstractIntegerCalc(call, new Calc[] { calc }) {

        public int evaluateInteger(Evaluator evaluator) {
            final int savepoint = evaluator.savepoint();
            try {
                evaluator.setNonEmpty(false);
                final int count;
                if (calc instanceof IterCalc) {
                    IterCalc iterCalc = (IterCalc) calc;
                    TupleIterable iterable = evaluateCurrentIterable(iterCalc, evaluator);
                    count = count(evaluator, iterable, includeEmpty);
                } else {
                    // must be ListCalc
                    ListCalc listCalc = (ListCalc) calc;
                    TupleList list = evaluateCurrentList(listCalc, evaluator);
                    count = count(evaluator, list, includeEmpty);
                }
                return count;
            } finally {
                evaluator.restore(savepoint);
            }
        }

        public boolean dependsOn(Hierarchy hierarchy) {
            // on.
            if (super.dependsOn(hierarchy)) {
                return true;
            }
            if (includeEmpty) {
                return false;
            }
            // dimensions not masked by the set.
            return !calc.getType().usesHierarchy(hierarchy, true);
        }
    };
/*
 RME OLD STUFF
        final ListCalc memberListCalc =
                compiler.compileList(call.getArg(0));
        final boolean includeEmpty =
                call.getArgCount() < 2 ||
                ((Literal) call.getArg(1)).getValue().equals(
                        "INCLUDEEMPTY");
        return new AbstractIntegerCalc(
                call, new Calc[] {memberListCalc}) {
            public int evaluateInteger(Evaluator evaluator) {
                List memberList =
                    evaluateCurrentList(memberListCalc, evaluator);
                return count(evaluator, memberList, includeEmpty);
            }

            public boolean dependsOn(Dimension dimension) {
                // COUNT(<set>, INCLUDEEMPTY) is straightforward -- it
                // depends only on the dimensions that <Set> depends
                // on.
                if (super.dependsOn(dimension)) {
                    return true;
                }
                if (includeEmpty) {
                    return false;
                }
                // COUNT(<set>, EXCLUDEEMPTY) depends only on the
                // dimensions that <Set> depends on, plus all
                // dimensions not masked by the set.
                if (memberListCalc.getType().usesDimension(dimension, true)) {
                    return false;
                }
                return true;
            }
        };
*/
}
Also used : AbstractIntegerCalc(mondrian.calc.impl.AbstractIntegerCalc) AbstractIntegerCalc(mondrian.calc.impl.AbstractIntegerCalc)

Example 2 with AbstractIntegerCalc

use of mondrian.calc.impl.AbstractIntegerCalc in project mondrian by pentaho.

the class NamedSetCurrentOrdinalFunDef 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;
    return new AbstractIntegerCalc(call, new Calc[0]) {

        public int evaluateInteger(Evaluator evaluator) {
            return namedSetExpr.getEval(evaluator).currentOrdinal();
        }
    };
}
Also used : NamedSetExpr(mondrian.mdx.NamedSetExpr) AbstractIntegerCalc(mondrian.calc.impl.AbstractIntegerCalc)

Aggregations

AbstractIntegerCalc (mondrian.calc.impl.AbstractIntegerCalc)2 NamedSetExpr (mondrian.mdx.NamedSetExpr)1