use of org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector in project hive by apache.
the class TestVectorTypeCasts method getBatchDecimalLong2.
private VectorizedRowBatch getBatchDecimalLong2() {
VectorizedRowBatch b = new VectorizedRowBatch(2);
DecimalColumnVector dv;
short scale = 9;
b.cols[0] = dv = new DecimalColumnVector(18, scale);
b.cols[1] = new LongColumnVector();
b.size = 3;
dv.vector[0].set(HiveDecimal.create("1.111111111"));
dv.vector[1].set(HiveDecimal.create("-2.222222222"));
dv.vector[2].set(HiveDecimal.create("31536000.999999999"));
return b;
}
use of org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector in project hive by apache.
the class TestVectorTypeCasts method getBatchDoubleDecimal.
private VectorizedRowBatch getBatchDoubleDecimal() {
VectorizedRowBatch b = new VectorizedRowBatch(2);
DoubleColumnVector dv;
short scale = 2;
b.cols[0] = dv = new DoubleColumnVector();
b.cols[1] = new DecimalColumnVector(18, scale);
b.size = 3;
dv.vector[0] = 0d;
dv.vector[1] = -1d;
dv.vector[2] = 99999999999999.0d;
return b;
}
use of org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector in project hive by apache.
the class TestVectorTypeCasts method getBatchLongDecimal.
private VectorizedRowBatch getBatchLongDecimal() {
VectorizedRowBatch b = new VectorizedRowBatch(2);
LongColumnVector lv;
b.cols[0] = lv = new LongColumnVector();
b.cols[1] = new DecimalColumnVector(18, 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 testCastStringToDecimal.
@Test
public void testCastStringToDecimal() throws HiveException {
VectorizedRowBatch b = getBatchStringDecimal();
VectorExpression expr = new CastStringToDecimal(0, 1);
expr.evaluate(b);
DecimalColumnVector r = (DecimalColumnVector) b.cols[1];
assertTrue(r.vector[0].getHiveDecimal().equals(HiveDecimal.create("1.10")));
assertTrue(r.vector[1].getHiveDecimal().equals(HiveDecimal.create("-2.20")));
assertTrue(r.vector[2].getHiveDecimal().equals(HiveDecimal.create("99999999999999.0")));
}
use of org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector in project hive by apache.
the class TestVectorTypeCasts method testCastTimestampToDecimal.
@Test
public void testCastTimestampToDecimal() throws HiveException {
// The input timestamps are stored as long values
// measured in nanoseconds from the epoch.
HiveDecimal[] hiveDecimalValues = new HiveDecimal[500];
VectorizedRowBatch b = getBatchTimestampDecimal(hiveDecimalValues);
VectorExpression expr = new CastTimestampToDecimal(0, 1);
expr.evaluate(b);
DecimalColumnVector r = (DecimalColumnVector) b.cols[1];
for (int i = 0; i < hiveDecimalValues.length; i++) {
HiveDecimal hiveDecimal = r.vector[i].getHiveDecimal();
HiveDecimal expectedHiveDecimal = hiveDecimalValues[i];
if (!hiveDecimal.equals(expectedHiveDecimal)) {
assertTrue(false);
}
}
// Try again with a value that won't fit in 5 digits, to make
// sure that NULL is produced.
b.cols[1] = r = new DecimalColumnVector(hiveDecimalValues.length, 5, 2);
expr.evaluate(b);
r = (DecimalColumnVector) b.cols[1];
for (int i = 0; i < hiveDecimalValues.length; i++) {
HiveDecimal hiveDecimal = r.vector[i].getHiveDecimal();
HiveDecimal expectedHiveDecimal = hiveDecimalValues[i];
if (HiveDecimal.enforcePrecisionScale(expectedHiveDecimal, 5, 2) == null) {
assertTrue(r.isNull[i]);
} else {
assertTrue(!r.isNull[i]);
if (!hiveDecimal.equals(expectedHiveDecimal)) {
assertTrue(false);
}
}
}
}
Aggregations