Package org.apache.hadoop.hive.ql.exec.vector.expressions.gen

Examples of org.apache.hadoop.hive.ql.exec.vector.expressions.gen.DecimalColDivideDecimalColumn


    VectorizedRowBatch b = getVectorizedRowBatch3DecimalCols();
    DecimalColumnVector in1 = (DecimalColumnVector) b.cols[1];
    for (int i = 0; i < 3; i++) {
      in1.vector[i] = new Decimal128("0.50", (short) 2);
    }
    VectorExpression expr = new DecimalColDivideDecimalColumn(0, 1, 2);
    expr.evaluate(b);
    DecimalColumnVector r = (DecimalColumnVector) b.cols[2];

    // all divides are by 0.50 so the result column is 2 times col 0.
    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 null on left
    b.cols[0].noNulls = false;
    b.cols[0].isNull[0] = true;
    expr.evaluate(b);
    assertFalse(r.noNulls);
    assertTrue(r.isNull[0]);

    // test null on right
    b = getVectorizedRowBatch3DecimalCols();
    b.cols[1].noNulls = false;
    b.cols[1].isNull[0] = true;
    r = (DecimalColumnVector) b.cols[2];
    expr.evaluate(b);
    assertFalse(r.noNulls);
    assertTrue(r.isNull[0]);

    // test null on both sides
    b = getVectorizedRowBatch3DecimalCols();
    b.cols[0].noNulls = false;
    b.cols[0].isNull[0] = true;
    b.cols[1].noNulls = false;
    b.cols[1].isNull[0] = true;
    expr.evaluate(b);
    assertFalse(r.noNulls);
    assertTrue(r.isNull[0]);
    assertFalse(r.isNull[1]);
    assertFalse(r.isNull[2]);

    // test repeating on left
    b = getVectorizedRowBatch3DecimalCols();
    b.cols[0].isRepeating = true;
    expr.evaluate(b);
    r = (DecimalColumnVector) b.cols[2];
    assertTrue(r.vector[2].equals(new Decimal128("1.20", (short) 2)));

    // test repeating on right
    b = getVectorizedRowBatch3DecimalCols();
    b.cols[1].isRepeating = true;
    expr.evaluate(b);
    r = (DecimalColumnVector) b.cols[2];
    assertTrue(r.vector[2].equals(new Decimal128("0", (short) 2)));

    // test both repeating
    b = getVectorizedRowBatch3DecimalCols();
    b.cols[0].isRepeating = true;
    b.cols[1].isRepeating = true;
    expr.evaluate(b);
    r = (DecimalColumnVector) b.cols[2];
    assertTrue(r.isRepeating);
    assertTrue(r.vector[0].equals(new Decimal128("1.20", (short) 2)));

    // test zero-divide to show it results in NULL
    b = getVectorizedRowBatch3DecimalCols();
    ((DecimalColumnVector) b.cols[1]).vector[0].update(0);
    expr.evaluate(b);
    r = (DecimalColumnVector) b.cols[2];
    assertFalse(r.noNulls);
    assertTrue(r.isNull[0]);
  }
View Full Code Here


    VectorizedRowBatch b = getVectorizedRowBatch3DecimalCols();
    DecimalColumnVector in1 = (DecimalColumnVector) b.cols[1];
    for (int i = 0; i < 3; i++) {
      in1.vector[i].set(HiveDecimal.create("0.50"));
    }
    VectorExpression expr = new DecimalColDivideDecimalColumn(0, 1, 2);
    expr.evaluate(b);
    DecimalColumnVector r = (DecimalColumnVector) b.cols[2];

    // all divides are by 0.50 so the result column is 2 times col 0.
    assertTrue(r.vector[0].getHiveDecimal().equals(HiveDecimal.create("2.4")));
    assertTrue(r.vector[1].getHiveDecimal().equals(HiveDecimal.create("-6.6")));
    assertTrue(r.vector[2].getHiveDecimal().equals(HiveDecimal.create("0")));

    // test null on left
    b.cols[0].noNulls = false;
    b.cols[0].isNull[0] = true;
    expr.evaluate(b);
    assertFalse(r.noNulls);
    assertTrue(r.isNull[0]);

    // test null on right
    b = getVectorizedRowBatch3DecimalCols();
    b.cols[1].noNulls = false;
    b.cols[1].isNull[0] = true;
    r = (DecimalColumnVector) b.cols[2];
    expr.evaluate(b);
    assertFalse(r.noNulls);
    assertTrue(r.isNull[0]);

    // test null on both sides
    b = getVectorizedRowBatch3DecimalCols();
    b.cols[0].noNulls = false;
    b.cols[0].isNull[0] = true;
    b.cols[1].noNulls = false;
    b.cols[1].isNull[0] = true;
    expr.evaluate(b);
    assertFalse(r.noNulls);
    assertTrue(r.isNull[0]);
    assertFalse(r.isNull[1]);
    assertFalse(r.isNull[2]);

    // test repeating on left
    b = getVectorizedRowBatch3DecimalCols();
    b.cols[0].isRepeating = true;
    expr.evaluate(b);
    r = (DecimalColumnVector) b.cols[2];
    assertTrue(r.vector[2].getHiveDecimal().equals(HiveDecimal.create("1.2")));

    // test repeating on right
    b = getVectorizedRowBatch3DecimalCols();
    b.cols[1].isRepeating = true;
    expr.evaluate(b);
    r = (DecimalColumnVector) b.cols[2];
    assertTrue(r.vector[2].getHiveDecimal().equals(HiveDecimal.create("0")));

    // test both repeating
    b = getVectorizedRowBatch3DecimalCols();
    b.cols[0].isRepeating = true;
    b.cols[1].isRepeating = true;
    expr.evaluate(b);
    r = (DecimalColumnVector) b.cols[2];
    assertTrue(r.isRepeating);
    assertTrue(r.vector[0].getHiveDecimal().equals(HiveDecimal.create("1.2")));

    // test zero-divide to show it results in NULL
    b = getVectorizedRowBatch3DecimalCols();
    ((DecimalColumnVector) b.cols[1]).vector[0].set(HiveDecimal.create("0"));
    expr.evaluate(b);
    r = (DecimalColumnVector) b.cols[2];
    assertFalse(r.noNulls);
    assertTrue(r.isNull[0]);
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.ql.exec.vector.expressions.gen.DecimalColDivideDecimalColumn

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.