use of mondrian.calc.impl.ListTupleList 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