Search in sources :

Example 6 with GenerateType

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");
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) Random(java.util.Random) GenerateType(org.apache.hadoop.hive.ql.exec.vector.util.batchgen.VectorBatchGenerator.GenerateType) VectorBatchGenerator(org.apache.hadoop.hive.ql.exec.vector.util.batchgen.VectorBatchGenerator) Test(org.junit.Test)

Example 7 with GenerateType

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");
}
Also used : VectorizedRowBatch(org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch) Random(java.util.Random) GenerateType(org.apache.hadoop.hive.ql.exec.vector.util.batchgen.VectorBatchGenerator.GenerateType) VectorBatchGenerator(org.apache.hadoop.hive.ql.exec.vector.util.batchgen.VectorBatchGenerator) Test(org.junit.Test)

Example 8 with GenerateType

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);
    }
}
Also used : TimestampColumnVector(org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector) DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) Timestamp(java.sql.Timestamp) Date(org.apache.hadoop.hive.common.type.Date) TimestampColumnVector(org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector) DecimalColumnVector(org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector) ColumnVector(org.apache.hadoop.hive.ql.exec.vector.ColumnVector) DoubleColumnVector(org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector) GenerateType(org.apache.hadoop.hive.ql.exec.vector.util.batchgen.VectorBatchGenerator.GenerateType) GenerateCategory(org.apache.hadoop.hive.ql.exec.vector.util.batchgen.VectorBatchGenerator.GenerateType.GenerateCategory) BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) LongColumnVector(org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)

Aggregations

GenerateType (org.apache.hadoop.hive.ql.exec.vector.util.batchgen.VectorBatchGenerator.GenerateType)8 GenerateCategory (org.apache.hadoop.hive.ql.exec.vector.util.batchgen.VectorBatchGenerator.GenerateType.GenerateCategory)6 Timestamp (java.sql.Timestamp)3 Date (org.apache.hadoop.hive.common.type.Date)3 HiveDecimalWritable (org.apache.hadoop.hive.serde2.io.HiveDecimalWritable)3 Random (java.util.Random)2 HiveChar (org.apache.hadoop.hive.common.type.HiveChar)2 HiveVarchar (org.apache.hadoop.hive.common.type.HiveVarchar)2 VectorizedRowBatch (org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch)2 VectorBatchGenerator (org.apache.hadoop.hive.ql.exec.vector.util.batchgen.VectorBatchGenerator)2 Test (org.junit.Test)2 BytesColumnVector (org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)1 ColumnVector (org.apache.hadoop.hive.ql.exec.vector.ColumnVector)1 DecimalColumnVector (org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector)1 DoubleColumnVector (org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector)1 LongColumnVector (org.apache.hadoop.hive.ql.exec.vector.LongColumnVector)1 TimestampColumnVector (org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector)1 PrimitiveTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)1