use of org.apache.hadoop.hive.ql.exec.vector.util.batchgen.VectorBatchGenerator.GenerateType in project hive by apache.
the class TestVectorBatchGenerate method testTryIt2.
@Test
public void testTryIt2() throws Exception {
GenerateType[] generateTypes = new GenerateType[] { new GenerateType(GenerateCategory.BOOLEAN), new GenerateType(GenerateCategory.LONG), new GenerateType(GenerateCategory.DOUBLE) };
VectorBatchGenerator generator = new VectorBatchGenerator(generateTypes);
VectorizedRowBatch batch = generator.createBatch();
Random random = new Random();
generator.generateBatch(batch, random, VectorizedRowBatch.DEFAULT_SIZE);
VectorBatchDebug.debugDisplayBatch(batch, "testTryIt2");
}
use of org.apache.hadoop.hive.ql.exec.vector.util.batchgen.VectorBatchGenerator.GenerateType in project hive by apache.
the class TestVectorBatchGenerate method testTryIt.
@Test
public void testTryIt() throws Exception {
GenerateType[] generateTypes = new GenerateType[] { new GenerateType(GenerateCategory.INT), new GenerateType(GenerateCategory.BYTE) };
VectorBatchGenerator generator = new VectorBatchGenerator(generateTypes);
VectorizedRowBatch batch = generator.createBatch();
Random random = new Random();
generator.generateBatch(batch, random, VectorizedRowBatch.DEFAULT_SIZE);
VectorBatchDebug.debugDisplayBatch(batch, "testTryIt");
}
use of org.apache.hadoop.hive.ql.exec.vector.util.batchgen.VectorBatchGenerator.GenerateType in project hive by apache.
the class VectorColumnGroupGenerator method populateBatchColumn.
private void populateBatchColumn(VectorizedRowBatch batch, int logicalColumnIndex, int size) {
int columnNum = columnNums[logicalColumnIndex];
ColumnVector colVector = batch.cols[columnNum];
GenerateType generateType = generateTypes[logicalColumnIndex];
GenerateCategory category = generateType.getCategory();
boolean allowNulls = generateType.getAllowNulls();
boolean[] isNull = isNullArrays[logicalColumnIndex];
if (allowNulls) {
for (int i = 0; i < size; i++) {
if (isNull[i]) {
colVector.isNull[i] = true;
colVector.noNulls = false;
}
}
}
Object array = arrays[logicalColumnIndex];
switch(category) {
case BOOLEAN:
{
boolean[] booleanArray = ((boolean[]) array);
long[] vector = ((LongColumnVector) colVector).vector;
for (int i = 0; i < size; i++) {
if (isNull[i]) {
vector[i] = 0;
} else {
vector[i] = (booleanArray[i] ? 1 : 0);
}
}
}
break;
case BYTE:
{
byte[] byteArray = ((byte[]) array);
long[] vector = ((LongColumnVector) colVector).vector;
for (int i = 0; i < size; i++) {
if (isNull[i]) {
vector[i] = 0;
} else {
vector[i] = byteArray[i];
}
}
}
break;
case SHORT:
{
short[] shortArray = ((short[]) array);
long[] vector = ((LongColumnVector) colVector).vector;
for (int i = 0; i < size; i++) {
if (isNull[i]) {
vector[i] = 0;
} else {
vector[i] = shortArray[i];
}
}
}
break;
case INT:
{
int[] intArray = ((int[]) array);
long[] vector = ((LongColumnVector) colVector).vector;
for (int i = 0; i < size; i++) {
if (isNull[i]) {
vector[i] = 0;
} else {
vector[i] = intArray[i];
}
}
}
break;
case LONG:
{
long[] longArray = ((long[]) array);
long[] vector = ((LongColumnVector) colVector).vector;
for (int i = 0; i < size; i++) {
if (isNull[i]) {
vector[i] = 0;
} else {
vector[i] = longArray[i];
}
}
}
break;
case FLOAT:
{
float[] floatArray = ((float[]) array);
double[] vector = ((DoubleColumnVector) colVector).vector;
for (int i = 0; i < size; i++) {
if (isNull[i]) {
vector[i] = 0;
} else {
vector[i] = floatArray[i];
}
}
}
break;
case DOUBLE:
{
double[] doubleArray = ((double[]) array);
double[] vector = ((DoubleColumnVector) colVector).vector;
for (int i = 0; i < size; i++) {
if (isNull[i]) {
vector[i] = 0;
} else {
vector[i] = doubleArray[i];
}
}
}
break;
case STRING:
{
String[] stringArray = ((String[]) array);
BytesColumnVector bytesColVec = ((BytesColumnVector) colVector);
for (int i = 0; i < size; i++) {
if (!isNull[i]) {
byte[] bytes = stringArray[i].getBytes();
bytesColVec.setVal(i, bytes);
}
}
}
break;
case BINARY:
{
byte[][] byteArrayArray = ((byte[][]) array);
BytesColumnVector bytesColVec = ((BytesColumnVector) colVector);
for (int i = 0; i < size; i++) {
if (!isNull[i]) {
byte[] bytes = byteArrayArray[i];
bytesColVec.setVal(i, bytes);
}
}
}
break;
case DATE:
{
Date[] dateArray = ((Date[]) array);
LongColumnVector longColVec = ((LongColumnVector) colVector);
for (int i = 0; i < size; i++) {
if (!isNull[i]) {
Date date = dateArray[i];
longColVec.vector[i] = DateWritableV2.dateToDays(date);
}
}
}
break;
case TIMESTAMP:
{
Timestamp[] timestampArray = ((Timestamp[]) array);
TimestampColumnVector timestampColVec = ((TimestampColumnVector) colVector);
for (int i = 0; i < size; i++) {
if (!isNull[i]) {
Timestamp timestamp = timestampArray[i];
timestampColVec.set(i, timestamp);
}
}
}
break;
case CHAR:
{
HiveChar[] hiveCharArray = ((HiveChar[]) array);
BytesColumnVector bytesColVec = ((BytesColumnVector) colVector);
for (int i = 0; i < size; i++) {
if (!isNull[i]) {
byte[] bytes = hiveCharArray[i].getValue().getBytes();
bytesColVec.setVal(i, bytes);
}
}
}
break;
case VARCHAR:
{
HiveVarchar[] hiveCharArray = ((HiveVarchar[]) array);
BytesColumnVector bytesColVec = ((BytesColumnVector) colVector);
for (int i = 0; i < size; i++) {
if (!isNull[i]) {
byte[] bytes = hiveCharArray[i].getValue().getBytes();
bytesColVec.setVal(i, bytes);
}
}
}
break;
case DECIMAL:
{
HiveDecimalWritable[] hiveDecimalWritableArray = ((HiveDecimalWritable[]) array);
DecimalColumnVector decimalColVec = ((DecimalColumnVector) colVector);
for (int i = 0; i < size; i++) {
if (!isNull[i]) {
HiveDecimalWritable decWritable = hiveDecimalWritableArray[i];
decimalColVec.set(i, decWritable);
}
}
}
break;
case LIST:
case MAP:
case STRUCT:
case UNION:
default:
throw new RuntimeException("Unepected generate category " + category);
}
}
Aggregations