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()));
}
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()));
}
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]);
}
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);
}
}
}
}
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);
}
}
Aggregations