Search in sources :

Example 6 with Evaluator

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

the class SubsetFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final ListCalc listCalc = compiler.compileList(call.getArg(0));
    final IntegerCalc startCalc = compiler.compileInteger(call.getArg(1));
    final IntegerCalc countCalc = call.getArgCount() > 2 ? compiler.compileInteger(call.getArg(2)) : null;
    return new AbstractListCalc(call, new Calc[] { listCalc, startCalc, countCalc }) {

        public TupleList evaluateList(Evaluator evaluator) {
            final int savepoint = evaluator.savepoint();
            try {
                evaluator.setNonEmpty(false);
                final TupleList list = listCalc.evaluateList(evaluator);
                final int start = startCalc.evaluateInteger(evaluator);
                int end;
                if (countCalc != null) {
                    final int count = countCalc.evaluateInteger(evaluator);
                    end = start + count;
                } else {
                    end = list.size();
                }
                if (end > list.size()) {
                    end = list.size();
                }
                if (start >= end || start < 0) {
                    return TupleCollections.emptyList(list.getArity());
                }
                if (start == 0 && end == list.size()) {
                    return list;
                }
                assert 0 <= start;
                assert start < end;
                assert end <= list.size();
                return list.subList(start, end);
            } finally {
                evaluator.restore(savepoint);
            }
        }
    };
}
Also used : AbstractListCalc(mondrian.calc.impl.AbstractListCalc) AbstractListCalc(mondrian.calc.impl.AbstractListCalc) Evaluator(mondrian.olap.Evaluator)

Example 7 with Evaluator

use of mondrian.olap.Evaluator 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 8 with Evaluator

use of mondrian.olap.Evaluator 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 9 with Evaluator

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

the class SqlConstraintUtilsTest method testExpandSupportedCalculatedMember_notCalculated.

public void testExpandSupportedCalculatedMember_notCalculated() {
    // init
    Evaluator evaluator = Mockito.mock(Evaluator.class);
    Member member = makeNoncalculatedMember("0");
    // tested call
    TupleConstraintStruct constraint = new TupleConstraintStruct();
    SqlConstraintUtils.expandSupportedCalculatedMember(member, evaluator, constraint);
    List<Member> r = constraint.getMembers();
    // test
    Assert.assertNotNull(r);
    Assert.assertEquals(1, r.size());
    Assert.assertSame(member, r.get(0));
}
Also used : Evaluator(mondrian.olap.Evaluator) SetEvaluator(mondrian.olap.Evaluator.SetEvaluator) Member(mondrian.olap.Member) TestMember(mondrian.olap.fun.TestMember)

Example 10 with Evaluator

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

the class SqlConstraintUtilsTest method testExpandSupportedCalculatedMember_calculated_aggregate.

public void testExpandSupportedCalculatedMember_calculated_aggregate() {
    Evaluator evaluator = Mockito.mock(Evaluator.class);
    Member endMember0 = Mockito.mock(Member.class);
    Member endMember1 = Mockito.mock(Member.class);
    Member endMember2 = Mockito.mock(Member.class);
    Member member = null;
    List<Member> r = null;
    List<Member> aggregatedMembers = null;
    // 0
    aggregatedMembers = Collections.emptyList();
    member = makeAggregateExprMember(evaluator, aggregatedMembers);
    // tested call
    TupleConstraintStruct constraint = new TupleConstraintStruct();
    SqlConstraintUtils.expandSupportedCalculatedMember(member, evaluator, true, constraint);
    r = constraint.getMembers();
    // test
    assertSameContent("", aggregatedMembers, r);
    // 1
    aggregatedMembers = Collections.singletonList(endMember0);
    member = makeAggregateExprMember(evaluator, aggregatedMembers);
    // tested call
    constraint = new TupleConstraintStruct();
    SqlConstraintUtils.expandSupportedCalculatedMember(member, evaluator, constraint);
    r = constraint.getMembers();
    // test
    assertSameContent("", aggregatedMembers, r);
    // 2
    aggregatedMembers = Arrays.asList(new Member[] { endMember0, endMember1 });
    member = makeAggregateExprMember(evaluator, aggregatedMembers);
    // tested call
    constraint = new TupleConstraintStruct();
    SqlConstraintUtils.expandSupportedCalculatedMember(member, evaluator, constraint);
    r = constraint.getMembers();
    // test
    assertSameContent("", aggregatedMembers, r);
    // 3
    aggregatedMembers = Arrays.asList(new Member[] { endMember0, endMember1, endMember2 });
    member = makeAggregateExprMember(evaluator, aggregatedMembers);
    // tested call
    constraint = new TupleConstraintStruct();
    SqlConstraintUtils.expandSupportedCalculatedMember(member, evaluator, constraint);
    r = constraint.getMembers();
    // test
    assertSameContent("", aggregatedMembers, r);
}
Also used : Evaluator(mondrian.olap.Evaluator) SetEvaluator(mondrian.olap.Evaluator.SetEvaluator) Member(mondrian.olap.Member) TestMember(mondrian.olap.fun.TestMember)

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