Search in sources :

Example 1 with Level

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

the class MemberCacheHelper method flushCache.

// Must sync here because we want the three maps to be modified together.
public synchronized void flushCache() {
    mapMemberToChildren.clear();
    mapKeyToMember.clear();
    mapLevelToMembers.clear();
    mapParentToNamedChildren.clear();
    // We also need to clear the approxRowCount of each level.
    for (Level level : rolapHierarchy.getLevels()) {
        ((RolapLevel) level).setApproxRowCount(Integer.MIN_VALUE);
    }
}
Also used : Level(mondrian.olap.Level)

Example 2 with Level

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

the class SqlConstraintUtils method getRolesConstraints.

public static Map<RolapLevel, List<RolapMember>> getRolesConstraints(Evaluator evaluator) {
    Member[] mm = evaluator.getMembers();
    SchemaReader schemaReader = evaluator.getSchemaReader();
    Map<RolapLevel, List<RolapMember>> roleConstraints = new LinkedHashMap<RolapLevel, List<RolapMember>>(mm.length);
    for (Member member : mm) {
        boolean isRolesMember = (member instanceof LimitedRollupMember) || (member instanceof MultiCardinalityDefaultMember);
        if (isRolesMember) {
            List<Level> hierarchyLevels = schemaReader.getHierarchyLevels(member.getHierarchy());
            for (Level affectedLevel : hierarchyLevels) {
                List<Member> availableMembers = schemaReader.getLevelMembers(affectedLevel, false);
                List<RolapMember> slicerMembers = new ArrayList<RolapMember>(availableMembers.size());
                for (Member available : availableMembers) {
                    if (!available.isAll()) {
                        slicerMembers.add((RolapMember) available);
                    }
                }
                if (!slicerMembers.isEmpty()) {
                    roleConstraints.put((RolapLevel) affectedLevel, slicerMembers);
                }
            }
        }
    }
    return roleConstraints.isEmpty() ? Collections.<RolapLevel, List<RolapMember>>emptyMap() : roleConstraints;
}
Also used : SchemaReader(mondrian.olap.SchemaReader) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) LimitedRollupMember(mondrian.rolap.RolapHierarchy.LimitedRollupMember) MultiCardinalityDefaultMember(mondrian.rolap.RestrictedMemberReader.MultiCardinalityDefaultMember) List(java.util.List) FilteredIterableList(mondrian.util.FilteredIterableList) ArrayList(java.util.ArrayList) TupleList(mondrian.calc.TupleList) Level(mondrian.olap.Level) Member(mondrian.olap.Member) LimitedRollupMember(mondrian.rolap.RolapHierarchy.LimitedRollupMember) MultiCardinalityDefaultMember(mondrian.rolap.RestrictedMemberReader.MultiCardinalityDefaultMember)

Example 3 with Level

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

the class NonEmptyTest method testLevelMembers.

public void testLevelMembers() {
    if (MondrianProperties.instance().TestExpDependencies.get() > 0) {
        // test.
        return;
    }
    SmartMemberReader smr = getSmartMemberReader("Customers");
    // use the RolapCubeHierarchy's member cache for levels
    MemberCacheHelper smrch = ((RolapCubeHierarchy.CacheRolapCubeHierarchyMemberReader) smr).rolapCubeCacheHelper;
    clearAndHardenCache(smrch);
    MemberCacheHelper smrich = smr.cacheHelper;
    clearAndHardenCache(smrich);
    // use the shared member cache for mapMemberToChildren
    SmartMemberReader ssmr = getSharedSmartMemberReader("Customers");
    MemberCacheHelper ssmrch = ssmr.cacheHelper;
    clearAndHardenCache(ssmrch);
    TestCase c = new TestCase(50, 21, "select \n" + "{[Measures].[Unit Sales]} ON columns,\n" + "NON EMPTY {[Customers].[All Customers], [Customers].[Name].Members} ON rows\n" + "from [Sales]\n" + "where ([Store].[All Stores].[USA].[CA].[San Francisco].[Store 14], [Time].[1997].[Q1].[1])");
    Result r = c.run();
    Level[] levels = smr.getHierarchy().getLevels();
    Level nameLevel = levels[levels.length - 1];
    // evaluator for [All Customers], [Store 14], [1/1/1997]
    Evaluator context = getEvaluator(r, new int[] { 0, 0 });
    // make sure that [Customers].[Name].Members is NOT in cache
    TupleConstraint lmc = scf.getLevelMembersConstraint(null);
    assertNull(smrch.mapLevelToMembers.get((RolapLevel) nameLevel, lmc));
    // make sure that NON EMPTY [Customers].[Name].Members IS in cache
    context.setNonEmpty(true);
    lmc = scf.getLevelMembersConstraint(context);
    List<RolapMember> list = smrch.mapLevelToMembers.get((RolapLevel) nameLevel, lmc);
    if (MondrianProperties.instance().EnableRolapCubeMemberCache.get()) {
        assertNotNull(list);
        assertEquals(20, list.size());
    }
    // make sure that the parent/child for the context are cached
    // [Customers].[USA].[CA].[Burlingame].[Peggy Justice]
    Member member = r.getAxes()[1].getPositions().get(1).get(0);
    Member parent = member.getParentMember();
    parent = ((RolapCubeMember) parent).getRolapMember();
    member = ((RolapCubeMember) member).getRolapMember();
    // lookup all children of [Burlingame] -> not in cache
    MemberChildrenConstraint mcc = scf.getMemberChildrenConstraint(null);
    assertNull(ssmrch.mapMemberToChildren.get((RolapMember) parent, mcc));
    // lookup NON EMPTY children of [Burlingame] -> yes these are in cache
    mcc = scf.getMemberChildrenConstraint(context);
    list = smrich.mapMemberToChildren.get((RolapMember) parent, mcc);
    assertNotNull(list);
    assertTrue(list.contains(member));
}
Also used : Evaluator(mondrian.olap.Evaluator) NonEmptyResult(mondrian.rolap.RolapConnection.NonEmptyResult) Result(mondrian.olap.Result) TupleConstraint(mondrian.rolap.sql.TupleConstraint) MemberChildrenConstraint(mondrian.rolap.sql.MemberChildrenConstraint) Level(mondrian.olap.Level) Member(mondrian.olap.Member)

Example 4 with Level

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

the class NonEmptyTest method testLevelMembersWithoutNonEmpty.

public void testLevelMembersWithoutNonEmpty() {
    SmartMemberReader smr = getSmartMemberReader("Customers");
    MemberCacheHelper smrch = ((RolapCubeHierarchy.CacheRolapCubeHierarchyMemberReader) smr).rolapCubeCacheHelper;
    clearAndHardenCache(smrch);
    MemberCacheHelper smrich = smr.cacheHelper;
    clearAndHardenCache(smrich);
    SmartMemberReader ssmr = getSharedSmartMemberReader("Customers");
    MemberCacheHelper ssmrch = ssmr.cacheHelper;
    clearAndHardenCache(ssmrch);
    Result r = executeQuery("select \n" + "{[Measures].[Unit Sales]} ON columns,\n" + "{[Customers].[All Customers], [Customers].[Name].Members} ON rows\n" + "from [Sales]\n" + "where ([Store].[All Stores].[USA].[CA].[San Francisco].[Store 14], [Time].[1997].[Q1].[1])");
    Level[] levels = smr.getHierarchy().getLevels();
    Level nameLevel = levels[levels.length - 1];
    // evaluator for [All Customers], [Store 14], [1/1/1997]
    Evaluator context = getEvaluator(r, new int[] { 0, 0 });
    // make sure that [Customers].[Name].Members IS in cache
    TupleConstraint lmc = scf.getLevelMembersConstraint(null);
    List<RolapMember> list = smrch.mapLevelToMembers.get((RolapLevel) nameLevel, lmc);
    if (MondrianProperties.instance().EnableRolapCubeMemberCache.get()) {
        assertNotNull(list);
        assertEquals(10281, list.size());
    }
    // make sure that NON EMPTY [Customers].[Name].Members is NOT in cache
    context.setNonEmpty(true);
    lmc = scf.getLevelMembersConstraint(context);
    assertNull(smrch.mapLevelToMembers.get((RolapLevel) nameLevel, lmc));
    // make sure that the parent/child for the context are cached
    // [Customers].[Canada].[BC].[Burnaby]
    Member member = r.getAxes()[1].getPositions().get(1).get(0);
    Member parent = member.getParentMember();
    parent = ((RolapCubeMember) parent).getRolapMember();
    member = ((RolapCubeMember) member).getRolapMember();
    // lookup all children of [Burnaby] -> yes, found in cache
    MemberChildrenConstraint mcc = scf.getMemberChildrenConstraint(null);
    list = ssmrch.mapMemberToChildren.get((RolapMember) parent, mcc);
    assertNotNull(list);
    assertTrue(list.contains(member));
    // lookup NON EMPTY children of [Burlingame] -> not in cache
    mcc = scf.getMemberChildrenConstraint(context);
    list = ssmrch.mapMemberToChildren.get((RolapMember) parent, mcc);
    assertNull(list);
}
Also used : Evaluator(mondrian.olap.Evaluator) NonEmptyResult(mondrian.rolap.RolapConnection.NonEmptyResult) Result(mondrian.olap.Result) TupleConstraint(mondrian.rolap.sql.TupleConstraint) MemberChildrenConstraint(mondrian.rolap.sql.MemberChildrenConstraint) Level(mondrian.olap.Level) Member(mondrian.olap.Member)

Example 5 with Level

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

the class RestrictedMemberReaderTest method testGetHierarchy_allAccess.

public void testGetHierarchy_allAccess() {
    Schema schema = Mockito.mock(Schema.class);
    Dimension dimension = Mockito.mock(Dimension.class);
    RolapHierarchy hierarchy = Mockito.mock(RolapHierarchy.class);
    Level[] hierarchyAccessLevels = new Level[] { null };
    MemberReader delegateMemberReader = Mockito.mock(MemberReader.class);
    HierarchyAccess roleAccess = null;
    Role role = Mockito.mock(Role.class);
    Mockito.doReturn(schema).when(dimension).getSchema();
    Mockito.doReturn(dimension).when(hierarchy).getDimension();
    Mockito.doReturn(hierarchyAccessLevels).when(hierarchy).getLevels();
    Mockito.doReturn(true).when(hierarchy).isRagged();
    Mockito.doReturn(roleAccess).when(role).getAccessDetails(Mockito.any(Hierarchy.class));
    Mockito.doReturn(hierarchy).when(delegateMemberReader).getHierarchy();
    rmr = new RestrictedMemberReader(delegateMemberReader, role);
    Assert.assertSame(hierarchy, rmr.getHierarchy());
}
Also used : Role(mondrian.olap.Role) Hierarchy(mondrian.olap.Hierarchy) Schema(mondrian.olap.Schema) Level(mondrian.olap.Level) Dimension(mondrian.olap.Dimension) HierarchyAccess(mondrian.olap.Role.HierarchyAccess)

Aggregations

Level (mondrian.olap.Level)17 Hierarchy (mondrian.olap.Hierarchy)9 Member (mondrian.olap.Member)7 DataSource (javax.sql.DataSource)4 Dimension (mondrian.olap.Dimension)4 MondrianDef (mondrian.olap.MondrianDef)4 LinkedHashMap (java.util.LinkedHashMap)3 Role (mondrian.olap.Role)3 MultiCardinalityDefaultMember (mondrian.rolap.RestrictedMemberReader.MultiCardinalityDefaultMember)3 LimitedRollupMember (mondrian.rolap.RolapHierarchy.LimitedRollupMember)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 TupleList (mondrian.calc.TupleList)2 mondrian.olap (mondrian.olap)2 Evaluator (mondrian.olap.Evaluator)2 RelationOrJoin (mondrian.olap.MondrianDef.RelationOrJoin)2 Result (mondrian.olap.Result)2 HierarchyAccess (mondrian.olap.Role.HierarchyAccess)2 Schema (mondrian.olap.Schema)2