Skip to content

Commit

Permalink
MONDRIAN: Fix for bug #1881739
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//open/mondrian/": change = 10481]
  • Loading branch information
Ajit Joglekar committed Jan 29, 2008
1 parent 2706aba commit b2a1a55
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/main/mondrian/calc/impl/AbstractExpCompiler.java
Expand Up @@ -203,16 +203,16 @@ public IntegerCalc compileInteger(Exp exp) {
return new ConstantCalc(
new DecimalType(Integer.MAX_VALUE, 0),
constantCalc.evaluateInteger(null));
} else if (calc instanceof DoubleCalc) {
final DoubleCalc doubleCalc = (DoubleCalc) calc;
return new AbstractIntegerCalc(exp, new Calc[] {doubleCalc}) {
public int evaluateInteger(Evaluator evaluator) {
return (int) doubleCalc.evaluateDouble(evaluator);
}
};
}
final DoubleCalc doubleCalc = (DoubleCalc) calc;
return new AbstractIntegerCalc(exp, new Calc[] {doubleCalc}) {
public int evaluateInteger(Evaluator evaluator) {
return (int) doubleCalc.evaluateDouble(evaluator);
}
};
} else {
return (IntegerCalc) calc;
}
return (IntegerCalc) calc;
}

public StringCalc compileString(Exp exp) {
Expand Down
8 changes: 8 additions & 0 deletions testsrc/main/mondrian/olap/fun/FunctionTest.java
Expand Up @@ -7971,6 +7971,14 @@ public void testExcelPower() {
assertExprReturns("Power(8, 0.333333)", 2.0, 0.01);
assertExprReturns("Power(-2, 0.5)", Double.NaN, 0.001);
}

// Comment from the bug: the reason for this is that in AbstractExpCompiler
// in the compileInteger method we are casting an IntegerCalc into a
// DoubleCalc and there is no check for IntegerCalc in the NumericType
// conditional path.
public void testBug1881739() {
assertExprReturns("LEFT(\"TEST\", LEN(\"TEST\"))", "TEST");
}
}

// End FunctionTest.java

0 comments on commit b2a1a55

Please sign in to comment.