Search in sources :

Example 11 with Evaluator

use of mondrian.olap.Evaluator in project mondrian by pentaho.

the class NonEmptyTest method testNonEmptyDescendants.

/**
 * Ensures that NON EMPTY Descendants is optimized.
 * Ensures that Descendants as a side effect collects MemberChildren that
 * may be looked up in the cache.
 */
public void testNonEmptyDescendants() {
    // 'level.getMembers()' which create false negatives in this test.
    if (MondrianProperties.instance().TestExpDependencies.get() > 0) {
        return;
    }
    Connection con = getTestContext().withSchemaPool(false).getConnection();
    SmartMemberReader smr = getSmartMemberReader(con, "Customers");
    MemberCacheHelper smrch = smr.cacheHelper;
    clearAndHardenCache(smrch);
    SmartMemberReader ssmr = getSmartMemberReader(con, "Customers");
    MemberCacheHelper ssmrch = ssmr.cacheHelper;
    clearAndHardenCache(ssmrch);
    TestCase c = new TestCase(con, 45, 21, "select \n" + "{[Measures].[Unit Sales]} ON columns, " + "NON EMPTY {[Customers].[All Customers], Descendants([Customers].[All Customers].[USA].[CA], [Customers].[Name])} on rows " + "from [Sales] " + "where ([Store].[All Stores].[USA].[CA].[San Francisco].[Store 14], [Time].[1997].[Q1].[1])");
    Result result = c.run();
    // [Customers].[All Customers].[USA].[CA].[Burlingame].[Peggy Justice]
    RolapMember peggy = (RolapMember) result.getAxes()[1].getPositions().get(1).get(0);
    RolapMember burlingame = peggy.getParentMember();
    peggy = ((RolapCubeMember) peggy).getRolapMember();
    burlingame = ((RolapCubeMember) burlingame).getRolapMember();
    // all children of burlingame are not in cache
    MemberChildrenConstraint mcc = scf.getMemberChildrenConstraint(null);
    assertNull(ssmrch.mapMemberToChildren.get(burlingame, mcc));
    // but non empty children is
    Evaluator evaluator = getEvaluator(result, new int[] { 0, 0 });
    evaluator.setNonEmpty(true);
    mcc = scf.getMemberChildrenConstraint(evaluator);
    List<RolapMember> list = ssmrch.mapMemberToChildren.get(burlingame, mcc);
    assertNotNull(list);
    assertTrue(list.contains(peggy));
    // now we run the same query again, this time everything must come out
    // of the cache
    RolapNativeRegistry reg = getRegistry(con);
    reg.setListener(new Listener() {

        public void foundEvaluator(NativeEvent e) {
        }

        public void foundInCache(TupleEvent e) {
        }

        public void executingSql(TupleEvent e) {
            fail("expected caching");
        }
    });
    try {
        c.run();
    } finally {
        reg.setListener(null);
    }
}
Also used : Listener(mondrian.rolap.RolapNative.Listener) Connection(mondrian.olap.Connection) Evaluator(mondrian.olap.Evaluator) NonEmptyResult(mondrian.rolap.RolapConnection.NonEmptyResult) Result(mondrian.olap.Result) MemberChildrenConstraint(mondrian.rolap.sql.MemberChildrenConstraint) TupleEvent(mondrian.rolap.RolapNative.TupleEvent) NativeEvent(mondrian.rolap.RolapNative.NativeEvent)

Example 12 with Evaluator

use of mondrian.olap.Evaluator in project mondrian by pentaho.

the class ExistingFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final IterCalc setArg = compiler.compileIter(call.getArg(0));
    final Type myType = call.getArg(0).getType();
    return new AbstractListCalc(call, new Calc[] { setArg }) {

        public boolean dependsOn(Hierarchy hierarchy) {
            return myType.usesHierarchy(hierarchy, false);
        }

        public TupleList evaluateList(Evaluator evaluator) {
            TupleIterable setTuples = setArg.evaluateIterable(evaluator);
            TupleList result = TupleCollections.createList(setTuples.getArity());
            List<Member> contextMembers = Arrays.asList(evaluator.getMembers());
            List<Hierarchy> argDims = null;
            List<Hierarchy> contextDims = getHierarchies(contextMembers);
            for (List<Member> tuple : setTuples) {
                if (argDims == null) {
                    argDims = getHierarchies(tuple);
                }
                if (existsInTuple(tuple, contextMembers, argDims, contextDims, evaluator)) {
                    result.add(tuple);
                }
            }
            return result;
        }
    };
}
Also used : TupleList(mondrian.calc.TupleList) Hierarchy(mondrian.olap.Hierarchy) Type(mondrian.olap.type.Type) TupleIterable(mondrian.calc.TupleIterable) IterCalc(mondrian.calc.IterCalc) AbstractListCalc(mondrian.calc.impl.AbstractListCalc) Evaluator(mondrian.olap.Evaluator) Member(mondrian.olap.Member)

Example 13 with Evaluator

use of mondrian.olap.Evaluator in project mondrian by pentaho.

the class HeadTailFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final ListCalc listCalc = compiler.compileList(call.getArg(0));
    final IntegerCalc integerCalc = call.getArgCount() > 1 ? compiler.compileInteger(call.getArg(1)) : ConstantCalc.constantInteger(1);
    if (head) {
        return new AbstractListCalc(call, new Calc[] { listCalc, integerCalc }) {

            public TupleList evaluateList(Evaluator evaluator) {
                final int savepoint = evaluator.savepoint();
                try {
                    evaluator.setNonEmpty(false);
                    TupleList list = listCalc.evaluateList(evaluator);
                    int count = integerCalc.evaluateInteger(evaluator);
                    return head(count, list);
                } finally {
                    evaluator.restore(savepoint);
                }
            }
        };
    } else {
        return new AbstractListCalc(call, new Calc[] { listCalc, integerCalc }) {

            public TupleList evaluateList(Evaluator evaluator) {
                final int savepoint = evaluator.savepoint();
                try {
                    evaluator.setNonEmpty(false);
                    TupleList list = listCalc.evaluateList(evaluator);
                    int count = integerCalc.evaluateInteger(evaluator);
                    return tail(count, list);
                } finally {
                    evaluator.restore(savepoint);
                }
            }
        };
    }
}
Also used : AbstractListCalc(mondrian.calc.impl.AbstractListCalc) AbstractListCalc(mondrian.calc.impl.AbstractListCalc) Evaluator(mondrian.olap.Evaluator)

Example 14 with Evaluator

use of mondrian.olap.Evaluator in project mondrian by pentaho.

the class HierarchizeFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final ListCalc listCalc = compiler.compileList(call.getArg(0), true);
    String order = getLiteralArg(call, 1, "PRE", prePost);
    final boolean post = order.equals("POST");
    return new AbstractListCalc(call, new Calc[] { listCalc }) {

        public TupleList evaluateList(Evaluator evaluator) {
            TupleList list = listCalc.evaluateList(evaluator);
            return hierarchizeTupleList(list, post);
        }
    };
}
Also used : AbstractListCalc(mondrian.calc.impl.AbstractListCalc) AbstractListCalc(mondrian.calc.impl.AbstractListCalc) Evaluator(mondrian.olap.Evaluator)

Example 15 with Evaluator

use of mondrian.olap.Evaluator in project mondrian by pentaho.

the class TupleToStrFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    if (TypeUtil.couldBeMember(call.getArg(0).getType())) {
        final MemberCalc memberCalc = compiler.compileMember(call.getArg(0));
        return new AbstractStringCalc(call, new Calc[] { memberCalc }) {

            public String evaluateString(Evaluator evaluator) {
                final Member member = memberCalc.evaluateMember(evaluator);
                if (member.isNull()) {
                    return "";
                }
                StringBuilder buf = new StringBuilder();
                buf.append(member.getUniqueName());
                return buf.toString();
            }
        };
    } else {
        final TupleCalc tupleCalc = compiler.compileTuple(call.getArg(0));
        return new AbstractStringCalc(call, new Calc[] { tupleCalc }) {

            public String evaluateString(Evaluator evaluator) {
                final Member[] members = tupleCalc.evaluateTuple(evaluator);
                if (members == null) {
                    return "";
                }
                StringBuilder buf = new StringBuilder();
                SetToStrFunDef.appendTuple(buf, members);
                return buf.toString();
            }
        };
    }
}
Also used : AbstractStringCalc(mondrian.calc.impl.AbstractStringCalc) Evaluator(mondrian.olap.Evaluator) Member(mondrian.olap.Member)

Aggregations

Evaluator (mondrian.olap.Evaluator)15 Member (mondrian.olap.Member)11 SetEvaluator (mondrian.olap.Evaluator.SetEvaluator)7 TestMember (mondrian.olap.fun.TestMember)7 AbstractListCalc (mondrian.calc.impl.AbstractListCalc)4 Result (mondrian.olap.Result)3 NonEmptyResult (mondrian.rolap.RolapConnection.NonEmptyResult)3 MemberChildrenConstraint (mondrian.rolap.sql.MemberChildrenConstraint)3 TupleIterable (mondrian.calc.TupleIterable)2 TupleList (mondrian.calc.TupleList)2 Level (mondrian.olap.Level)2 TupleConstraint (mondrian.rolap.sql.TupleConstraint)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 IterCalc (mondrian.calc.IterCalc)1 AbstractStringCalc (mondrian.calc.impl.AbstractStringCalc)1 AbstractTupleCursor (mondrian.calc.impl.AbstractTupleCursor)1 UnaryTupleList (mondrian.calc.impl.UnaryTupleList)1 ResolvedFunCall (mondrian.mdx.ResolvedFunCall)1