use of mondrian.olap.FunDef 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.olap.FunDef in project mondrian by pentaho.
the class TopCountNativeEvaluatorTest method mockFunctionDef.
private FunDef mockFunctionDef() {
FunDef topCountFunMock = mock(FunDef.class);
when(topCountFunMock.getName()).thenReturn("TOPCOUNT");
return topCountFunMock;
}
use of mondrian.olap.FunDef in project mondrian by pentaho.
the class SqlConstraintUtilsTest method makeParenthesesExprMember.
private Member makeParenthesesExprMember(Evaluator evaluator, Member parenthesesInnerMember, String toString) {
Member member = Mockito.mock(Member.class);
Mockito.doReturn("mock[" + toString + "]").when(member).toString();
Mockito.doReturn(true).when(member).isCalculated();
Exp parenthesesArg = new MemberExpr(parenthesesInnerMember);
FunDef funDef = new ParenthesesFunDef(Category.Member);
Exp[] args = new Exp[] { parenthesesArg };
Type returnType = new DecimalType(1, 1);
Exp memberExp = new ResolvedFunCall(funDef, args, returnType);
Mockito.doReturn(memberExp).when(member).getExpression();
Assert.assertEquals(true, member.isCalculated());
Assert.assertEquals(true, SqlConstraintUtils.isSupportedCalculatedMember(member));
return member;
}
use of mondrian.olap.FunDef in project mondrian by pentaho.
the class SqlConstraintUtilsTest method makeAggregateExprMember.
private Member makeAggregateExprMember(Evaluator mockEvaluator, List<Member> endMembers) {
Member member = Mockito.mock(Member.class);
Mockito.doReturn(true).when(member).isCalculated();
Member aggregatedMember0 = Mockito.mock(Member.class);
Exp aggregateArg0 = new MemberExpr(aggregatedMember0);
FunDef dummy = Mockito.mock(FunDef.class);
Mockito.doReturn(Syntax.Function).when(dummy).getSyntax();
Mockito.doReturn("dummy").when(dummy).getName();
FunDef funDef = new AggregateFunDef(dummy);
Exp[] args = new Exp[] { aggregateArg0 };
Type returnType = new DecimalType(1, 1);
Exp memberExp = new ResolvedFunCall(funDef, args, returnType);
Mockito.doReturn(memberExp).when(member).getExpression();
SetEvaluator setEvaluator = Mockito.mock(SetEvaluator.class);
Mockito.doReturn(setEvaluator).when(mockEvaluator).getSetEvaluator(aggregateArg0, true);
Mockito.doReturn(new UnaryTupleList(endMembers)).when(setEvaluator).evaluateTupleIterable();
Assert.assertEquals(true, member.isCalculated());
Assert.assertEquals(true, SqlConstraintUtils.isSupportedCalculatedMember(member));
return member;
}
Aggregations