Search in sources :

Example 1 with UnaryTupleList

use of mondrian.calc.impl.UnaryTupleList in project mondrian by pentaho.

the class AggregationOnDistinctCountMeasuresTest method testShouldNotRemoveDuplicateTuples.

public void testShouldNotRemoveDuplicateTuples() {
    Member maleChildMember = member(Id.Segment.toList("Gender", "All Gender", "M"), salesCubeSchemaReader);
    Member femaleChildMember = member(Id.Segment.toList("Gender", "All Gender", "F"), salesCubeSchemaReader);
    List<Member> memberList = new ArrayList<Member>();
    memberList.add(maleChildMember);
    memberList.add(maleChildMember);
    memberList.add(femaleChildMember);
    TupleList tuples = new UnaryTupleList(memberList);
    tuples = optimizeChildren(tuples);
    assertEquals(3, tuples.size());
}
Also used : UnaryTupleList(mondrian.calc.impl.UnaryTupleList) TupleList(mondrian.calc.TupleList) ArrayTupleList(mondrian.calc.impl.ArrayTupleList) UnaryTupleList(mondrian.calc.impl.UnaryTupleList)

Example 2 with UnaryTupleList

use of mondrian.calc.impl.UnaryTupleList in project mondrian by pentaho.

the class AggregationOnDistinctCountMeasuresTest method testMemberCountIsNotSameForAllMembersInTuple.

public void testMemberCountIsNotSameForAllMembersInTuple() {
    Member maleChild = member(Id.Segment.toList("Gender", "All Gender", "M"), salesCubeSchemaReader);
    Member femaleChild = member(Id.Segment.toList("Gender", "All Gender", "F"), salesCubeSchemaReader);
    Member mexicoMember = member(Id.Segment.toList("Store", "All Stores", "Mexico"), salesCubeSchemaReader);
    TupleList memberList = new UnaryTupleList(Collections.singletonList(maleChild));
    TupleList list2 = storeMembersUsaAndCanada(false, salesCubeSchemaReader, salesCube);
    memberList = mutableCrossJoin(memberList, list2);
    memberList.addTuple(femaleChild, mexicoMember);
    Map<Member, Integer>[] memberCounterMap = AggregateFunDef.AggregateCalc.membersVersusOccurencesInTuple(memberList);
    assertFalse(Util.areOccurencesEqual(memberCounterMap[0].values()));
    assertTrue(Util.areOccurencesEqual(memberCounterMap[1].values()));
}
Also used : UnaryTupleList(mondrian.calc.impl.UnaryTupleList) TupleList(mondrian.calc.TupleList) ArrayTupleList(mondrian.calc.impl.ArrayTupleList) UnaryTupleList(mondrian.calc.impl.UnaryTupleList)

Example 3 with UnaryTupleList

use of mondrian.calc.impl.UnaryTupleList in project mondrian by pentaho.

the class LastPeriodsFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    // Member defaults to [Time].currentmember
    Exp[] args = call.getArgs();
    final MemberCalc memberCalc;
    if (args.length == 1) {
        final RolapHierarchy timeHierarchy = ((RolapCube) compiler.getEvaluator().getCube()).getTimeHierarchy(getName());
        memberCalc = new HierarchyCurrentMemberFunDef.FixedCalcImpl(call, timeHierarchy);
    } else {
        memberCalc = compiler.compileMember(args[1]);
    }
    // Numeric Expression.
    final IntegerCalc indexValueCalc = compiler.compileInteger(args[0]);
    return new AbstractListCalc(call, new Calc[] { memberCalc, indexValueCalc }) {

        public TupleList evaluateList(Evaluator evaluator) {
            Member member = memberCalc.evaluateMember(evaluator);
            int indexValue = indexValueCalc.evaluateInteger(evaluator);
            return new UnaryTupleList(lastPeriods(member, evaluator, indexValue));
        }
    };
}
Also used : AbstractListCalc(mondrian.calc.impl.AbstractListCalc) RolapCube(mondrian.rolap.RolapCube) RolapHierarchy(mondrian.rolap.RolapHierarchy) UnaryTupleList(mondrian.calc.impl.UnaryTupleList)

Example 4 with UnaryTupleList

use of mondrian.calc.impl.UnaryTupleList in project mondrian by pentaho.

the class PeriodsToDateFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final LevelCalc levelCalc = call.getArgCount() > 0 ? compiler.compileLevel(call.getArg(0)) : null;
    final MemberCalc memberCalc = call.getArgCount() > 1 ? compiler.compileMember(call.getArg(1)) : null;
    final RolapHierarchy timeHierarchy = levelCalc == null ? ((RolapCube) compiler.getEvaluator().getCube()).getTimeHierarchy(getName()) : null;
    return new AbstractListCalc(call, new Calc[] { levelCalc, memberCalc }) {

        public TupleList evaluateList(Evaluator evaluator) {
            final Member member;
            final Level level;
            if (levelCalc == null) {
                member = evaluator.getContext(timeHierarchy);
                level = member.getLevel().getParentLevel();
            } else {
                level = levelCalc.evaluateLevel(evaluator);
                if (memberCalc == null) {
                    member = evaluator.getContext(level.getHierarchy());
                } else {
                    member = memberCalc.evaluateMember(evaluator);
                }
            }
            return new UnaryTupleList(periodsToDate(evaluator, level, member));
        }

        public boolean dependsOn(Hierarchy hierarchy) {
            if (super.dependsOn(hierarchy)) {
                return true;
            }
            if (memberCalc != null) {
                return false;
            } else if (levelCalc != null) {
                return levelCalc.getType().usesHierarchy(hierarchy, true);
            } else {
                return hierarchy == timeHierarchy;
            }
        }
    };
}
Also used : RolapHierarchy(mondrian.rolap.RolapHierarchy) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) AbstractListCalc(mondrian.calc.impl.AbstractListCalc) RolapHierarchy(mondrian.rolap.RolapHierarchy)

Example 5 with UnaryTupleList

use of mondrian.calc.impl.UnaryTupleList in project mondrian by pentaho.

the class SqlTupleReader method readTuples.

public TupleList readTuples(DataSource jdbcConnection, TupleList partialResult, List<List<RolapMember>> newPartialResult) {
    // The following algorithm will first group targets based on the cubes
    // that are applicable to each.  This allows loading the tuple data
    // in groups that join correctly to the associated fact table.
    // Once each group has been loaded, results of each are
    // brought together in a crossjoin, and then projected into a new
    // tuple list based on the ordering originally specified by the
    // targets list.
    // For non-virtual cube queries there is only a single
    // targetGroup.
    List<List<TargetBase>> targetGroups = groupTargets(targets, constraint.getEvaluator().getQuery());
    List<TupleList> tupleLists = new ArrayList<>();
    for (List<TargetBase> targetGroup : targetGroups) {
        prepareTuples(jdbcConnection, partialResult, newPartialResult, targetGroup);
        int size = targetGroup.size();
        final Iterator<Member>[] iter = new Iterator[size];
        for (int i = 0; i < size; i++) {
            TargetBase t = targetGroup.get(i);
            iter[i] = t.close().iterator();
        }
        List<Member> members = new ArrayList<>();
        while (iter[0].hasNext()) {
            for (int i = 0; i < size; i++) {
                members.add(iter[i].next());
            }
        }
        tupleLists.add(size + emptySets == 1 ? new UnaryTupleList(members) : new ListTupleList(size + emptySets, members));
    }
    if (tupleLists.isEmpty()) {
        return TupleCollections.emptyList(targets.size());
    }
    TupleList tupleList = CrossJoinFunDef.mutableCrossJoin(tupleLists);
    if (!tupleList.isEmpty() && targetGroups.size() > 1) {
        tupleList = projectTupleList(tupleList);
    }
    // need to hierarchize the columns from the enumerated targets
    // since we didn't necessarily add them in the order in which
    // they originally appeared in the cross product
    int enumTargetCount = getEnumTargetCount();
    if (enumTargetCount > 0) {
        tupleList = FunUtil.hierarchizeTupleList(tupleList, false);
    }
    return tupleList;
}
Also used : ListTupleList(mondrian.calc.impl.ListTupleList) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) TupleList(mondrian.calc.TupleList) ArrayTupleList(mondrian.calc.impl.ArrayTupleList) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) ListTupleList(mondrian.calc.impl.ListTupleList) ListTupleList(mondrian.calc.impl.ListTupleList) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) TupleList(mondrian.calc.TupleList) ArrayTupleList(mondrian.calc.impl.ArrayTupleList)

Aggregations

UnaryTupleList (mondrian.calc.impl.UnaryTupleList)11 TupleList (mondrian.calc.TupleList)6 AbstractListCalc (mondrian.calc.impl.AbstractListCalc)4 ArrayTupleList (mondrian.calc.impl.ArrayTupleList)4 ResolvedFunCall (mondrian.mdx.ResolvedFunCall)2 Exp (mondrian.olap.Exp)2 FunDef (mondrian.olap.FunDef)2 Member (mondrian.olap.Member)2 RolapHierarchy (mondrian.rolap.RolapHierarchy)2 Execution (mondrian.server.Execution)2 ArrayList (java.util.ArrayList)1 Calc (mondrian.calc.Calc)1 ListTupleList (mondrian.calc.impl.ListTupleList)1 MemberExpr (mondrian.mdx.MemberExpr)1 mondrian.olap (mondrian.olap)1 SetEvaluator (mondrian.olap.Evaluator.SetEvaluator)1 AggregateFunDef (mondrian.olap.fun.AggregateFunDef)1 CrossJoinTest (mondrian.olap.fun.CrossJoinTest)1 NullFunDef (mondrian.olap.fun.CrossJoinTest.NullFunDef)1 ParenthesesFunDef (mondrian.olap.fun.ParenthesesFunDef)1