use of org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector in project hive by apache.
the class TestVectorTypeCasts method getBatchDecimalTimestamp.
private VectorizedRowBatch getBatchDecimalTimestamp(double[] doubleValues) {
VectorizedRowBatch b = new VectorizedRowBatch(2);
DecimalColumnVector dv;
b.cols[0] = dv = new DecimalColumnVector(doubleValues.length, HiveDecimal.SYSTEM_DEFAULT_PRECISION, HiveDecimal.SYSTEM_DEFAULT_SCALE);
b.cols[1] = new TimestampColumnVector(doubleValues.length);
dv.noNulls = true;
Random r = new Random(94830);
for (int i = 0; i < doubleValues.length; i++) {
long millis = RandomTypeUtil.randomMillis(r);
Timestamp ts = new Timestamp(millis);
int nanos = RandomTypeUtil.randomNanos(r);
ts.setNanos(nanos);
TimestampWritable tsw = new TimestampWritable(ts);
double asDouble = tsw.getDouble();
doubleValues[i] = asDouble;
HiveDecimal hiveDecimal = HiveDecimal.create(new BigDecimal(asDouble));
dv.set(i, hiveDecimal);
}
b.size = doubleValues.length;
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() {
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 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() {
VectorizedRowBatch b = getBatchDecimalLong();
VectorExpression expr = new CastDecimalToBoolean(0, 1);
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 VectorizedRowGroupGenUtil method generateDecimalColumnVector.
public static DecimalColumnVector generateDecimalColumnVector(DecimalTypeInfo typeInfo, boolean nulls, boolean repeating, int size, Random rand) {
DecimalColumnVector dcv = new DecimalColumnVector(size, typeInfo.precision(), typeInfo.scale());
dcv.noNulls = !nulls;
dcv.isRepeating = repeating;
HiveDecimalWritable repeatingValue = new HiveDecimalWritable();
do {
repeatingValue.set(HiveDecimal.create(((Double) rand.nextDouble()).toString()).setScale((short) typeInfo.scale(), HiveDecimal.ROUND_HALF_UP));
} while (repeatingValue.getHiveDecimal().doubleValue() == 0);
int nullFrequency = generateNullFrequency(rand);
for (int i = 0; i < size; i++) {
if (nulls && (repeating || i % nullFrequency == 0)) {
dcv.isNull[i] = true;
dcv.vector[i] = null;
} else {
dcv.isNull[i] = false;
if (repeating) {
dcv.vector[i].set(repeatingValue);
} else {
dcv.vector[i].set(HiveDecimal.create(((Double) rand.nextDouble()).toString()).setScale((short) typeInfo.scale(), HiveDecimal.ROUND_HALF_UP));
}
if (dcv.vector[i].getHiveDecimal().doubleValue() == 0) {
i--;
}
}
}
return dcv;
}
Aggregations