Merge pull request #2246 from OpenRefine/issue-2244-wikidata-quantity-bound
Fix overflow error for quantities stored as doubles.
This commit is contained in:
commit
909d347650
@ -61,7 +61,7 @@ public class WbQuantityExpr implements WbExpression<QuantityValue> {
|
||||
@Override
|
||||
public QuantityValue evaluate(ExpressionContext ctxt)
|
||||
throws SkipSchemaExpressionException {
|
||||
StringValue amount = getLanguageExpr().evaluate(ctxt);
|
||||
StringValue amount = getAmountExpr().evaluate(ctxt);
|
||||
// we know the amount is nonnull, nonempty here
|
||||
|
||||
BigDecimal parsedAmount = null;
|
||||
@ -99,7 +99,7 @@ public class WbQuantityExpr implements WbExpression<QuantityValue> {
|
||||
}
|
||||
|
||||
@JsonProperty("amount")
|
||||
public WbExpression<? extends StringValue> getLanguageExpr() {
|
||||
public WbExpression<? extends StringValue> getAmountExpr() {
|
||||
return amountExpr;
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class WbStringVariable extends WbVariableExpr<StringValue> {
|
||||
if (!cell.value.toString().isEmpty()) {
|
||||
String stringValue = cell.value.toString();
|
||||
if (cell.value instanceof Double && ((Double)cell.value) % 1 == 0) {
|
||||
stringValue = Integer.toString(((Double)cell.value).intValue());
|
||||
stringValue = Long.toString(((Double)cell.value).longValue());
|
||||
}
|
||||
return Datamodel.makeStringValue(stringValue.trim());
|
||||
}
|
||||
|
@ -46,6 +46,12 @@ public class WbQuantityExprTest extends WbExpressionTest<QuantityValue> {
|
||||
setRow("4.00");
|
||||
evaluatesTo(Datamodel.makeQuantityValue(new BigDecimal("4.00"), null, null, "1"), exprWithoutUnit);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverflow() {
|
||||
setRow(14341937500d);
|
||||
evaluatesTo(Datamodel.makeQuantityValue(new BigDecimal("14341937500"), null, null, "1"), exprWithoutUnit);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidAmountWithoutUnit() {
|
||||
|
@ -69,6 +69,22 @@ public class WbStringVariableTest extends WbVariableTest<StringValue> {
|
||||
public void testDoubleInteger() {
|
||||
evaluatesTo(Datamodel.makeStringValue("45"), new Cell(45.0,null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that large doubles are correctly converted to strings
|
||||
*/
|
||||
@Test
|
||||
public void testLargeDouble() {
|
||||
evaluatesTo(Datamodel.makeStringValue("14341937500"), new Cell(14341937500d, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that large doubles are correctly converted to strings
|
||||
*/
|
||||
@Test
|
||||
public void testLong() {
|
||||
evaluatesTo(Datamodel.makeStringValue("14341937500"), new Cell(14341937500L, null));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user