Search in sources :

Example 56 with DecimalColumnVector

use of org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector in project hive by apache.

the class TestDecimalUtil method testFloor.

@Test
public void testFloor() {
    DecimalColumnVector dcv = new DecimalColumnVector(4, 20, 13);
    HiveDecimal d1 = HiveDecimal.create("19.56778");
    HiveDecimal expected1 = HiveDecimal.create("19");
    DecimalUtil.floor(0, d1, dcv);
    Assert.assertEquals(0, expected1.compareTo(dcv.vector[0].getHiveDecimal()));
    // As of HIVE-8745, these decimal values should be trimmed of trailing zeros.
    HiveDecimal d2 = HiveDecimal.create("23.00000");
    Assert.assertEquals(0, d2.scale());
    HiveDecimal expected2 = HiveDecimal.create("23");
    DecimalUtil.floor(0, d2, dcv);
    Assert.assertEquals(0, expected2.compareTo(dcv.vector[0].getHiveDecimal()));
    HiveDecimal d3 = HiveDecimal.create("-25.34567");
    HiveDecimal expected3 = HiveDecimal.create("-26");
    DecimalUtil.floor(0, d3, dcv);
    Assert.assertEquals(0, expected3.compareTo(dcv.vector[0].getHiveDecimal()));
    HiveDecimal d4 = HiveDecimal.create("-17.00000");
    Assert.assertEquals(0, d4.scale());
    HiveDecimal expected4 = HiveDecimal.create("-17");
    DecimalUtil.floor(0, d4, dcv);
    Assert.assertEquals(0, expected4.compareTo(dcv.vector[0].getHiveDecimal()));
    HiveDecimal d5 = HiveDecimal.create("-0.30000");
    Assert.assertEquals(1, d5.scale());
    HiveDecimal expected5 = HiveDecimal.create("-1");
    DecimalUtil.floor(0, d5, dcv);
    Assert.assertEquals(0, expected5.compareTo(dcv.vector[0].getHiveDecimal()));
    HiveDecimal d6 = HiveDecimal.create("0.30000");
    Assert.assertEquals(1, d6.scale());
    HiveDecimal expected6 = HiveDecimal.create("0");
    DecimalUtil.floor(0, d6, dcv);
    Assert.assertEquals(0, expected6.compareTo(dcv.vector[0].getHiveDecimal()));
}
Also used : DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) HiveDecimal(org.apache.hadoop.hive.common.type.HiveDecimal) Test(org.junit.Test)

Example 57 with DecimalColumnVector

use of org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector in project hive by apache.

the class TestDecimalUtil method testAbs.

@Test
public void testAbs() {
    DecimalColumnVector dcv = new DecimalColumnVector(4, 20, 13);
    HiveDecimal d1 = HiveDecimal.create("19.56778");
    DecimalUtil.abs(0, d1, dcv);
    Assert.assertEquals(0, d1.compareTo(dcv.vector[0].getHiveDecimal()));
    HiveDecimal d2 = HiveDecimal.create("-25.34567");
    HiveDecimal expected2 = HiveDecimal.create("25.34567");
    DecimalUtil.abs(0, d2, dcv);
    Assert.assertEquals(0, expected2.compareTo(dcv.vector[0].getHiveDecimal()));
}
Also used : DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) HiveDecimal(org.apache.hadoop.hive.common.type.HiveDecimal) Test(org.junit.Test)

Example 58 with DecimalColumnVector

use of org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector in project hive by apache.

the class TestVectorArithmeticExpressions method testDecimalColSubtractDecimalScalar.

/* Spot check correctness of decimal column subtract decimal scalar. The case for
   * addition checks all the cases for the template, so don't do that redundantly here.
   */
@Test
public void testDecimalColSubtractDecimalScalar() {
    VectorizedRowBatch b = getVectorizedRowBatch3DecimalCols();
    HiveDecimal d = HiveDecimal.create(1);
    VectorExpression expr = new DecimalColSubtractDecimalScalar(0, d, 2);
    // test without nulls
    expr.evaluate(b);
    DecimalColumnVector r = (DecimalColumnVector) b.cols[2];
    assertTrue(r.vector[0].getHiveDecimal().equals(HiveDecimal.create("0.20")));
    assertTrue(r.vector[1].getHiveDecimal().equals(HiveDecimal.create("-4.30")));
    assertTrue(r.vector[2].getHiveDecimal().equals(HiveDecimal.create("-1")));
    // test that underflow produces null
    b = getVectorizedRowBatch3DecimalCols();
    DecimalColumnVector in = (DecimalColumnVector) b.cols[0];
    // set to min possible value
    in.vector[0].set(HiveDecimal.create("-9999999999999999.99"));
    expr.evaluate(b);
    r = (DecimalColumnVector) b.cols[2];
    assertFalse(r.noNulls);
    assertTrue(r.isNull[0]);
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) TestVectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch) DecimalColSubtractDecimalScalar(org.apache.hadoop.hive.ql.exec.vector.expressions.gen.DecimalColSubtractDecimalScalar) DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) HiveDecimal(org.apache.hadoop.hive.common.type.HiveDecimal) Test(org.junit.Test)

Example 59 with DecimalColumnVector

use of org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector in project hive by apache.

the class VectorUDAFAvgDecimal method aggregateInputSelection.

@Override
public void aggregateInputSelection(VectorAggregationBufferRow[] aggregationBufferSets, int bufferIndex, VectorizedRowBatch batch) throws HiveException {
    int batchSize = batch.size;
    if (batchSize == 0) {
        return;
    }
    inputExpression.evaluate(batch);
    DecimalColumnVector inputVector = (DecimalColumnVector) batch.cols[this.inputExpression.getOutputColumn()];
    HiveDecimalWritable[] vector = inputVector.vector;
    if (inputVector.noNulls) {
        if (inputVector.isRepeating) {
            iterateNoNullsRepeatingWithAggregationSelection(aggregationBufferSets, bufferIndex, vector[0], batchSize);
        } else {
            if (batch.selectedInUse) {
                iterateNoNullsSelectionWithAggregationSelection(aggregationBufferSets, bufferIndex, vector, batch.selected, batchSize);
            } else {
                iterateNoNullsWithAggregationSelection(aggregationBufferSets, bufferIndex, vector, batchSize);
            }
        }
    } else {
        if (inputVector.isRepeating) {
            if (batch.selectedInUse) {
                iterateHasNullsRepeatingSelectionWithAggregationSelection(aggregationBufferSets, bufferIndex, vector[0], batchSize, batch.selected, inputVector.isNull);
            } else {
                iterateHasNullsRepeatingWithAggregationSelection(aggregationBufferSets, bufferIndex, vector[0], batchSize, inputVector.isNull);
            }
        } else {
            if (batch.selectedInUse) {
                iterateHasNullsSelectionWithAggregationSelection(aggregationBufferSets, bufferIndex, vector, batchSize, batch.selected, inputVector.isNull);
            } else {
                iterateHasNullsWithAggregationSelection(aggregationBufferSets, bufferIndex, vector, batchSize, inputVector.isNull);
            }
        }
    }
}
Also used : DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)

Example 60 with DecimalColumnVector

use of org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector in project hive by apache.

the class VectorUDAFAvgDecimal method aggregateInput.

@Override
public void aggregateInput(AggregationBuffer agg, VectorizedRowBatch batch) throws HiveException {
    inputExpression.evaluate(batch);
    DecimalColumnVector inputVector = (DecimalColumnVector) batch.cols[this.inputExpression.getOutputColumn()];
    int batchSize = batch.size;
    if (batchSize == 0) {
        return;
    }
    Aggregation myagg = (Aggregation) agg;
    HiveDecimalWritable[] vector = inputVector.vector;
    if (inputVector.isRepeating) {
        if (inputVector.noNulls) {
            if (myagg.isNull) {
                myagg.isNull = false;
                myagg.sum.setFromLong(0L);
                myagg.count = 0;
            }
            HiveDecimal value = vector[0].getHiveDecimal();
            HiveDecimal multiple = value.multiply(HiveDecimal.create(batchSize));
            myagg.sum.mutateAdd(multiple);
            myagg.count += batchSize;
        }
        return;
    }
    if (!batch.selectedInUse && inputVector.noNulls) {
        iterateNoSelectionNoNulls(myagg, vector, batchSize);
    } else if (!batch.selectedInUse) {
        iterateNoSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull);
    } else if (inputVector.noNulls) {
        iterateSelectionNoNulls(myagg, vector, batchSize, batch.selected);
    } else {
        iterateSelectionHasNulls(myagg, vector, batchSize, inputVector.isNull, batch.selected);
    }
}
Also used : DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) HiveDecimal(org.apache.hadoop.hive.common.type.HiveDecimal)

Aggregations

DecimalColumnVector (org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector)84 VectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch)38 Test (org.junit.Test)28 HiveDecimal (org.apache.hadoop.hive.common.type.HiveDecimal)22 LongColumnVector (org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)20 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)17 DoubleColumnVector (org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector)16 TestVectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.TestVectorizedRowBatch)16 BytesColumnVector (org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)15 TimestampColumnVector (org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector)11 ColumnVector (org.apache.hadoop.hive.ql.exec.vector.ColumnVector)7 TimestampWritable (org.apache.hadoop.hive.serde2.io.TimestampWritable)5 Timestamp (java.sql.Timestamp)4 Random (java.util.Random)4 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)3 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)3 ShortWritable (org.apache.hadoop.hive.serde2.io.ShortWritable)3 BooleanWritable (org.apache.hadoop.io.BooleanWritable)3 IntWritable (org.apache.hadoop.io.IntWritable)3 LongWritable (org.apache.hadoop.io.LongWritable)3