Search in sources :

Example 1 with RoundDecimalExpression

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));
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) RoundDateExpression(org.apache.phoenix.expression.function.RoundDateExpression) RoundDecimalExpression(org.apache.phoenix.expression.function.RoundDecimalExpression) FloorDateExpression(org.apache.phoenix.expression.function.FloorDateExpression) CeilDateExpression(org.apache.phoenix.expression.function.CeilDateExpression) CeilDecimalExpression(org.apache.phoenix.expression.function.CeilDecimalExpression) FloorDecimalExpression(org.apache.phoenix.expression.function.FloorDecimalExpression) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 2 with RoundDecimalExpression

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);
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) RoundDateExpression(org.apache.phoenix.expression.function.RoundDateExpression) RoundDecimalExpression(org.apache.phoenix.expression.function.RoundDecimalExpression) FloorDateExpression(org.apache.phoenix.expression.function.FloorDateExpression) CeilDateExpression(org.apache.phoenix.expression.function.CeilDateExpression) CeilDecimalExpression(org.apache.phoenix.expression.function.CeilDecimalExpression) FloorDecimalExpression(org.apache.phoenix.expression.function.FloorDecimalExpression) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 3 with RoundDecimalExpression

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);
}
Also used : RoundDateExpression(org.apache.phoenix.expression.function.RoundDateExpression) RoundDecimalExpression(org.apache.phoenix.expression.function.RoundDecimalExpression) FloorDateExpression(org.apache.phoenix.expression.function.FloorDateExpression) CeilDateExpression(org.apache.phoenix.expression.function.CeilDateExpression) CeilDecimalExpression(org.apache.phoenix.expression.function.CeilDecimalExpression) FloorDecimalExpression(org.apache.phoenix.expression.function.FloorDecimalExpression) Test(org.junit.Test)

Aggregations

CeilDateExpression (org.apache.phoenix.expression.function.CeilDateExpression)3 CeilDecimalExpression (org.apache.phoenix.expression.function.CeilDecimalExpression)3 FloorDateExpression (org.apache.phoenix.expression.function.FloorDateExpression)3 FloorDecimalExpression (org.apache.phoenix.expression.function.FloorDecimalExpression)3 RoundDateExpression (org.apache.phoenix.expression.function.RoundDateExpression)3 RoundDecimalExpression (org.apache.phoenix.expression.function.RoundDecimalExpression)3 Test (org.junit.Test)3 BigDecimal (java.math.BigDecimal)2 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)2