Search in sources :

Example 6 with ScalarFunction

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

the class RoundFloorCeilExpressionsTest method testRoundDecimalExpressionKeyRangeSimple.

// KeyRange explicit simple / sanity tests
@Test
public void testRoundDecimalExpressionKeyRangeSimple() throws Exception {
    ScalarFunction roundDecimalExpression = (ScalarFunction) RoundDecimalExpression.create(DUMMY_DECIMAL, 3);
    byte[] upperBound = PDecimal.INSTANCE.toBytes(new BigDecimal("1.2385"));
    byte[] lowerBound = PDecimal.INSTANCE.toBytes(new BigDecimal("1.2375"));
    KeyRange expectedKeyRange = KeyRange.getKeyRange(lowerBound, upperBound);
    KeyPart keyPart = roundDecimalExpression.newKeyPart(null);
    assertEquals(expectedKeyRange, keyPart.getKeyRange(CompareOp.EQUAL, LiteralExpression.newConstant(new BigDecimal("1.238"), PDecimal.INSTANCE)));
}
Also used : ScalarFunction(org.apache.phoenix.expression.function.ScalarFunction) KeyRange(org.apache.phoenix.query.KeyRange) KeyPart(org.apache.phoenix.compile.KeyPart) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

KeyPart (org.apache.phoenix.compile.KeyPart)6 ScalarFunction (org.apache.phoenix.expression.function.ScalarFunction)6 Test (org.junit.Test)6 BigDecimal (java.math.BigDecimal)3 KeyRange (org.apache.phoenix.query.KeyRange)3