Package org.apache.phoenix.expression

Examples of org.apache.phoenix.expression.DecimalDivideExpression


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

        // The value should be 1234500.0000...00 because we set to scale to be 24. However, in
        // PhoenixResultSet.getBigDecimal, the case to (BigDecimal) actually cause the scale to be eradicated. As
        // a result, the resulting value does not have the right form.
        op1 = LiteralExpression.newConstant(new BigDecimal("12345"), PDataType.DECIMAL, 5, 0);
        op2 = LiteralExpression.newConstant(new BigDecimal("0.01"), PDataType.DECIMAL, 2, 2);
        children = Arrays.<Expression>asList(op1, op2);
        e = new DecimalDivideExpression(children);
        ptr = new ImmutableBytesWritable();
        evaluated = e.evaluate(null, ptr);
        assertTrue(evaluated);
        assertEqualValue(PDataType.DECIMAL, new BigDecimal("1.2345E+6"), ptr);

        // Exceeds precision.
        op1 = LiteralExpression.newConstant(new BigDecimal("12345678901234567890123456789012345678"), PDataType.DECIMAL, 38, 0);
        op2 = LiteralExpression.newConstant(new BigDecimal("0.01"), PDataType.DECIMAL, 2, 2);
        children = Arrays.<Expression>asList(op1, op2);
        e = new DecimalDivideExpression(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("10"), PDataType.DECIMAL);
        op2 = LiteralExpression.newConstant(new BigDecimal("3"), PDataType.DECIMAL, 5, 4);
        assertEquals(Integer.valueOf(4),op2.getScale());
        children = Arrays.<Expression>asList(op1, op2);
        e = new DecimalDivideExpression(children);
        ptr = new ImmutableBytesWritable();
        evaluated = e.evaluate(null, ptr);
        assertTrue(evaluated);
        assertEqualValue(PDataType.DECIMAL, new BigDecimal("3.3333333333333333333333333333333333333"), ptr);
    }
View Full Code Here


                        throw TypeMismatchException.newException(type, node.toString());
                    }
                }
                switch (theType) {
                case DECIMAL:
                    return new DecimalDivideExpression( children);
                case LONG:
                    return new LongDivideExpression( children);
                case DOUBLE:
                    return new DoubleDivideExpression(children);
                default:
View Full Code Here

                        throw new TypeMismatchException(type, node.toString());
                    }
                }
                switch (theType) {
                case DECIMAL:
                    return new DecimalDivideExpression( children);
                case LONG:
                    return new LongDivideExpression( children);
                case DOUBLE:
                    return new DoubleDivideExpression(children);
                default:
View Full Code Here

                        throw TypeMismatchException.newException(type, node.toString());
                    }
                }
                switch (theType) {
                case DECIMAL:
                    return new DecimalDivideExpression( children);
                case LONG:
                    return new LongDivideExpression( children);
                case DOUBLE:
                    return new DoubleDivideExpression(children);
                default:
View Full Code Here

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

        // The value should be 1234500.0000...00 because we set to scale to be 24. However, in
        // PhoenixResultSet.getBigDecimal, the case to (BigDecimal) actually cause the scale to be eradicated. As
        // a result, the resulting value does not have the right form.
        op1 = LiteralExpression.newConstant(new BigDecimal("12345"), PDataType.DECIMAL, 5, 0);
        op2 = LiteralExpression.newConstant(new BigDecimal("0.01"), PDataType.DECIMAL, 2, 2);
        children = Arrays.<Expression>asList(op1, op2);
        e = new DecimalDivideExpression(children);
        ptr = new ImmutableBytesWritable();
        evaluated = e.evaluate(null, ptr);
        assertTrue(evaluated);
        assertEqualValue(PDataType.DECIMAL, new BigDecimal("1.2345E+6"), ptr);

        // Exceeds precision.
        op1 = LiteralExpression.newConstant(new BigDecimal("12345678901234567890123456789012345678"), PDataType.DECIMAL, 38, 0);
        op2 = LiteralExpression.newConstant(new BigDecimal("0.01"), PDataType.DECIMAL, 2, 2);
        children = Arrays.<Expression>asList(op1, op2);
        e = new DecimalDivideExpression(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("10"), PDataType.DECIMAL);
        op2 = LiteralExpression.newConstant(new BigDecimal("3"), PDataType.DECIMAL, 5, 4);
        assertEquals(Integer.valueOf(4),op2.getScale());
        children = Arrays.<Expression>asList(op1, op2);
        e = new DecimalDivideExpression(children);
        ptr = new ImmutableBytesWritable();
        evaluated = e.evaluate(null, ptr);
        assertTrue(evaluated);
        assertEqualValue(PDataType.DECIMAL, new BigDecimal("3.3333333333333333333333333333333333333"), ptr);
    }
View Full Code Here

                        throw TypeMismatchException.newException(type, node.toString());
                    }
                }
                switch (theType) {
                case DECIMAL:
                    return new DecimalDivideExpression( children);
                case LONG:
                    return new LongDivideExpression( children);
                case DOUBLE:
                    return new DoubleDivideExpression(children);
                default:
View Full Code Here

TOP

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

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.