Search in sources :

Example 6 with KeyPart

use of org.apache.phoenix.compile.KeyPart 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 7 with KeyPart

use of org.apache.phoenix.compile.KeyPart 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 8 with KeyPart

use of org.apache.phoenix.compile.KeyPart 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 9 with KeyPart

use of org.apache.phoenix.compile.KeyPart 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)

Example 10 with KeyPart

use of org.apache.phoenix.compile.KeyPart 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)10 ScalarFunction (org.apache.phoenix.expression.function.ScalarFunction)6 Test (org.junit.Test)6 BigDecimal (java.math.BigDecimal)4 Expression (org.apache.phoenix.expression.Expression)4 KeyRange (org.apache.phoenix.query.KeyRange)4 List (java.util.List)3 CompareOp (org.apache.hadoop.hbase.filter.CompareFilter.CompareOp)3 PDataType (org.apache.phoenix.schema.types.PDataType)3 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)2 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)1 PColumn (org.apache.phoenix.schema.PColumn)1 SortOrder (org.apache.phoenix.schema.SortOrder)1 PDataCodec (org.apache.phoenix.schema.types.PDataType.PDataCodec)1