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);
}
}
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;
}
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));
}
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);
}
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());
}
Aggregations