Search in sources :

Example 1 with TupleConstraint

use of mondrian.rolap.sql.TupleConstraint in project mondrian by pentaho.

the class SqlTupleReaderTest method testAddLevelMemberSql.

public void testAddLevelMemberSql() throws Exception {
    TupleConstraint constraint = mock(TupleConstraint.class);
    SqlQuery sqlQuery = mock(SqlQuery.class, Answers.RETURNS_MOCKS.get());
    RolapCube baseCube = mock(RolapCube.class);
    RolapLevel targetLevel = mock(RolapLevel.class);
    RolapCubeLevel levelIter = mock(RolapCubeLevel.class, Answers.RETURNS_MOCKS.get());
    RolapProperty rolapProperty = mock(RolapProperty.class, Answers.RETURNS_MOCKS.get());
    String propertyName = "property_1";
    when(rolapProperty.getName()).thenReturn(propertyName);
    RolapProperty[] properties = { rolapProperty };
    when(levelIter.getProperties()).thenReturn(properties);
    when(levelIter.getKeyExp()).thenReturn(mock(MondrianDef.Expression.class));
    when(levelIter.getOrdinalExp()).thenReturn(mock(MondrianDef.Expression.class));
    when(levelIter.getParentExp()).thenReturn(null);
    RolapHierarchy hierarchy = mock(RolapHierarchy.class, Answers.RETURNS_MOCKS.get());
    when(targetLevel.getHierarchy()).thenReturn(hierarchy);
    when(hierarchy.getLevels()).thenReturn(new RolapLevel[] { levelIter });
    SqlTupleReader.WhichSelect whichSelect = SqlTupleReader.WhichSelect.LAST;
    JdbcSchema.Table dbTable = mock(JdbcSchema.Table.class, Answers.RETURNS_MOCKS.get());
    when(dbTable.getColumnUsages(any())).thenReturn(mock(Iterator.class));
    RolapStar star = mock(RolapStar.class);
    when(star.getColumnCount()).thenReturn(1);
    AggStar aggStar = spy(AggStar.makeAggStar(star, dbTable, mock(MessageRecorder.class), 10));
    AggStar.Table.Column column = mock(AggStar.Table.Column.class, Answers.RETURNS_MOCKS.get());
    doReturn(column).when(aggStar).lookupColumn(0);
    RolapStar.Column starColumn = mock(RolapStar.Column.class, Answers.RETURNS_MOCKS.get());
    when(starColumn.getBitPosition()).thenReturn(0);
    doReturn(starColumn).when(levelIter).getStarKeyColumn();
    AggStar.FactTable factTable = (AggStar.FactTable) createInstance("mondrian.rolap.aggmatcher.AggStar$FactTable", new Class[] { mondrian.rolap.aggmatcher.AggStar.class, JdbcSchema.Table.class }, new Object[] { aggStar, dbTable }, AggStar.FactTable.class.getClassLoader());
    factTable = spy(factTable);
    Map<String, MondrianDef.Expression> propertiesAgg = new HashMap<>();
    propertiesAgg.put(propertyName, mock(MondrianDef.Expression.class));
    Class[] constructorArgsClasses = { mondrian.rolap.aggmatcher.AggStar.Table.class, String.class, MondrianDef.Expression.class, int.class, RolapStar.Column.class, boolean.class, MondrianDef.Expression.class, MondrianDef.Expression.class, Map.class };
    Object[] constructorArgs = { factTable, "name", mock(MondrianDef.Expression.class), 0, starColumn, true, mock(MondrianDef.Expression.class), null, propertiesAgg };
    AggStar.Table.Level aggStarLevel = (AggStar.Table.Level) createInstance("mondrian.rolap.aggmatcher.AggStar$Table$Level", constructorArgsClasses, constructorArgs, AggStar.Table.Level.class.getClassLoader());
    when(aggStar.lookupLevel(0)).thenReturn(aggStarLevel);
    doReturn(factTable).when(column).getTable();
    SqlTupleReader reader = new SqlTupleReader(constraint);
    reader.addLevelMemberSql(sqlQuery, targetLevel, baseCube, whichSelect, aggStar);
    verify(factTable).addToFrom(any(), eq(false), eq(true));
}
Also used : HashMap(java.util.HashMap) Iterator(java.util.Iterator) AggStar(mondrian.rolap.aggmatcher.AggStar) SqlQuery(mondrian.rolap.sql.SqlQuery) JdbcSchema(mondrian.rolap.aggmatcher.JdbcSchema) TupleConstraint(mondrian.rolap.sql.TupleConstraint) MondrianDef(mondrian.olap.MondrianDef)

Example 2 with TupleConstraint

use of mondrian.rolap.sql.TupleConstraint in project mondrian by pentaho.

the class RolapSchemaReader method getLevelMembers.

public List<Member> getLevelMembers(Level level, Evaluator context) {
    TupleConstraint constraint = sqlConstraintFactory.getLevelMembersConstraint(context, new Level[] { level });
    final MemberReader memberReader = getMemberReader(level.getHierarchy());
    List<RolapMember> membersInLevel = memberReader.getMembersInLevel((RolapLevel) level, constraint);
    return Util.cast(membersInLevel);
}
Also used : TupleConstraint(mondrian.rolap.sql.TupleConstraint)

Example 3 with TupleConstraint

use of mondrian.rolap.sql.TupleConstraint 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 TupleConstraint

use of mondrian.rolap.sql.TupleConstraint 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 TupleConstraint

use of mondrian.rolap.sql.TupleConstraint in project mondrian by pentaho.

the class RestrictedMemberReader method getMembersInLevel.

public List<RolapMember> getMembersInLevel(RolapLevel level, TupleConstraint constraint) {
    if (hierarchyAccess != null) {
        final int depth = level.getDepth();
        if (depth < hierarchyAccess.getTopLevelDepth()) {
            return Collections.emptyList();
        }
        if (depth > hierarchyAccess.getBottomLevelDepth()) {
            return Collections.emptyList();
        }
    }
    final List<RolapMember> membersInLevel = memberReader.getMembersInLevel(level, constraint);
    List<RolapMember> filteredMembers = new ArrayList<RolapMember>();
    filterMembers(membersInLevel, filteredMembers);
    return filteredMembers;
}
Also used : TupleConstraint(mondrian.rolap.sql.TupleConstraint) MemberChildrenConstraint(mondrian.rolap.sql.MemberChildrenConstraint)

Aggregations

TupleConstraint (mondrian.rolap.sql.TupleConstraint)6 MemberChildrenConstraint (mondrian.rolap.sql.MemberChildrenConstraint)4 Level (mondrian.olap.Level)3 Member (mondrian.olap.Member)3 Evaluator (mondrian.olap.Evaluator)2 Result (mondrian.olap.Result)2 NonEmptyResult (mondrian.rolap.RolapConnection.NonEmptyResult)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 MondrianDef (mondrian.olap.MondrianDef)1 CellRequest (mondrian.rolap.agg.CellRequest)1 AggStar (mondrian.rolap.aggmatcher.AggStar)1 JdbcSchema (mondrian.rolap.aggmatcher.JdbcSchema)1 CrossJoinArg (mondrian.rolap.sql.CrossJoinArg)1 DescendantsCrossJoinArg (mondrian.rolap.sql.DescendantsCrossJoinArg)1 MemberListCrossJoinArg (mondrian.rolap.sql.MemberListCrossJoinArg)1 SqlQuery (mondrian.rolap.sql.SqlQuery)1