Package org.apache.hadoop.hive.common.type

Examples of org.apache.hadoop.hive.common.type.Decimal128


   * addition checks all the cases for the template, so don't do that redundantly here.
   */
  @Test
  public void testDecimalColSubtractDecimalScalar() {
    VectorizedRowBatch b = getVectorizedRowBatch3DecimalCols();
    Decimal128 d = new Decimal128(1);
    VectorExpression expr = new DecimalColSubtractDecimalScalar(0, d, 2);

    // test without nulls
    expr.evaluate(b);
    DecimalColumnVector r = (DecimalColumnVector) b.cols[2];
    assertTrue(r.vector[0].equals(new Decimal128("0.20", (short) 2)));
    assertTrue(r.vector[1].equals(new Decimal128("-4.30", (short) 2)));
    assertTrue(r.vector[2].equals(new Decimal128("-1.00", (short) 2)));

    // test that underflow produces null
    b = getVectorizedRowBatch3DecimalCols();
    DecimalColumnVector in = (DecimalColumnVector) b.cols[0];
    in.vector[0].update("-9999999999999999.99", (short) 2); // set to min possible value
View Full Code Here


   * addition checks all the cases for the template, so don't do that redundantly here.
   */
  @Test
  public void testDecimalColMultiplyDecimalScalar() {
    VectorizedRowBatch b = getVectorizedRowBatch3DecimalCols();
    Decimal128 d = new Decimal128(2);
    VectorExpression expr = new DecimalColMultiplyDecimalScalar(0, d, 2);

    // test without nulls
    expr.evaluate(b);
    DecimalColumnVector r = (DecimalColumnVector) b.cols[2];
    assertTrue(r.vector[0].equals(new Decimal128("2.40", (short) 2)));
    assertTrue(r.vector[1].equals(new Decimal128("-6.60", (short) 2)));
    assertTrue(r.vector[2].equals(new Decimal128("0", (short) 2)));

    // test that overflow produces null
    b = getVectorizedRowBatch3DecimalCols();
    DecimalColumnVector in = (DecimalColumnVector) b.cols[0];
    in.vector[0].update("9999999999999999.99", (short) 2); // set to max possible value
View Full Code Here

   * cases used in the source code template ScalarArithmeticColumnDecimal.txt.
   */
  @Test
  public void testDecimalScalarAddDecimalColumn() {
    VectorizedRowBatch b = getVectorizedRowBatch3DecimalCols();
    Decimal128 d = new Decimal128(1);
    VectorExpression expr = new DecimalScalarAddDecimalColumn(d, 0, 2);

    // test without nulls
    expr.evaluate(b);
    DecimalColumnVector r = (DecimalColumnVector) b.cols[2];
    assertTrue(r.vector[0].equals(new Decimal128("2.20", (short) 2)));
    assertTrue(r.vector[1].equals(new Decimal128("-2.30", (short) 2)));
    assertTrue(r.vector[2].equals(new Decimal128("1.00", (short) 2)));

    // test null propagation
    b = getVectorizedRowBatch3DecimalCols();
    DecimalColumnVector in = (DecimalColumnVector) b.cols[0];
    r = (DecimalColumnVector) b.cols[2];
    in.noNulls = false;
    in.isNull[0] = true;
    expr.evaluate(b);
    assertTrue(!r.noNulls);
    assertTrue(r.isNull[0]);

    // test repeating case, no nulls
    b = getVectorizedRowBatch3DecimalCols();
    in = (DecimalColumnVector) b.cols[0];
    in.isRepeating = true;
    expr.evaluate(b);
    r = (DecimalColumnVector) b.cols[2];
    assertTrue(r.isRepeating);
    assertTrue(r.vector[0].equals(new Decimal128("2.20", (short) 2)));

    // test repeating case for null value
    b = getVectorizedRowBatch3DecimalCols();
    in = (DecimalColumnVector) b.cols[0];
    in.isRepeating = true;
View Full Code Here

   * addition checks all the cases for the template, so don't do that redundantly here.
   */
  @Test
  public void testDecimalScalarSubtractDecimalColumn() {
    VectorizedRowBatch b = getVectorizedRowBatch3DecimalCols();
    Decimal128 d = new Decimal128(1);
    VectorExpression expr = new DecimalScalarSubtractDecimalColumn(d, 0, 2);

    // test without nulls
    expr.evaluate(b);
    DecimalColumnVector r = (DecimalColumnVector) b.cols[2];
    assertTrue(r.vector[0].equals(new Decimal128("-0.20", (short) 2)));
    assertTrue(r.vector[1].equals(new Decimal128("4.30", (short) 2)));
    assertTrue(r.vector[2].equals(new Decimal128("1.00", (short) 2)));

    // test that overflow produces null
    b = getVectorizedRowBatch3DecimalCols();
    DecimalColumnVector in = (DecimalColumnVector) b.cols[0];
    in.vector[0].update("-9999999999999999.99", (short) 2); // set to min possible value
View Full Code Here

   */

  @Test
  public void testDecimalScalarMultiplyDecimalColumn() {
    VectorizedRowBatch b = getVectorizedRowBatch3DecimalCols();
    Decimal128 d = new Decimal128(2);
    VectorExpression expr = new DecimalScalarMultiplyDecimalColumn(d, 0, 2);

    // test without nulls
    expr.evaluate(b);
    DecimalColumnVector r = (DecimalColumnVector) b.cols[2];
    assertTrue(r.vector[0].equals(new Decimal128("2.40", (short) 2)));
    assertTrue(r.vector[1].equals(new Decimal128("-6.60", (short) 2)));
    assertTrue(r.vector[2].equals(new Decimal128("0", (short) 2)));

    // test that overflow produces null
    b = getVectorizedRowBatch3DecimalCols();
    DecimalColumnVector in = (DecimalColumnVector) b.cols[0];
    in.vector[0].update("9999999999999999.99", (short) 2); // set to max possible value
View Full Code Here

  public void testConstantExpression() {
    ConstantVectorExpression longCve = new ConstantVectorExpression(0, 17);
    ConstantVectorExpression doubleCve = new ConstantVectorExpression(1, 17.34);
    String str = "alpha";
    ConstantVectorExpression bytesCve = new ConstantVectorExpression(2, str.getBytes());
    Decimal128 decVal = new Decimal128(25.8, (short) 1);
    ConstantVectorExpression decimalCve = new ConstantVectorExpression(3, decVal);

    int size = 20;
    VectorizedRowBatch vrg = VectorizedRowGroupGenUtil.getVectorizedRowBatch(size, 4, 0);

    LongColumnVector lcv = (LongColumnVector) vrg.cols[0];
    DoubleColumnVector dcv = new DoubleColumnVector(size);
    BytesColumnVector bcv = new BytesColumnVector(size);
    DecimalColumnVector dv = new DecimalColumnVector(5, 1);
    vrg.cols[1] = dcv;
    vrg.cols[2] = bcv;
    vrg.cols[3] = dv;

    longCve.evaluate(vrg);
    doubleCve.evaluate(vrg);
    bytesCve.evaluate(vrg)
    decimalCve.evaluate(vrg);
    assertTrue(lcv.isRepeating);
    assertTrue(dcv.isRepeating);
    assertTrue(bcv.isRepeating);
    assertEquals(17, lcv.vector[0]);
    assertTrue(17.34 == dcv.vector[0]);
   
    byte[] alphaBytes = "alpha".getBytes();
    assertTrue(bcv.length[0] == alphaBytes.length);
    assertTrue(sameFirstKBytes(alphaBytes, bcv.vector[0], alphaBytes.length));
    // Evaluation of the bytes Constant Vector Expression after the vector is
    // modified.
    ((BytesColumnVector) (vrg.cols[2])).vector[0] = "beta".getBytes();
    bytesCve.evaluate(vrg)
    assertTrue(bcv.length[0] == alphaBytes.length);
    assertTrue(sameFirstKBytes(alphaBytes, bcv.vector[0], alphaBytes.length));

    assertTrue(25.8 == dv.vector[0].doubleValue());
    // Evaluation of the decimal Constant Vector Expression after the vector is
    // modified.   
    ((DecimalColumnVector) (vrg.cols[3])).vector[0] = new Decimal128(39.7, (short) 1);
    decimalCve.evaluate(vrg);
    assertTrue(25.8 == dv.vector[0].doubleValue());   
  }
View Full Code Here

public class TestDecimalUtil {

  @Test
  public void testFloor() {
    DecimalColumnVector dcv = new DecimalColumnVector(4 ,20, 13);
    Decimal128 d1 = new Decimal128(19.56778, (short) 5);
    Decimal128 expected1 = new Decimal128(19, (short)0);
    DecimalUtil.floor(0, d1, dcv);
    Assert.assertEquals(0, expected1.compareTo(dcv.vector[0]));

    Decimal128 d2 = new Decimal128(23.0, (short) 5);
    Decimal128 expected2 = new Decimal128(23, (short)0);
    DecimalUtil.floor(0, d2, dcv);
    Assert.assertEquals(0, expected2.compareTo(dcv.vector[0]));

    Decimal128 d3 = new Decimal128(-25.34567, (short) 5);
    Decimal128 expected3 = new Decimal128(-26, (short)0);
    DecimalUtil.floor(0, d3, dcv);
    Assert.assertEquals(0, expected3.compareTo(dcv.vector[0]));

    Decimal128 d4 = new Decimal128(-17, (short) 5);
    Decimal128 expected4 = new Decimal128(-17, (short)0);
    DecimalUtil.floor(0, d4, dcv);
    Assert.assertEquals(0, expected4.compareTo(dcv.vector[0]));

    Decimal128 d5 = new Decimal128(-0.3, (short) 5);
    Decimal128 expected5 = new Decimal128(-1, (short)0);
    DecimalUtil.floor(0, d5, dcv);
    Assert.assertEquals(0, expected5.compareTo(dcv.vector[0]));

    Decimal128 d6 = new Decimal128(0.3, (short) 5);
    Decimal128 expected6 = new Decimal128(0, (short)0);
    DecimalUtil.floor(0, d6, dcv);
    Assert.assertEquals(0, expected6.compareTo(dcv.vector[0]));
  }
View Full Code Here

  }

  @Test
  public void testCeiling() {
    DecimalColumnVector dcv = new DecimalColumnVector(4 ,20, 13);
    Decimal128 d1 = new Decimal128(19.56778, (short) 5);
    Decimal128 expected1 = new Decimal128(20, (short)0);
    DecimalUtil.ceiling(0, d1, dcv);
    Assert.assertEquals(0, expected1.compareTo(dcv.vector[0]));

    Decimal128 d2 = new Decimal128(23.0, (short) 5);
    Decimal128 expected2 = new Decimal128(23, (short)0);
    DecimalUtil.ceiling(0, d2, dcv);
    Assert.assertEquals(0, expected2.compareTo(dcv.vector[0]));

    Decimal128 d3 = new Decimal128(-25.34567, (short) 5);
    Decimal128 expected3 = new Decimal128(-25, (short)0);
    DecimalUtil.ceiling(0, d3, dcv);
    Assert.assertEquals(0, expected3.compareTo(dcv.vector[0]));

    Decimal128 d4 = new Decimal128(-17, (short) 5);
    Decimal128 expected4 = new Decimal128(-17, (short)0);
    DecimalUtil.ceiling(0, d4, dcv);
    Assert.assertEquals(0, expected4.compareTo(dcv.vector[0]));

    Decimal128 d5 = new Decimal128(-0.3, (short) 5);
    Decimal128 expected5 = new Decimal128(0, (short)0);
    DecimalUtil.ceiling(0, d5, dcv);
    Assert.assertEquals(0, expected5.compareTo(dcv.vector[0]));

    Decimal128 d6 = new Decimal128(0.3, (short) 5);
    Decimal128 expected6 = new Decimal128(1, (short)0);
    DecimalUtil.ceiling(0, d6, dcv);
    Assert.assertEquals(0, expected6.compareTo(dcv.vector[0]));
  }
View Full Code Here

  public void testCastLongToDecimal() {
    VectorizedRowBatch b = getBatchLongDecimal();
    VectorExpression expr = new CastLongToDecimal(0, 1);
    expr.evaluate(b);
    DecimalColumnVector r = (DecimalColumnVector) b.cols[1];
    assertTrue(r.vector[0].equals(new Decimal128(0, (short) 2)));
    assertTrue(r.vector[1].equals(new Decimal128(-1, (short) 2)));
    assertTrue(r.vector[2].equals(new Decimal128(99999999999999L, (short) 2)));
  }
View Full Code Here

    VectorizedRowBatch b = getBatchDoubleDecimal();
    VectorExpression expr = new CastDoubleToDecimal(0, 1);
    expr.evaluate(b);
    DecimalColumnVector r = (DecimalColumnVector) b.cols[1];

    assertTrue(r.vector[0].equals(new Decimal128(0, r.scale)));
    assertTrue(r.vector[1].equals(new Decimal128(-1, r.scale)));
    assertTrue(r.vector[2].equals(new Decimal128("99999999999999.0", r.scale)));
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.common.type.Decimal128

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.