Search in sources :

Example 1 with ScalarFunction

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

the class RoundFloorCeilExpressionsTest method testCeilDecimalExpressionKeyRangeCoverage.

@Test
public void testCeilDecimalExpressionKeyRangeCoverage() throws Exception {
    for (int scale : SCALES) {
        ScalarFunction ceilDecimalExpression = (ScalarFunction) CeilDecimalExpression.create(DUMMY_DECIMAL, scale);
        KeyPart keyPart = ceilDecimalExpression.newKeyPart(null);
        verifyKeyPart(RoundingType.CEIL, scale, keyPart);
    }
}
Also used : ScalarFunction(org.apache.phoenix.expression.function.ScalarFunction) KeyPart(org.apache.phoenix.compile.KeyPart) Test(org.junit.Test)

Example 2 with ScalarFunction

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

the class RoundFloorCeilExpressionsTest method testFloorDecimalExpressionKeyRangeSimple.

@Test
public void testFloorDecimalExpressionKeyRangeSimple() throws Exception {
    ScalarFunction floorDecimalExpression = (ScalarFunction) FloorDecimalExpression.create(DUMMY_DECIMAL, 3);
    byte[] upperBound = PDecimal.INSTANCE.toBytes(new BigDecimal("1.239"));
    byte[] lowerBound = PDecimal.INSTANCE.toBytes(new BigDecimal("1.238"));
    KeyRange expectedKeyRange = KeyRange.getKeyRange(lowerBound, true, upperBound, false);
    KeyPart keyPart = floorDecimalExpression.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)

Example 3 with ScalarFunction

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

the class RoundFloorCeilExpressionsTest method testRoundDecimalExpressionKeyRangeCoverage.

// KeyRange complex / generated tests
@Test
public void testRoundDecimalExpressionKeyRangeCoverage() throws Exception {
    for (int scale : SCALES) {
        ScalarFunction roundDecimalExpression = (ScalarFunction) RoundDecimalExpression.create(DUMMY_DECIMAL, scale);
        KeyPart keyPart = roundDecimalExpression.newKeyPart(null);
        verifyKeyPart(RoundingType.ROUND, scale, keyPart);
    }
}
Also used : ScalarFunction(org.apache.phoenix.expression.function.ScalarFunction) KeyPart(org.apache.phoenix.compile.KeyPart) Test(org.junit.Test)

Example 4 with ScalarFunction

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

the class RoundFloorCeilExpressionsTest method testFloorDecimalExpressionKeyRangeCoverage.

@Test
public void testFloorDecimalExpressionKeyRangeCoverage() throws Exception {
    for (int scale : SCALES) {
        ScalarFunction floorDecimalExpression = (ScalarFunction) FloorDecimalExpression.create(DUMMY_DECIMAL, scale);
        KeyPart keyPart = floorDecimalExpression.newKeyPart(null);
        verifyKeyPart(RoundingType.FLOOR, scale, keyPart);
    }
}
Also used : ScalarFunction(org.apache.phoenix.expression.function.ScalarFunction) KeyPart(org.apache.phoenix.compile.KeyPart) Test(org.junit.Test)

Example 5 with ScalarFunction

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

the class RoundFloorCeilExpressionsTest method testCeilDecimalExpressionKeyRangeSimple.

@Test
public void testCeilDecimalExpressionKeyRangeSimple() throws Exception {
    ScalarFunction ceilDecimalExpression = (ScalarFunction) CeilDecimalExpression.create(DUMMY_DECIMAL, 3);
    byte[] upperBound = PDecimal.INSTANCE.toBytes(new BigDecimal("1.238"));
    byte[] lowerBound = PDecimal.INSTANCE.toBytes(new BigDecimal("1.237"));
    KeyRange expectedKeyRange = KeyRange.getKeyRange(lowerBound, false, upperBound, true);
    KeyPart keyPart = ceilDecimalExpression.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