use of org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector in project hive by apache.
the class TestVectorTypeCasts method getBatchLongDecimalPrec5Scale2.
/**
* This batch has output decimal column precision 5 and scale 2.
* The goal is to allow testing of input long values that, when
* converted to decimal, will not fit in the given precision.
* Then it will be possible to check that the results are NULL.
*/
private VectorizedRowBatch getBatchLongDecimalPrec5Scale2() {
VectorizedRowBatch b = new VectorizedRowBatch(2);
LongColumnVector lv;
b.cols[0] = lv = new LongColumnVector();
b.cols[1] = new DecimalColumnVector(5, 2);
lv.vector[0] = 0;
lv.vector[1] = -1;
lv.vector[2] = 99999999999999L;
return b;
}
use of org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector in project hive by apache.
the class TestVectorTypeCasts method testCastLongToDecimal.
@Test
public void testCastLongToDecimal() throws HiveException {
VectorizedRowBatch b = getBatchLongDecimal();
VectorExpression expr = new CastLongToDecimal(0, 1);
expr.evaluate(b);
DecimalColumnVector r = (DecimalColumnVector) b.cols[1];
assertTrue(r.vector[0].getHiveDecimal().equals(HiveDecimal.create("0")));
assertTrue(r.vector[1].getHiveDecimal().equals(HiveDecimal.create("-1")));
assertTrue(r.vector[2].getHiveDecimal().equals(HiveDecimal.create("99999999999999")));
}
use of org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector in project hive by apache.
the class TestVectorTypeCasts method getBatchStringDecimal.
private VectorizedRowBatch getBatchStringDecimal() {
VectorizedRowBatch b = new VectorizedRowBatch(2);
BytesColumnVector bv;
b.cols[0] = bv = new BytesColumnVector();
b.cols[1] = new DecimalColumnVector(18, 2);
bv.initBuffer();
byte[] x0 = toBytes("1.10");
byte[] x1 = toBytes("-2.20");
byte[] x2 = toBytes("99999999999999.0");
bv.setVal(0, x0, 0, x0.length);
bv.setVal(1, x1, 0, x1.length);
bv.setVal(2, x2, 0, x2.length);
return b;
}
use of org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector in project hive by apache.
the class TestVectorTypeCasts method testCastDecimalToBoolean.
@Test
public /**
* Just spot check the basic case because code path is the same as
* for cast of decimal to long due to inheritance.
*/
void testCastDecimalToBoolean() throws HiveException {
VectorizedRowBatch b = getBatchDecimalLong();
VectorExpression expr = new CastDecimalToBoolean(0, 1);
expr.setInputTypeInfos(new TypeInfo[] { TypeInfoFactory.decimalTypeInfo });
expr.setOutputTypeInfo(TypeInfoFactory.booleanTypeInfo);
expr.transientInit(hiveConf);
DecimalColumnVector in = (DecimalColumnVector) b.cols[0];
in.vector[1].set(HiveDecimal.create(0));
expr.evaluate(b);
LongColumnVector r = (LongColumnVector) b.cols[1];
assertEquals(1, r.vector[0]);
assertEquals(0, r.vector[1]);
assertEquals(1, r.vector[2]);
}
use of org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector in project hive by apache.
the class TestVectorTypeCasts method testCastDoubleToDecimal.
@Test
public void testCastDoubleToDecimal() throws HiveException {
VectorizedRowBatch b = getBatchDoubleDecimal();
VectorExpression expr = new CastDoubleToDecimal(0, 1);
expr.evaluate(b);
DecimalColumnVector r = (DecimalColumnVector) b.cols[1];
HiveDecimal hd0 = HiveDecimal.create("0.0");
if (!hd0.equals(r.vector[0].getHiveDecimal())) {
assertTrue(false);
}
HiveDecimal hd1 = HiveDecimal.create("-1.0");
if (!hd1.equals(r.vector[1].getHiveDecimal())) {
assertTrue(false);
}
HiveDecimal hd2 = HiveDecimal.create("99999999999999");
if (!hd2.equals(r.vector[2].getHiveDecimal())) {
assertTrue(false);
}
}
Aggregations