use of mondrian.calc.TupleIterable in project mondrian by pentaho.
the class ExistingFunDef method compileCall.
public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
final IterCalc setArg = compiler.compileIter(call.getArg(0));
final Type myType = call.getArg(0).getType();
return new AbstractListCalc(call, new Calc[] { setArg }) {
public boolean dependsOn(Hierarchy hierarchy) {
return myType.usesHierarchy(hierarchy, false);
}
public TupleList evaluateList(Evaluator evaluator) {
TupleIterable setTuples = setArg.evaluateIterable(evaluator);
TupleList result = TupleCollections.createList(setTuples.getArity());
List<Member> contextMembers = Arrays.asList(evaluator.getMembers());
List<Hierarchy> argDims = null;
List<Hierarchy> contextDims = getHierarchies(contextMembers);
for (List<Member> tuple : setTuples) {
if (argDims == null) {
argDims = getHierarchies(tuple);
}
if (existsInTuple(tuple, contextMembers, argDims, contextDims, evaluator)) {
result.add(tuple);
}
}
return result;
}
};
}
use of mondrian.calc.TupleIterable in project mondrian by pentaho.
the class RolapResult method evaluateExp.
/**
* Evaluates an expression. Intended for evaluating named sets.
*
* <p>
* Does not modify the contents of the evaluator.
*
* @param calc
* Compiled expression
* @param slicerEvaluator
* Evaluation context for slicers
* @param contextEvaluator
* Evaluation context (optional)
* @return Result
*/
Object evaluateExp(Calc calc, RolapEvaluator slicerEvaluator, Evaluator contextEvaluator) {
int attempt = 0;
RolapEvaluator evaluator = slicerEvaluator.push();
if (contextEvaluator != null && contextEvaluator.isEvalAxes()) {
evaluator.setEvalAxes(true);
}
final int savepoint = evaluator.savepoint();
boolean dirty = batchingReader.isDirty();
try {
while (true) {
evaluator.restore(savepoint);
evaluator.setCellReader(batchingReader);
Object preliminaryValue = calc.evaluate(evaluator);
if (preliminaryValue instanceof TupleIterable) {
// During the preliminary phase, we have to materialize the
// tuple lists or the evaluation lower down won't take into
// account all the tuples.
TupleIterable iterable = (TupleIterable) preliminaryValue;
final TupleCursor cursor = iterable.tupleCursor();
while (cursor.forward()) {
// ignore
}
}
if (!phase()) {
break;
} else {
// Clear invalid expression result so that the next
// evaluation will pick up the newly loaded aggregates.
evaluator.clearExpResultCache(false);
}
if (attempt++ > maxEvalDepth) {
throw Util.newInternal("Failed to load all aggregations after " + maxEvalDepth + "passes; there's probably a cycle");
}
}
// re-evaluate them.
if (dirty) {
batchingReader.setDirty(true);
}
evaluator.restore(savepoint);
evaluator.setCellReader(aggregatingReader);
final Object o = calc.evaluate(evaluator);
return o;
} finally {
evaluator.restore(savepoint);
}
}
use of mondrian.calc.TupleIterable in project mondrian by pentaho.
the class RolapResult method evalExecute.
TupleIterable evalExecute(List<List<Member>> nonAllMembers, int cnt, RolapEvaluator evaluator, QueryAxis queryAxis, Calc calc) {
final int savepoint = evaluator.savepoint();
final int arity = calc == null ? 0 : calc.getType().getArity();
if (cnt < 0) {
try {
final TupleIterable axis = executeAxis(evaluator, queryAxis, calc, true, null);
return axis;
} finally {
evaluator.restore(savepoint);
}
// No need to clear expression cache here as no new aggregates are
// loaded(aggregatingReader reads from cache).
} else {
try {
TupleList axisResult = TupleCollections.emptyList(arity);
for (Member m : nonAllMembers.get(cnt)) {
evaluator.setContext(m);
TupleIterable axis = evalExecute(nonAllMembers, cnt - 1, evaluator, queryAxis, calc);
boolean ordered = false;
if (queryAxis != null) {
ordered = queryAxis.isOrdered();
}
axisResult = mergeAxes(axisResult, axis, ordered);
}
return axisResult;
} finally {
evaluator.restore(savepoint);
}
}
}
use of mondrian.calc.TupleIterable in project mondrian by pentaho.
the class CrossJoinTest method doTupleTupleIterTest.
private void doTupleTupleIterTest(CrossJoinFunDef.CrossJoinIterCalc calc, Execution execution) {
TupleList l4 = makeListTuple(m4);
String s4 = toString(l4);
String e4 = "{[U, V], [W, X], [Y, Z]}";
Assert.assertEquals(e4, s4);
TupleList l3 = makeListTuple(m3);
String s3 = toString(l3);
String e3 = "{[k, l], [m, n]}";
Assert.assertEquals(e3, s3);
String s = Locus.execute(execution, "CrossJoinTest", new Locus.Action<String>() {
public String execute() {
TupleIterable iterable = calc.makeIterable(l4, l3);
return CrossJoinTest.this.toString(iterable);
}
});
String e = "{[U, V, k, l], [U, V, m, n], [W, X, k, l], " + "[W, X, m, n], [Y, Z, k, l], [Y, Z, m, n]}";
Assert.assertEquals(e, s);
}
Aggregations