use of mondrian.calc.TupleIterable in project mondrian by pentaho.
the class SqlConstraintUtils method expandSetFromCalculatedMember.
public static void expandSetFromCalculatedMember(Evaluator evaluator, Member member, TupleConstraintStruct expandedSet) {
assert member.getExpression() instanceof ResolvedFunCall;
ResolvedFunCall fun = (ResolvedFunCall) member.getExpression();
// Calling the main set evaluator to extend this.
Exp exp = fun.getArg(0);
TupleIterable tupleIterable = evaluator.getSetEvaluator(exp, true).evaluateTupleIterable();
Iterator<List<Member>> tupleIterator = tupleIterable.iterator();
TupleList tupleList = TupleCollections.materialize(tupleIterable, false);
boolean disjointSlicerTuple = false;
if (tupleList != null) {
disjointSlicerTuple = SqlConstraintUtils.isDisjointTuple(tupleList);
}
if (disjointSlicerTuple) {
if (!tupleList.isEmpty()) {
expandedSet.addTupleList(tupleList);
}
} else {
while (tupleIterator.hasNext()) {
expandedSet.addMembers(tupleIterator.next());
}
}
}
use of mondrian.calc.TupleIterable in project mondrian by pentaho.
the class SqlConstraintUtilsTest method getCalculatedMember.
public TupleConstraintStruct getCalculatedMember(final List<List<Member>> table, int arity) {
Member memberMock = mock(Member.class);
Exp[] funCallArgExps = new Exp[0];
ResolvedFunCall funCallArgMock = new ResolvedFunCall(mock(FunDef.class), funCallArgExps, mock(TupleType.class));
Exp[] funCallExps = { funCallArgMock };
ResolvedFunCall funCallMock = new ResolvedFunCall(mock(FunDef.class), funCallExps, mock(TupleType.class));
when(memberMock.getExpression()).thenReturn(funCallMock);
Evaluator evaluatorMock = mock(Evaluator.class);
Evaluator.SetEvaluator setEvaluatorMock = mock(Evaluator.SetEvaluator.class);
TupleIterable tupleIterableMock = mock(TupleIterable.class);
when(tupleIterableMock.iterator()).thenReturn(table.iterator());
when(tupleIterableMock.getArity()).thenReturn(arity);
AbstractTupleCursor cursor = new AbstractTupleCursor(arity) {
Iterator<List<Member>> iterator = table.iterator();
List<Member> curList;
@Override
public boolean forward() {
boolean hasNext = iterator.hasNext();
if (hasNext) {
curList = iterator.next();
} else {
curList = null;
}
return hasNext;
}
@Override
public List<Member> current() {
return curList;
}
};
when(tupleIterableMock.tupleCursor()).thenReturn(cursor);
when(setEvaluatorMock.evaluateTupleIterable()).thenReturn(tupleIterableMock);
when(evaluatorMock.getSetEvaluator(eq(funCallArgMock), anyBoolean())).thenReturn(setEvaluatorMock);
TupleConstraintStruct constraint = new TupleConstraintStruct();
SqlConstraintUtils.expandSetFromCalculatedMember(evaluatorMock, memberMock, constraint);
return constraint;
}
use of mondrian.calc.TupleIterable in project mondrian by pentaho.
the class RolapResult method executeAxis.
private TupleIterable executeAxis(Evaluator evaluator, QueryAxis queryAxis, Calc axisCalc, boolean construct, AxisMemberList axisMembers) {
if (queryAxis == null) {
// the same as an empty axis).
return new DelegatingTupleList(0, Collections.singletonList(Collections.<Member>emptyList()));
}
final int savepoint = evaluator.savepoint();
try {
evaluator.setNonEmpty(queryAxis.isNonEmpty());
evaluator.setEvalAxes(true);
final TupleIterable iterable = ((IterCalc) axisCalc).evaluateIterable(evaluator);
if (axisCalc.getClass().getName().indexOf("OrderFunDef") != -1) {
queryAxis.setOrdered(true);
}
if (iterable instanceof TupleList) {
TupleList list = (TupleList) iterable;
if (construct) {
} else if (axisMembers != null) {
axisMembers.mergeTupleList(list);
}
} else {
// Iterable
TupleCursor cursor = iterable.tupleCursor();
if (construct) {
} else if (axisMembers != null) {
axisMembers.mergeTupleIter(cursor);
}
}
return iterable;
} finally {
evaluator.restore(savepoint);
}
}
use of mondrian.calc.TupleIterable in project mondrian by pentaho.
the class CompoundPredicateInfo method makeSetPredicate.
private StarPredicate makeSetPredicate(final Exp exp, Evaluator evaluator) {
TupleIterable evaluatedSet = evaluator.getSetEvaluator(exp, true).evaluateTupleIterable();
ArrayList<StarPredicate> orList = new ArrayList<StarPredicate>();
OrPredicate orPredicate = null;
for (List<Member> complexSetItem : evaluatedSet) {
List<StarPredicate> andList = new ArrayList<StarPredicate>();
for (Member singleSetItem : complexSetItem) {
final List<List<Member>> singleItemList = Collections.singletonList(Collections.singletonList(singleSetItem));
StarPredicate singlePredicate = predicateFromTupleList(singleItemList, measure, evaluator).getValue();
andList.add(singlePredicate);
}
AndPredicate andPredicate = new AndPredicate(andList);
orList.add(andPredicate);
orPredicate = new OrPredicate(orList);
}
return orPredicate;
}
use of mondrian.calc.TupleIterable in project mondrian by pentaho.
the class RolapNamedSetEvaluator method ensureList.
/**
* Evaluates and saves the value of this named set, if it has not been evaluated already.
*/
private void ensureList(Evaluator evaluator) {
if (list != null) {
if (list == DUMMY_LIST) {
recursionCount++;
if (RECURSION_TOLERANCE > 0 && recursionCount > RECURSION_TOLERANCE) {
throw rrer.result.slicerEvaluator.newEvalException(null, "Illegal attempt to reference value of named set '" + namedSet.getName() + "' while evaluating itself");
}
}
return;
}
if (RolapResult.LOGGER.isDebugEnabled()) {
RolapResult.LOGGER.debug("Named set " + namedSet.getName() + ": starting evaluation");
}
// recursion detection
list = DUMMY_LIST;
try {
final Calc calc = rrer.getCompiled(namedSet.getExp(), false, ResultStyle.ITERABLE);
TupleIterable iterable = (TupleIterable) rrer.result.evaluateExp(calc, rrer.result.slicerEvaluator, evaluator);
// Axes can be in two forms: list or iterable. If iterable, we
// need to materialize it, to ensure that all cell values are in
// cache.
final TupleList rawList;
if (iterable instanceof TupleList) {
rawList = (TupleList) iterable;
} else {
rawList = TupleCollections.createList(iterable.getArity());
TupleCursor cursor = iterable.tupleCursor();
while (cursor.forward()) {
rawList.addCurrent(cursor);
}
}
if (RolapResult.LOGGER.isDebugEnabled()) {
RolapResult.LOGGER.debug(generateDebugMessage(calc, rawList));
}
// NamedSets are not supposed to depend on the current evaluation context but the
// way NamedSet evaluation was implemented in Mondrian, they could...
// So as a result, the nameset calc has to be profiled at the time of use instead
// of on close of the statement.
Util.explain(rrer.statement.getProfileHandler(), "NamedSet (" + namedSet.getName() + "):", calc, evaluator.getTiming());
// Wrap list so that currentOrdinal is updated whenever the list
// is accessed. The list is immutable, because we don't override
// AbstractList.set(int, Object).
this.list = rawList.withPositionCallback(this);
} finally {
if (this.list == DUMMY_LIST) {
this.list = null;
}
recursionCount = 0;
}
}
Aggregations