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

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


  public void testCastStringToDecimal() {
    VectorizedRowBatch b = getBatchStringDecimal();
    VectorExpression expr = new CastStringToDecimal(0, 1);
    expr.evaluate(b);
    DecimalColumnVector r = (DecimalColumnVector) b.cols[1];
    assertTrue(r.vector[0].equals(new Decimal128("1.10", r.scale)));
    assertTrue(r.vector[1].equals(new Decimal128("-2.20", r.scale)));
    assertTrue(r.vector[2].equals(new Decimal128("99999999999999.0", r.scale)));
  }
View Full Code Here


    VectorExpression expr = new CastTimestampToDecimal(0, 1);
    LongColumnVector inL = (LongColumnVector) b.cols[0];
    inL.vector[1] = -1990000000L;
    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.99", (short) 2)));
    assertTrue(r.vector[2].equals(new Decimal128("100000.00", (short) 2)));

    // Try again with a value that won't fit in 5 digits, to make
    // sure that NULL is produced.
    b = getBatchLongDecimalPrec5Scale2();
    expr.evaluate(b);
View Full Code Here

    // test casting from one precision and scale to another.
    VectorizedRowBatch b = getBatchDecimalDecimal();
    VectorExpression expr = new CastDecimalToDecimal(0, 1);
    expr.evaluate(b);
    DecimalColumnVector r = (DecimalColumnVector) b.cols[1];
    assertTrue(r.vector[0].equals(new Decimal128("10.00", (short) 2)));
    assertFalse(r.noNulls);
    assertTrue(r.isNull[1]);

    // test an increase in precision/scale
    b = getBatchDecimalDecimal();
    expr = new CastDecimalToDecimal(1, 0);
    expr.evaluate(b);
    r = (DecimalColumnVector) b.cols[0];
    assertTrue(r.vector[0].equals(new Decimal128("100.01", (short) 4)));
    assertTrue(r.vector[1].equals(new Decimal128("-200.02", (short) 4)));
    assertTrue(r.noNulls);
  }
View Full Code Here

    DecimalColumnVector v0, v1;
    b.cols[0] = v0 = new DecimalColumnVector(18, 4);
    b.cols[1] = v1 = new DecimalColumnVector(5, 2);

    v0.vector[0].update(new Decimal128("10.0001", (short) 4));
    v0.vector[1].update(new Decimal128("-9999999.9999", (short) 4));

    v1.vector[0].update(new Decimal128("100.01", (short) 2));
    v1.vector[1].update(new Decimal128("-200.02", (short) 2));

    b.size = 2;
    return b;
  }
View Full Code Here

   * multiple cases because the logic is the same for <, >, <=, >=, == and !=.
   */
  @Test
  public void testFilterDecimalColEqualDecimalScalar() {
    VectorizedRowBatch b = getVectorizedRowBatch1DecimalCol();
    Decimal128 scalar = new Decimal128();
    scalar.update("-3.30", (short) 2);
    VectorExpression expr = new FilterDecimalColEqualDecimalScalar(0, scalar);
    expr.evaluate(b);

    // check that right row(s) are selected
    assertTrue(b.selectedInUse);
View Full Code Here

   * cases because the logic is the same for <, >, <=, >=, == and !=.
   */
  @Test
  public void testFilterDecimalScalarEqualDecimalColumn() {
    VectorizedRowBatch b = getVectorizedRowBatch1DecimalCol();
    Decimal128 scalar = new Decimal128();
    scalar.update("-3.30", (short) 2);
    VectorExpression expr = new FilterDecimalScalarEqualDecimalColumn(scalar, 0);
    expr.evaluate(b);

    // check that right row(s) are selected
    assertTrue(b.selectedInUse);
View Full Code Here

   * Spot check col < scalar for decimal.
   */
  @Test
  public void testFilterDecimalColLessScalar() {
    VectorizedRowBatch b = getVectorizedRowBatch1DecimalCol();
    Decimal128 scalar = new Decimal128();
    scalar.update("0", (short) 2);
    VectorExpression expr = new FilterDecimalColLessDecimalScalar(0, scalar);
    expr.evaluate(b);

    // check that right row(s) are selected
    assertTrue(b.selectedInUse);
View Full Code Here

   * Spot check scalar > col for decimal.
   */
  @Test
  public void testFilterDecimalScalarGreaterThanColumn() {
    VectorizedRowBatch b = getVectorizedRowBatch1DecimalCol();
    Decimal128 scalar = new Decimal128();
    scalar.update("0", (short) 2);
    VectorExpression expr = new FilterDecimalScalarGreaterDecimalColumn(scalar, 0);
    expr.evaluate(b);

    // check that right row(s) are selected
    assertTrue(b.selectedInUse);
View Full Code Here

  }

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

    Decimal128 d2 = new Decimal128(-25.34567, (short) 5);
    Decimal128 expected2 = new Decimal128(25.34567, (short)5);
    DecimalUtil.abs(0, d2, dcv);
    Assert.assertEquals(0, expected2.compareTo(dcv.vector[0]));
  }
View Full Code Here

  }

  @Test
  public void testRound() {
    DecimalColumnVector dcv = new DecimalColumnVector(4 ,20, 0);
    Decimal128 d1 = new Decimal128(19.56778, (short) 5);
    Decimal128 expected1 = new Decimal128(20, (short)0);
    DecimalUtil.round(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.round(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.round(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.round(0, d4, dcv);
    Assert.assertEquals(0, expected4.compareTo(dcv.vector[0]));

    Decimal128 d5 = new Decimal128(19.36778, (short) 5);
    Decimal128 expected5 = new Decimal128(19, (short)0);
    DecimalUtil.round(0, d5, dcv);
    Assert.assertEquals(0, expected5.compareTo(dcv.vector[0]));

    Decimal128 d6 = new Decimal128(-25.54567, (short) 5);
    Decimal128 expected6 = new Decimal128(-26, (short)0);
    DecimalUtil.round(0, d6, dcv);
    Assert.assertEquals(0, expected6.compareTo(dcv.vector[0]));
  }
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.