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