Search in sources :

Example 1 with TupleEvent

use of mondrian.rolap.RolapNative.TupleEvent 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)

Aggregations

Connection (mondrian.olap.Connection)1 Evaluator (mondrian.olap.Evaluator)1 Result (mondrian.olap.Result)1 NonEmptyResult (mondrian.rolap.RolapConnection.NonEmptyResult)1 Listener (mondrian.rolap.RolapNative.Listener)1 NativeEvent (mondrian.rolap.RolapNative.NativeEvent)1 TupleEvent (mondrian.rolap.RolapNative.TupleEvent)1 MemberChildrenConstraint (mondrian.rolap.sql.MemberChildrenConstraint)1