Search in sources :

Example 1 with MondrianEvaluationException

use of mondrian.olap.fun.MondrianEvaluationException in project mondrian by pentaho.

the class InverseNormalUdf method execute.

public Object execute(Evaluator evaluator, Argument[] args) {
    final Object argValue = args[0].evaluateScalar(evaluator);
    LOGGER.debug("Inverse Normal argument was : " + argValue);
    if (!(argValue instanceof Number)) {
        // function will be called again when the cache is loaded.
        return null;
    }
    final Double d = new Double(((Number) argValue).doubleValue());
    LOGGER.debug("Inverse Normal argument as Double was : " + d);
    if (d.isNaN()) {
        return null;
    }
    // If probability is nonnumeric or
    // probability < 0 or
    // probability > 1,
    // returns an error.
    double dbl = d.doubleValue();
    if (dbl < 0.0 || dbl > 1.0) {
        LOGGER.debug("Invalid value for inverse normal distribution: " + dbl);
        throw new MondrianEvaluationException("Invalid value for inverse normal distribution: " + dbl);
    }
    try {
        Double result = new Double(nd.inverseCumulativeProbability(dbl));
        LOGGER.debug("Inverse Normal result : " + result.doubleValue());
        return result;
    } catch (MathException e) {
        LOGGER.debug("Exception calculating inverse normal distribution: " + dbl, e);
        throw new MondrianEvaluationException("Exception calculating inverse normal distribution: " + dbl);
    }
}
Also used : MathException(org.apache.commons.math.MathException) MondrianEvaluationException(mondrian.olap.fun.MondrianEvaluationException)

Example 2 with MondrianEvaluationException

use of mondrian.olap.fun.MondrianEvaluationException in project mondrian by pentaho.

the class NumberSqlCompilerTest method checkRejectsString.

private void checkRejectsString(String value) {
    Exp exp = Literal.createString(value);
    try {
        compiler.compile(exp);
    } catch (MondrianEvaluationException e) {
        return;
    }
    fail("Expected to get MondrianEvaluationException for " + value);
}
Also used : MondrianEvaluationException(mondrian.olap.fun.MondrianEvaluationException) DummyExp(mondrian.calc.DummyExp) Exp(mondrian.olap.Exp)

Aggregations

MondrianEvaluationException (mondrian.olap.fun.MondrianEvaluationException)2 DummyExp (mondrian.calc.DummyExp)1 Exp (mondrian.olap.Exp)1 MathException (org.apache.commons.math.MathException)1