Search in sources :

Example 1 with GenerateType

use of org.apache.hadoop.hive.ql.exec.vector.util.batchgen.VectorBatchGenerator.GenerateType in project hive by apache.

the class MapJoinTestData method generateTypesFromTypeInfos.

private static GenerateType[] generateTypesFromTypeInfos(TypeInfo[] typeInfos) {
    final int size = typeInfos.length;
    GenerateType[] generateTypes = new GenerateType[size];
    for (int i = 0; i < size; i++) {
        PrimitiveTypeInfo primitiveTypeInfo = (PrimitiveTypeInfo) typeInfos[i];
        GenerateCategory category = GenerateCategory.generateCategoryFromPrimitiveCategory(primitiveTypeInfo.getPrimitiveCategory());
        generateTypes[i] = new GenerateType(category);
    }
    return generateTypes;
}
Also used : 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) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)

Example 2 with GenerateType

use of org.apache.hadoop.hive.ql.exec.vector.util.batchgen.VectorBatchGenerator.GenerateType in project hive by apache.

the class VectorColumnGroupGenerator method clearColumnValueArrays.

public void clearColumnValueArrays() {
    for (int i = 0; i < generateTypes.length; i++) {
        GenerateType generateType = generateTypes[i];
        GenerateCategory category = generateType.getCategory();
        Object array = arrays[i];
        switch(category) {
            case BOOLEAN:
                Arrays.fill(((boolean[]) array), false);
                break;
            case BYTE:
                Arrays.fill(((byte[]) array), (byte) 0);
                break;
            case SHORT:
                Arrays.fill(((short[]) array), (short) 0);
                break;
            case INT:
                Arrays.fill(((int[]) array), 0);
                break;
            case LONG:
                Arrays.fill(((long[]) array), 0);
                break;
            case FLOAT:
                Arrays.fill(((float[]) array), 0);
                break;
            case DOUBLE:
                Arrays.fill(((double[]) array), 0);
                break;
            case STRING:
                Arrays.fill(((String[]) array), null);
                break;
            case BINARY:
                Arrays.fill(((byte[][]) array), null);
                break;
            case DATE:
                Arrays.fill(((Date[]) array), null);
                break;
            case TIMESTAMP:
                Arrays.fill(((Timestamp[]) array), null);
                break;
            case CHAR:
                Arrays.fill(((HiveChar[]) array), null);
                break;
            case VARCHAR:
                Arrays.fill(((HiveVarchar[]) array), null);
                break;
            case DECIMAL:
                Arrays.fill(((HiveDecimalWritable[]) array), null);
                break;
            case LIST:
            case MAP:
            case STRUCT:
            case UNION:
            default:
        }
    }
}
Also used : 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)

Example 3 with GenerateType

use of org.apache.hadoop.hive.ql.exec.vector.util.batchgen.VectorBatchGenerator.GenerateType in project hive by apache.

the class VectorColumnGroupGenerator method generateRowColumnValue.

private void generateRowColumnValue(int rowIndex, int columnIndex, Random random) {
    GenerateType generateType = generateTypes[columnIndex];
    GenerateCategory category = generateType.getCategory();
    boolean allowNulls = generateType.getAllowNulls();
    if (allowNulls && random.nextInt(100) < 5) {
        isNullArrays[columnIndex][rowIndex] = true;
        return;
    }
    Object array = arrays[columnIndex];
    switch(category) {
        case BOOLEAN:
            {
                boolean value = random.nextBoolean();
                ((boolean[]) array)[rowIndex] = value;
            }
            break;
        case BYTE:
            {
                byte value = (byte) (random.nextBoolean() ? -random.nextInt(-((int) Byte.MIN_VALUE) + 1) : random.nextInt((int) Byte.MAX_VALUE + 1));
                ((byte[]) array)[rowIndex] = value;
            }
            break;
        case SHORT:
            {
                short value = (short) (random.nextBoolean() ? -random.nextInt(-((int) Short.MIN_VALUE) + 1) : random.nextInt((int) Short.MAX_VALUE + 1));
                ((short[]) array)[rowIndex] = value;
            }
            break;
        case INT:
            {
                int value = random.nextInt();
                ((int[]) array)[rowIndex] = value;
            }
            break;
        case LONG:
            {
                long value = random.nextLong();
                ((long[]) array)[rowIndex] = value;
            }
            break;
        case FLOAT:
            {
                float value = random.nextLong();
                ((float[]) array)[rowIndex] = value;
            }
            break;
        case DOUBLE:
            {
                double value = random.nextLong();
                ((double[]) array)[rowIndex] = value;
            }
            break;
        case STRING:
            {
                String value = RandomTypeUtil.getRandString(random);
                ((String[]) array)[rowIndex] = value;
            }
            break;
        case BINARY:
            {
                byte[] value = RandomTypeUtil.getRandBinary(random, 10);
                ((byte[][]) array)[rowIndex] = value;
            }
            break;
        case DATE:
            {
                Date value = RandomTypeUtil.getRandDate(random);
                ((Date[]) array)[rowIndex] = value;
            }
            break;
        case TIMESTAMP:
            {
                Timestamp value = RandomTypeUtil.getRandTimestamp(random).toSqlTimestamp();
                ((Timestamp[]) array)[rowIndex] = value;
            }
            break;
        case CHAR:
            {
                // UNDONE: Use CharTypeInfo.maxLength
                HiveChar value = new HiveChar(RandomTypeUtil.getRandString(random), 10);
                ((HiveChar[]) array)[rowIndex] = value;
            }
            break;
        case VARCHAR:
            {
                // UNDONE: Use VarcharTypeInfo.maxLength
                HiveVarchar value = new HiveVarchar(RandomTypeUtil.getRandString(random), 10);
                ((HiveVarchar[]) array)[rowIndex] = value;
            }
            break;
        case DECIMAL:
            {
                HiveDecimalWritable value = new HiveDecimalWritable(RandomTypeUtil.getRandHiveDecimal(random));
                ((HiveDecimalWritable[]) array)[rowIndex] = value;
            }
            break;
        case LIST:
        case MAP:
        case STRUCT:
        case UNION:
        default:
    }
}
Also used : GenerateType(org.apache.hadoop.hive.ql.exec.vector.util.batchgen.VectorBatchGenerator.GenerateType) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) GenerateCategory(org.apache.hadoop.hive.ql.exec.vector.util.batchgen.VectorBatchGenerator.GenerateType.GenerateCategory) HiveChar(org.apache.hadoop.hive.common.type.HiveChar) HiveVarchar(org.apache.hadoop.hive.common.type.HiveVarchar) Timestamp(java.sql.Timestamp) Date(org.apache.hadoop.hive.common.type.Date)

Example 4 with GenerateType

use of org.apache.hadoop.hive.ql.exec.vector.util.batchgen.VectorBatchGenerator.GenerateType in project hive by apache.

the class VectorColumnGroupGenerator method allocateArrays.

private void allocateArrays(int size) {
    arrays = new Object[generateTypes.length];
    isNullArrays = new boolean[generateTypes.length][];
    for (int i = 0; i < generateTypes.length; i++) {
        GenerateType generateType = generateTypes[i];
        GenerateCategory category = generateType.getCategory();
        Object array = null;
        switch(category) {
            case BOOLEAN:
                array = new boolean[size];
                break;
            case BYTE:
                array = new byte[size];
                break;
            case SHORT:
                array = new short[size];
                break;
            case INT:
                array = new int[size];
                break;
            case LONG:
                array = new long[size];
                break;
            case FLOAT:
                array = new float[size];
                break;
            case DOUBLE:
                array = new double[size];
                break;
            case STRING:
                array = new String[size];
                break;
            case BINARY:
                array = new byte[size][];
                break;
            case DATE:
                array = new Date[size];
                break;
            case TIMESTAMP:
                array = new Timestamp[size];
                break;
            case CHAR:
                array = new HiveChar[size];
                break;
            case VARCHAR:
                array = new HiveVarchar[size];
                break;
            case DECIMAL:
                array = new HiveDecimalWritable[size];
                break;
            case LIST:
            case MAP:
            case STRUCT:
            case UNION:
            default:
                throw new RuntimeException("Unexpected generate category " + category);
        }
        arrays[i] = array;
        isNullArrays[i] = new boolean[size];
    }
}
Also used : 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)

Example 5 with GenerateType

use of org.apache.hadoop.hive.ql.exec.vector.util.batchgen.VectorBatchGenerator.GenerateType in project hive by apache.

the class VectorColumnGroupGenerator method fillDownRowColumnValue.

private void fillDownRowColumnValue(int rowIndex, int columnIndex, int seriesCount, Random random) {
    GenerateType generateType = generateTypes[columnIndex];
    GenerateCategory category = generateType.getCategory();
    boolean allowNulls = generateType.getAllowNulls();
    Object array = arrays[columnIndex];
    boolean[] isNull = isNullArrays[columnIndex];
    if (allowNulls && isNull[rowIndex]) {
        for (int i = 1; i < seriesCount; i++) {
            isNull[rowIndex + i] = true;
        }
        return;
    }
    switch(category) {
        case BOOLEAN:
            {
                boolean[] booleanArray = ((boolean[]) array);
                boolean value = booleanArray[rowIndex];
                for (int i = 1; i < seriesCount; i++) {
                    booleanArray[rowIndex + i] = value;
                }
            }
            break;
        case BYTE:
            {
                byte[] byteArray = ((byte[]) array);
                byte value = byteArray[rowIndex];
                for (int i = 1; i < seriesCount; i++) {
                    byteArray[rowIndex + i] = value;
                }
            }
            break;
        case SHORT:
            {
                short[] shortArray = ((short[]) array);
                short value = shortArray[rowIndex];
                for (int i = 1; i < seriesCount; i++) {
                    shortArray[rowIndex + i] = value;
                }
            }
            break;
        case INT:
            {
                int[] intArray = ((int[]) array);
                int value = intArray[rowIndex];
                for (int i = 1; i < seriesCount; i++) {
                    intArray[rowIndex + i] = value;
                }
            }
            break;
        case LONG:
            {
                long[] longArray = ((long[]) array);
                long value = longArray[rowIndex];
                for (int i = 1; i < seriesCount; i++) {
                    longArray[rowIndex + i] = value;
                }
            }
            break;
        case FLOAT:
            {
                float[] floatArray = ((float[]) array);
                float value = floatArray[rowIndex];
                for (int i = 1; i < seriesCount; i++) {
                    floatArray[rowIndex + i] = value;
                }
            }
            break;
        case DOUBLE:
            {
                double[] doubleArray = ((double[]) array);
                double value = doubleArray[rowIndex];
                for (int i = 1; i < seriesCount; i++) {
                    doubleArray[rowIndex + i] = value;
                }
            }
            break;
        case STRING:
            {
                String[] stringArray = ((String[]) array);
                String value = stringArray[rowIndex];
                for (int i = 1; i < seriesCount; i++) {
                    stringArray[rowIndex + i] = value;
                }
            }
            break;
        case BINARY:
            {
                byte[][] byteArrayArray = ((byte[][]) array);
                byte[] value = byteArrayArray[rowIndex];
                for (int i = 1; i < seriesCount; i++) {
                    byteArrayArray[rowIndex + i] = value;
                }
            }
            break;
        case DATE:
            {
                Date[] dateArray = ((Date[]) array);
                Date value = dateArray[rowIndex];
                for (int i = 1; i < seriesCount; i++) {
                    dateArray[rowIndex + i] = value;
                }
            }
            break;
        case TIMESTAMP:
            {
                Timestamp[] timestampArray = ((Timestamp[]) array);
                Timestamp value = timestampArray[rowIndex];
                for (int i = 1; i < seriesCount; i++) {
                    timestampArray[rowIndex + i] = value;
                }
            }
            break;
        case CHAR:
            {
                HiveChar[] hiveCharArray = ((HiveChar[]) array);
                HiveChar value = hiveCharArray[rowIndex];
                for (int i = 1; i < seriesCount; i++) {
                    hiveCharArray[rowIndex + i] = value;
                }
            }
            break;
        case VARCHAR:
            {
                HiveVarchar[] hiveVarcharArray = ((HiveVarchar[]) array);
                HiveVarchar value = hiveVarcharArray[rowIndex];
                for (int i = 1; i < seriesCount; i++) {
                    hiveVarcharArray[rowIndex + i] = value;
                }
            }
            break;
        case DECIMAL:
            {
                HiveDecimalWritable[] hiveDecimalWritableArray = ((HiveDecimalWritable[]) array);
                HiveDecimalWritable value = hiveDecimalWritableArray[rowIndex];
                for (int i = 1; i < seriesCount; i++) {
                    hiveDecimalWritableArray[rowIndex + i] = value;
                }
            }
            break;
        case LIST:
        case MAP:
        case STRUCT:
        case UNION:
        default:
    }
}
Also used : GenerateType(org.apache.hadoop.hive.ql.exec.vector.util.batchgen.VectorBatchGenerator.GenerateType) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) GenerateCategory(org.apache.hadoop.hive.ql.exec.vector.util.batchgen.VectorBatchGenerator.GenerateType.GenerateCategory) HiveChar(org.apache.hadoop.hive.common.type.HiveChar) HiveVarchar(org.apache.hadoop.hive.common.type.HiveVarchar) Timestamp(java.sql.Timestamp) Date(org.apache.hadoop.hive.common.type.Date)

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