Search in sources :

Example 1 with FloorDecimalExpression

use of org.apache.phoenix.expression.function.FloorDecimalExpression in project phoenix by apache.

the class RoundFloorCeilExpressionsTest method testFloorDecimalExpression.

@Test
public void testFloorDecimalExpression() throws Exception {
    LiteralExpression decimalLiteral = LiteralExpression.newConstant(1.23898, PDecimal.INSTANCE);
    Expression floorDecimalExpression = FloorDecimalExpression.create(decimalLiteral, 3);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    floorDecimalExpression.evaluate(null, ptr);
    Object result = floorDecimalExpression.getDataType().toObject(ptr);
    assertTrue(result instanceof BigDecimal);
    BigDecimal resultDecimal = (BigDecimal) result;
    assertEquals(BigDecimal.valueOf(1.238), 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 FloorDecimalExpression

use of org.apache.phoenix.expression.function.FloorDecimalExpression in project phoenix by apache.

the class RoundFloorCeilExpressionsTest method testFloorDecimalExpressionNoop.

@Test
public void testFloorDecimalExpressionNoop() throws Exception {
    LiteralExpression decimalLiteral = LiteralExpression.newConstant(5, PInteger.INSTANCE);
    Expression floorDecimalExpression = FloorDecimalExpression.create(decimalLiteral, 3);
    assertEquals(floorDecimalExpression, 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)2 CeilDecimalExpression (org.apache.phoenix.expression.function.CeilDecimalExpression)2 FloorDateExpression (org.apache.phoenix.expression.function.FloorDateExpression)2 FloorDecimalExpression (org.apache.phoenix.expression.function.FloorDecimalExpression)2 RoundDateExpression (org.apache.phoenix.expression.function.RoundDateExpression)2 RoundDecimalExpression (org.apache.phoenix.expression.function.RoundDecimalExpression)2 Test (org.junit.Test)2 BigDecimal (java.math.BigDecimal)1 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)1