use of mondrian.olap.type.NullType 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.type.NullType in project mondrian by pentaho.
the class RangeFunDef method compileMembers.
/**
* Returns two membercalc objects, substituting nulls with the hierarchy
* null member of the other expression.
*
* @param exp0 first expression
* @param exp1 second expression
*
* @return two member calcs
*/
private MemberCalc[] compileMembers(Exp exp0, Exp exp1, ExpCompiler compiler) {
MemberCalc[] members = new MemberCalc[2];
if (exp0.getType() instanceof NullType) {
members[0] = null;
} else {
members[0] = compiler.compileMember(exp0);
}
if (exp1.getType() instanceof NullType) {
members[1] = null;
} else {
members[1] = compiler.compileMember(exp1);
}
if (members[0] == null && members[1] == null) {
throw MondrianResource.instance().TwoNullsNotSupported.ex();
} else if (members[0] == null) {
Member nullMember = ((RolapMember) members[1].evaluate(null)).getHierarchy().getNullMember();
members[0] = (MemberCalc) ConstantCalc.constantMember(nullMember);
} else if (members[1] == null) {
Member nullMember = ((RolapMember) members[0].evaluate(null)).getHierarchy().getNullMember();
members[1] = (MemberCalc) ConstantCalc.constantMember(nullMember);
}
return members;
}
use of mondrian.olap.type.NullType in project mondrian by pentaho.
the class NumberSqlCompilerTest method testRejectsNonLiteral.
public void testRejectsNonLiteral() {
Exp exp = new DummyExp(new NullType());
assertNull(compiler.compile(exp));
}
use of mondrian.olap.type.NullType in project mondrian by pentaho.
the class ConstantCalcTest method testNullEvaluatesToConstantIntegerNull.
public void testNullEvaluatesToConstantIntegerNull() {
ConstantCalc constantCalc = new ConstantCalc(new NullType(), null);
assertEquals(FunUtil.IntegerNull, constantCalc.evaluateInteger(null));
}
use of mondrian.olap.type.NullType in project mondrian by pentaho.
the class ConstantCalcTest method testNullEvaluatesToConstantDoubleNull.
public void testNullEvaluatesToConstantDoubleNull() {
ConstantCalc constantCalc = new ConstantCalc(new NullType(), null);
assertEquals(FunUtil.DoubleNull, constantCalc.evaluateDouble(null));
}
Aggregations