use of mondrian.mdx.ResolvedFunCall in project mondrian by pentaho.
the class IifFunDefTest method setUp.
@Override
protected void setUp() throws Exception {
when(trueCaseParamMock.getType()).thenReturn(setTypeMock);
setListCalc = new SetListCalc(trueCaseParamMock, new Exp[] { args[1] }, compilerMock, ResultStyle.LIST_MUTABLELIST);
call = new ResolvedFunCall(funDefMock, args, setTypeMock);
when(compilerMock.compileAs(any(), any(), any())).thenReturn(setListCalc);
}
use of mondrian.mdx.ResolvedFunCall 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.mdx.ResolvedFunCall in project mondrian by pentaho.
the class ScenarioImpl method forMember.
/**
* Returns the scenario inside a calculated member in the scenario
* dimension. For example, applied to [Scenario].[1], returns the Scenario
* object representing scenario #1.
*
* @param member Wrapper member
* @return Wrapped scenario
*/
static Scenario forMember(final RolapMember member) {
if (isScenario(member.getHierarchy())) {
final Formula formula = ((RolapCalculatedMember) member).getFormula();
final ResolvedFunCall resolvedFunCall = (ResolvedFunCall) formula.getExpression();
final Calc calc = resolvedFunCall.getFunDef().compileCall(null, null);
return ((ScenarioCalc) calc).getScenario();
} else {
return null;
}
}
use of mondrian.mdx.ResolvedFunCall in project mondrian by pentaho.
the class SqlConstraintUtilsTest method testIsSupportedExpressionForCalculatedMember.
// ~ Test methods ----------------------------------------------------------
public void testIsSupportedExpressionForCalculatedMember() {
Assert.assertEquals("null expression", false, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(null));
Exp memberExpr = new MemberExpr(Mockito.mock(Member.class));
Assert.assertEquals("MemberExpr", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(memberExpr));
Exp nullFunDefExpr = new ResolvedFunCall(new NullFunDef(), new Exp[] {}, new NullType());
Assert.assertEquals("ResolvedFunCall-NullFunDef", false, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(nullFunDefExpr));
// ResolvedFunCall arguments
final Exp argUnsupported = new ResolvedFunCall(new NullFunDef(), new Exp[] {}, new NullType());
final Exp argSupported = new MemberExpr(Mockito.mock(Member.class));
Assert.assertEquals(false, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(argUnsupported));
Assert.assertEquals(true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(argSupported));
final Exp[] noArgs = new Exp[] {};
final Exp[] args1Unsupported = new Exp[] { argUnsupported };
final Exp[] args1Supported = new Exp[] { argSupported };
final Exp[] args2Different = new Exp[] { argUnsupported, argSupported };
final ParenthesesFunDef parenthesesFunDef = new ParenthesesFunDef(Category.Member);
Type parenthesesReturnType = new DecimalType(1, 1);
Exp parenthesesExpr = new ResolvedFunCall(parenthesesFunDef, noArgs, parenthesesReturnType);
Assert.assertEquals("ResolvedFunCall-Parentheses()", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(parenthesesExpr));
parenthesesExpr = new ResolvedFunCall(parenthesesFunDef, args1Unsupported, parenthesesReturnType);
Assert.assertEquals("ResolvedFunCall-Parentheses(N)", false, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(parenthesesExpr));
parenthesesExpr = new ResolvedFunCall(parenthesesFunDef, args1Supported, parenthesesReturnType);
Assert.assertEquals("ResolvedFunCall-Parentheses(Y)", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(parenthesesExpr));
parenthesesExpr = new ResolvedFunCall(parenthesesFunDef, args2Different, parenthesesReturnType);
Assert.assertEquals("ResolvedFunCall-Parentheses(N,Y)", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(parenthesesExpr));
FunDef dummy = Mockito.mock(FunDef.class);
Mockito.doReturn(Syntax.Function).when(dummy).getSyntax();
Mockito.doReturn("dummy").when(dummy).getName();
FunDef aggregateFunDef = new AggregateFunDef(dummy);
Type aggregateReturnType = new DecimalType(1, 1);
Exp aggregateExpr = new ResolvedFunCall(aggregateFunDef, noArgs, aggregateReturnType);
Assert.assertEquals("ResolvedFunCall-Aggregate()", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(aggregateExpr));
aggregateExpr = new ResolvedFunCall(aggregateFunDef, args1Unsupported, aggregateReturnType);
Assert.assertEquals("ResolvedFunCall-Aggregate(N)", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(aggregateExpr));
aggregateExpr = new ResolvedFunCall(aggregateFunDef, args1Supported, aggregateReturnType);
Assert.assertEquals("ResolvedFunCall-Aggregate(Y)", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(aggregateExpr));
aggregateExpr = new ResolvedFunCall(aggregateFunDef, args2Different, aggregateReturnType);
Assert.assertEquals("ResolvedFunCall-Aggregate(N,Y)", true, SqlConstraintUtils.isSupportedExpressionForCalculatedMember(aggregateExpr));
}
use of mondrian.mdx.ResolvedFunCall 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;
}
Aggregations