use of org.apache.phoenix.expression.function.RoundDecimalExpression in project phoenix by apache.
the class RoundFloorCeilExpressionsTest method testRoundNegativePrecisionDecimalExpression.
@Test
public void testRoundNegativePrecisionDecimalExpression() throws Exception {
LiteralExpression decimalLiteral = LiteralExpression.newConstant(444.44, PDecimal.INSTANCE);
Expression roundDecimalExpression = RoundDecimalExpression.create(decimalLiteral, -2);
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
roundDecimalExpression.evaluate(null, ptr);
Object result = roundDecimalExpression.getDataType().toObject(ptr);
assertTrue(result instanceof BigDecimal);
BigDecimal resultDecimal = (BigDecimal) result;
assertEquals(0, BigDecimal.valueOf(400).compareTo(resultDecimal));
}
use of org.apache.phoenix.expression.function.RoundDecimalExpression in project phoenix by apache.
the class RoundFloorCeilExpressionsTest method testRoundDecimalExpression.
// Decimal Expression Tests
@Test
public void testRoundDecimalExpression() throws Exception {
LiteralExpression decimalLiteral = LiteralExpression.newConstant(1.23898, PDecimal.INSTANCE);
Expression roundDecimalExpression = RoundDecimalExpression.create(decimalLiteral, 3);
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
roundDecimalExpression.evaluate(null, ptr);
Object result = roundDecimalExpression.getDataType().toObject(ptr);
assertTrue(result instanceof BigDecimal);
BigDecimal resultDecimal = (BigDecimal) result;
assertEquals(BigDecimal.valueOf(1.239), resultDecimal);
}
use of org.apache.phoenix.expression.function.RoundDecimalExpression in project phoenix by apache.
the class RoundFloorCeilExpressionsTest method testRoundDecimalExpressionNoop.
@Test
public void testRoundDecimalExpressionNoop() throws Exception {
LiteralExpression decimalLiteral = LiteralExpression.newConstant(5, PInteger.INSTANCE);
Expression roundDecimalExpression = RoundDecimalExpression.create(decimalLiteral, 3);
assertEquals(roundDecimalExpression, decimalLiteral);
}
Aggregations