Package org.apache.phoenix.expression

Examples of org.apache.phoenix.expression.DecimalAddExpression


    @Test
    public void testDecimalAddition() throws Exception {
        LiteralExpression op1, op2, op3;
        List<Expression> children;
        ImmutableBytesWritable ptr;
        DecimalAddExpression e;
        boolean evaluated;

        op1 = LiteralExpression.newConstant(new BigDecimal("1234567890123456789012345678901"), PDataType.DECIMAL, 31, 0);
        op2 = LiteralExpression.newConstant(new BigDecimal("12345"), PDataType.DECIMAL, 5, 0);
        children = Arrays.<Expression>asList(op1, op2);
        e = new DecimalAddExpression(children);
        ptr = new ImmutableBytesWritable();
        evaluated = e.evaluate(null, ptr);
        assertTrue(evaluated);
        assertEqualValue(PDataType.DECIMAL, new BigDecimal("1234567890123456789012345691246"), ptr);

        op1 = LiteralExpression.newConstant(new BigDecimal("12345"), PDataType.DECIMAL, 5, 0);
        op2 = LiteralExpression.newConstant(new BigDecimal("123.45"), PDataType.DECIMAL, 5, 2);
        children = Arrays.<Expression>asList(op1, op2);
        e = new DecimalAddExpression(children);
        ptr = new ImmutableBytesWritable();
        evaluated = e.evaluate(null, ptr);
        assertTrue(evaluated);
        assertEqualValue(PDataType.DECIMAL, new BigDecimal("12468.45"), ptr);

        // Exceeds precision.
        op1 = LiteralExpression.newConstant(new BigDecimal("99999999999999999999999999999999999999"), PDataType.DECIMAL, 38, 0);
        op2 = LiteralExpression.newConstant(new BigDecimal("123"), PDataType.DECIMAL, 3, 0);
        children = Arrays.<Expression>asList(op1, op2);
        e = new DecimalAddExpression(children);
        ptr = new ImmutableBytesWritable();
        try {
            evaluated = e.evaluate(null, ptr);
            fail("Evaluation should have failed");
        } catch (ValueTypeIncompatibleException ex) {
        }

        // Pass since we roll out imposing precisioin and scale.
        op1 = LiteralExpression.newConstant(new BigDecimal("99999999999999999999999999999999999999"), PDataType.DECIMAL, 38, 0);
        op2 = LiteralExpression.newConstant(new BigDecimal("123"), PDataType.DECIMAL, 3, 0);
        op3 = LiteralExpression.newConstant(new BigDecimal("-123"), PDataType.DECIMAL, 3, 0);
        children = Arrays.<Expression>asList(op1, op2, op3);
        e = new DecimalAddExpression(children);
        ptr = new ImmutableBytesWritable();
        evaluated = e.evaluate(null, ptr);
        assertTrue(evaluated);
        assertEqualValue(PDataType.DECIMAL, new BigDecimal("99999999999999999999999999999999999999"), ptr);

        // Exceeds scale.
        op1 = LiteralExpression.newConstant(new BigDecimal("12345678901234567890123456789012345678"), PDataType.DECIMAL, 38, 0);
        op2 = LiteralExpression.newConstant(new BigDecimal("123.45"), PDataType.DECIMAL, 5, 2);
        children = Arrays.<Expression>asList(op1, op2);
        e = new DecimalAddExpression(children);
        ptr = new ImmutableBytesWritable();
        try {
            evaluated = e.evaluate(null, ptr);
            fail("Evaluation should have failed");
        } catch (ValueTypeIncompatibleException ex) {
        }
       
        // Decimal with no precision and scale.
        op1 = LiteralExpression.newConstant(new BigDecimal("9999.1"), PDataType.DECIMAL);
        op2 = LiteralExpression.newConstant(new BigDecimal("1.1111"), PDataType.DECIMAL, 5, 4);
        children = Arrays.<Expression>asList(op1, op2);
        e = new DecimalAddExpression(children);
        ptr = new ImmutableBytesWritable();
        evaluated = e.evaluate(null, ptr);
        assertTrue(evaluated);
        assertEqualValue(PDataType.DECIMAL, new BigDecimal("10000.2111"), ptr);
    }
View Full Code Here


    @Test
    public void testIntPlusDecimal() throws Exception {
        LiteralExpression op1, op2;
        List<Expression> children;
        ImmutableBytesWritable ptr;
        DecimalAddExpression e;
        boolean evaluated;

        op1 = LiteralExpression.newConstant(new BigDecimal("1234.111"), PDataType.DECIMAL);
        assertNull(op1.getScale());
        op2 = LiteralExpression.newConstant(1, PDataType.INTEGER);
        children = Arrays.<Expression>asList(op1, op2);
        e = new DecimalAddExpression(children);
        ptr = new ImmutableBytesWritable();
        evaluated = e.evaluate(null, ptr);
        assertTrue(evaluated);
        assertEqualValue(PDataType.DECIMAL, new BigDecimal("1235.111"), ptr);
    }
View Full Code Here

                    } else {
                        throw TypeMismatchException.newException(type, node.toString());
                    }
                }
                if (theType == PDataType.DECIMAL) {
                    return new DecimalAddExpression(children);
                } else if (theType == PDataType.LONG) {
                    return new LongAddExpression(children);
                } else if (theType == PDataType.DOUBLE) {
                    return new DoubleAddExpression(children);
                } else if (theType == null) {
View Full Code Here

                    } else {
                        throw new TypeMismatchException(type, node.toString());
                    }
                }
                if (theType == PDataType.DECIMAL) {
                    return new DecimalAddExpression(children);
                } else if (theType == PDataType.LONG) {
                    return new LongAddExpression(children);
                } else if (theType == PDataType.DOUBLE) {
                    return new DoubleAddExpression(children);
                } else if (theType == null) {
View Full Code Here

                    } else {
                        throw TypeMismatchException.newException(type, node.toString());
                    }
                }
                if (theType == PDataType.DECIMAL) {
                    return new DecimalAddExpression(children);
                } else if (theType == PDataType.LONG) {
                    return new LongAddExpression(children);
                } else if (theType == PDataType.DOUBLE) {
                    return new DoubleAddExpression(children);
                } else if (theType == null) {
View Full Code Here

    @Test
    public void testDecimalAddition() throws Exception {
        LiteralExpression op1, op2, op3;
        List<Expression> children;
        ImmutableBytesWritable ptr;
        DecimalAddExpression e;
        boolean evaluated;

        op1 = LiteralExpression.newConstant(new BigDecimal("1234567890123456789012345678901"), PDataType.DECIMAL, 31, 0);
        op2 = LiteralExpression.newConstant(new BigDecimal("12345"), PDataType.DECIMAL, 5, 0);
        children = Arrays.<Expression>asList(op1, op2);
        e = new DecimalAddExpression(children);
        ptr = new ImmutableBytesWritable();
        evaluated = e.evaluate(null, ptr);
        assertTrue(evaluated);
        assertEqualValue(PDataType.DECIMAL, new BigDecimal("1234567890123456789012345691246"), ptr);

        op1 = LiteralExpression.newConstant(new BigDecimal("12345"), PDataType.DECIMAL, 5, 0);
        op2 = LiteralExpression.newConstant(new BigDecimal("123.45"), PDataType.DECIMAL, 5, 2);
        children = Arrays.<Expression>asList(op1, op2);
        e = new DecimalAddExpression(children);
        ptr = new ImmutableBytesWritable();
        evaluated = e.evaluate(null, ptr);
        assertTrue(evaluated);
        assertEqualValue(PDataType.DECIMAL, new BigDecimal("12468.45"), ptr);

        // Exceeds precision.
        op1 = LiteralExpression.newConstant(new BigDecimal("99999999999999999999999999999999999999"), PDataType.DECIMAL, 38, 0);
        op2 = LiteralExpression.newConstant(new BigDecimal("123"), PDataType.DECIMAL, 3, 0);
        children = Arrays.<Expression>asList(op1, op2);
        e = new DecimalAddExpression(children);
        ptr = new ImmutableBytesWritable();
        try {
            evaluated = e.evaluate(null, ptr);
            fail("Evaluation should have failed");
        } catch (ValueTypeIncompatibleException ex) {
        }

        // Pass since we roll out imposing precisioin and scale.
        op1 = LiteralExpression.newConstant(new BigDecimal("99999999999999999999999999999999999999"), PDataType.DECIMAL, 38, 0);
        op2 = LiteralExpression.newConstant(new BigDecimal("123"), PDataType.DECIMAL, 3, 0);
        op3 = LiteralExpression.newConstant(new BigDecimal("-123"), PDataType.DECIMAL, 3, 0);
        children = Arrays.<Expression>asList(op1, op2, op3);
        e = new DecimalAddExpression(children);
        ptr = new ImmutableBytesWritable();
        evaluated = e.evaluate(null, ptr);
        assertTrue(evaluated);
        assertEqualValue(PDataType.DECIMAL, new BigDecimal("99999999999999999999999999999999999999"), ptr);

        // Exceeds scale.
        op1 = LiteralExpression.newConstant(new BigDecimal("12345678901234567890123456789012345678"), PDataType.DECIMAL, 38, 0);
        op2 = LiteralExpression.newConstant(new BigDecimal("123.45"), PDataType.DECIMAL, 5, 2);
        children = Arrays.<Expression>asList(op1, op2);
        e = new DecimalAddExpression(children);
        ptr = new ImmutableBytesWritable();
        try {
            evaluated = e.evaluate(null, ptr);
            fail("Evaluation should have failed");
        } catch (ValueTypeIncompatibleException ex) {
        }
       
        // Decimal with no precision and scale.
        op1 = LiteralExpression.newConstant(new BigDecimal("9999.1"), PDataType.DECIMAL);
        op2 = LiteralExpression.newConstant(new BigDecimal("1.1111"), PDataType.DECIMAL, 5, 4);
        children = Arrays.<Expression>asList(op1, op2);
        e = new DecimalAddExpression(children);
        ptr = new ImmutableBytesWritable();
        evaluated = e.evaluate(null, ptr);
        assertTrue(evaluated);
        assertEqualValue(PDataType.DECIMAL, new BigDecimal("10000.2111"), ptr);
    }
View Full Code Here

    @Test
    public void testIntPlusDecimal() throws Exception {
        LiteralExpression op1, op2;
        List<Expression> children;
        ImmutableBytesWritable ptr;
        DecimalAddExpression e;
        boolean evaluated;

        op1 = LiteralExpression.newConstant(new BigDecimal("1234.111"), PDataType.DECIMAL);
        assertEquals(Integer.valueOf(3),op1.getScale());
        op2 = LiteralExpression.newConstant(1, PDataType.INTEGER);
        children = Arrays.<Expression>asList(op1, op2);
        e = new DecimalAddExpression(children);
        ptr = new ImmutableBytesWritable();
        evaluated = e.evaluate(null, ptr);
        assertTrue(evaluated);
        assertEqualValue(PDataType.DECIMAL, new BigDecimal("1235.111"), ptr);
    }
View Full Code Here

                    } else {
                        throw TypeMismatchException.newException(type, node.toString());
                    }
                }
                if (theType == PDataType.DECIMAL) {
                    return new DecimalAddExpression(children);
                } else if (theType == PDataType.LONG) {
                    return new LongAddExpression(children);
                } else if (theType == PDataType.DOUBLE) {
                    return new DoubleAddExpression(children);
                } else if (theType == null) {
View Full Code Here

TOP

Related Classes of org.apache.phoenix.expression.DecimalAddExpression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.