Search in sources :

Example 6 with TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo

use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo in project hive by apache.

the class VectorExpressionWriterFactory method processVectorInspector.

/**
 * Creates the value writers for an struct object inspector.
 * Creates an appropriate output object inspector.
 */
public static void processVectorInspector(StructObjectInspector structObjInspector, SingleOIDClosure closure) throws HiveException {
    List<? extends StructField> fields = structObjInspector.getAllStructFieldRefs();
    VectorExpressionWriter[] writers = new VectorExpressionWriter[fields.size()];
    List<ObjectInspector> oids = new ArrayList<ObjectInspector>(writers.length);
    ArrayList<String> columnNames = new ArrayList<String>();
    int i = 0;
    for (StructField field : fields) {
        ObjectInspector fieldObjInsp = TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo(TypeInfoUtils.getTypeInfoFromObjectInspector(field.getFieldObjectInspector()));
        writers[i] = VectorExpressionWriterFactory.genVectorExpressionWritable(fieldObjInsp);
        columnNames.add(field.getFieldName());
        oids.add(writers[i].getObjectInspector());
        i++;
    }
    ObjectInspector objectInspector = ObjectInspectorFactory.getStandardStructObjectInspector(columnNames, oids);
    closure.assign(writers, objectInspector);
}
Also used : VoidObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.VoidObjectInspector) SettableMapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.SettableMapObjectInspector) SettableTimestampObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableTimestampObjectInspector) StandardStructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StandardStructObjectInspector) SettableBinaryObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableBinaryObjectInspector) SettableHiveDecimalObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableHiveDecimalObjectInspector) SettableStringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableStringObjectInspector) SettableUnionObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.SettableUnionObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) SettableHiveCharObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableHiveCharObjectInspector) SettableLongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableLongObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) SettableDateObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableDateObjectInspector) SettableShortObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableShortObjectInspector) SettableHiveIntervalDayTimeObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableHiveIntervalDayTimeObjectInspector) SettableFloatObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableFloatObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) SettableHiveVarcharObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableHiveVarcharObjectInspector) SettableListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.SettableListObjectInspector) SettableDoubleObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableDoubleObjectInspector) SettableBooleanObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableBooleanObjectInspector) SettableStructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.SettableStructObjectInspector) SettableHiveIntervalYearMonthObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableHiveIntervalYearMonthObjectInspector) SettableIntObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableIntObjectInspector) SettableByteObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableByteObjectInspector) StructField(org.apache.hadoop.hive.serde2.objectinspector.StructField) ArrayList(java.util.ArrayList)

Example 7 with TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo

use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo in project hive by apache.

the class VectorExpressionWriterFactory method genVectorExpressionWritable.

/**
 * Compiles the appropriate vector expression writer based on an expression info (ExprNodeDesc)
 */
public static VectorExpressionWriter genVectorExpressionWritable(VectorExpression vecExpr) throws HiveException {
    TypeInfo outputTypeInfo = vecExpr.getOutputTypeInfo();
    ObjectInspector objectInspector = TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo(outputTypeInfo);
    return genVectorExpressionWritable(objectInspector);
}
Also used : VoidObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.VoidObjectInspector) SettableMapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.SettableMapObjectInspector) SettableTimestampObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableTimestampObjectInspector) StandardStructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StandardStructObjectInspector) SettableBinaryObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableBinaryObjectInspector) SettableHiveDecimalObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableHiveDecimalObjectInspector) SettableStringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableStringObjectInspector) SettableUnionObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.SettableUnionObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) SettableHiveCharObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableHiveCharObjectInspector) SettableLongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableLongObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) SettableDateObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableDateObjectInspector) SettableShortObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableShortObjectInspector) SettableHiveIntervalDayTimeObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableHiveIntervalDayTimeObjectInspector) SettableFloatObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableFloatObjectInspector) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) SettableHiveVarcharObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableHiveVarcharObjectInspector) SettableListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.SettableListObjectInspector) SettableDoubleObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableDoubleObjectInspector) SettableBooleanObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableBooleanObjectInspector) SettableStructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.SettableStructObjectInspector) SettableHiveIntervalYearMonthObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableHiveIntervalYearMonthObjectInspector) SettableIntObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableIntObjectInspector) SettableByteObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.SettableByteObjectInspector) MapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo) StructTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo) ListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) UnionTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.UnionTypeInfo)

Example 8 with TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo

use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo in project hive by apache.

the class VectorRandomRowSource method randomRow.

public Object[] randomRow() {
    final Object[] row = new Object[columnCount];
    if (generationSpecList == null) {
        for (int c = 0; c < columnCount; c++) {
            row[c] = randomWritable(c);
        }
    } else {
        for (int c = 0; c < columnCount; c++) {
            GenerationSpec generationSpec = generationSpecList.get(c);
            GenerationSpec.GenerationKind generationKind = generationSpec.getGenerationKind();
            Object object;
            switch(generationKind) {
                case SAME_TYPE:
                    object = randomWritable(c, generationSpec.getColumnAllowNulls());
                    break;
                case OMIT_GENERATION:
                    object = null;
                    break;
                case STRING_FAMILY:
                    {
                        TypeInfo typeInfo = generationSpec.getTypeInfo();
                        StringGenerationOption stringGenerationOption = generationSpec.getStringGenerationOption();
                        object = randomStringFamily(r, typeInfo, stringGenerationOption, true);
                    }
                    break;
                case STRING_FAMILY_OTHER_TYPE_VALUE:
                    {
                        TypeInfo typeInfo = generationSpec.getTypeInfo();
                        TypeInfo otherTypeTypeInfo = generationSpec.getSourceTypeInfo();
                        object = randomStringFamilyOtherTypeValue(r, typeInfo, otherTypeTypeInfo, true);
                    }
                    break;
                case TIMESTAMP_MILLISECONDS:
                    {
                        LongWritable longWritable = (LongWritable) randomWritable(c);
                        if (longWritable != null) {
                            while (true) {
                                long longValue = longWritable.get();
                                if (longValue >= MIN_FOUR_DIGIT_YEAR_MILLIS && longValue <= MAX_FOUR_DIGIT_YEAR_MILLIS) {
                                    break;
                                }
                                longWritable.set((Long) VectorRandomRowSource.randomPrimitiveObject(r, TypeInfoFactory.longTypeInfo));
                            }
                        }
                        object = longWritable;
                    }
                    break;
                case VALUE_LIST:
                    {
                        List<Object> valueList = generationSpec.getValueList();
                        final int valueCount = valueList.size();
                        TypeInfo typeInfo = generationSpec.getTypeInfo();
                        Category category = typeInfo.getCategory();
                        switch(category) {
                            case PRIMITIVE:
                            case STRUCT:
                                object = valueList.get(r.nextInt(valueCount));
                                break;
                            case LIST:
                                {
                                    final int elementCount = r.nextInt(valueCount);
                                    ListTypeInfo listTypeInfo = (ListTypeInfo) typeInfo;
                                    TypeInfo elementTypeInfo = listTypeInfo.getListElementTypeInfo();
                                    final ObjectInspector elementObjectInspector = TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo(elementTypeInfo);
                                    List<Object> list = new ArrayList<Object>(elementCount);
                                    for (int i = 0; i < elementCount; i++) {
                                        Object elementWritable = randomWritable(elementTypeInfo, elementObjectInspector, allowNull);
                                        list.add(elementWritable);
                                    }
                                    object = list;
                                }
                                break;
                            case MAP:
                                {
                                    final int elementCount = r.nextInt(valueCount);
                                    MapTypeInfo mapTypeInfo = (MapTypeInfo) typeInfo;
                                    TypeInfo valueTypeInfo = mapTypeInfo.getMapValueTypeInfo();
                                    final ObjectInspector valueObjectInspector = TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo(valueTypeInfo);
                                    Map<Object, Object> map = new HashMap<Object, Object>(elementCount);
                                    for (int i = 0; i < elementCount; i++) {
                                        Object key = valueList.get(r.nextInt(valueCount));
                                        Object valueWritable = randomWritable(valueTypeInfo, valueObjectInspector, allowNull);
                                        if (!map.containsKey(key)) {
                                            map.put(key, valueWritable);
                                        }
                                    }
                                    object = map;
                                }
                                break;
                            default:
                                throw new RuntimeException("Unexpected category " + category);
                        }
                    }
                    break;
                default:
                    throw new RuntimeException("Unexpected generationKind " + generationKind);
            }
            row[c] = object;
        }
    }
    return row;
}
Also used : WritableIntObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableIntObjectInspector) WritableByteObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableByteObjectInspector) UnionObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.UnionObjectInspector) StandardStructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StandardStructObjectInspector) WritableDoubleObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableDoubleObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) MapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector) StandardListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StandardListObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) WritableStringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableStringObjectInspector) ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) WritableHiveCharObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableHiveCharObjectInspector) WritableHiveVarcharObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableHiveVarcharObjectInspector) WritableBooleanObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableBooleanObjectInspector) WritableTimestampObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableTimestampObjectInspector) WritableHiveIntervalDayTimeObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableHiveIntervalDayTimeObjectInspector) WritableShortObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableShortObjectInspector) StandardMapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StandardMapObjectInspector) WritableHiveIntervalYearMonthObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableHiveIntervalYearMonthObjectInspector) WritableFloatObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableFloatObjectInspector) WritableLongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableLongObjectInspector) StandardUnionObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StandardUnionObjectInspector) WritableDateObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableDateObjectInspector) WritableHiveDecimalObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableHiveDecimalObjectInspector) PrimitiveCategory(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory) Category(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo) StructTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) VarcharTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.VarcharTypeInfo) ListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo) DecimalTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) UnionTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.UnionTypeInfo) CharTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.CharTypeInfo) ListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo) MapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo) List(java.util.List) ArrayList(java.util.ArrayList) LongWritable(org.apache.hadoop.io.LongWritable)

Example 9 with TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo

use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo in project hive by apache.

the class AggregationBase method extractResultObjects.

private static void extractResultObjects(VectorizedRowBatch outputBatch, short[] keys, VectorExtractRow resultVectorExtractRow, TypeInfo outputTypeInfo, Object[] scrqtchRow, Object[] results) {
    final boolean isPrimitive = (outputTypeInfo instanceof PrimitiveTypeInfo);
    ObjectInspector objectInspector;
    if (isPrimitive) {
        objectInspector = TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo(outputTypeInfo);
    } else {
        objectInspector = null;
    }
    for (int batchIndex = 0; batchIndex < outputBatch.size; batchIndex++) {
        resultVectorExtractRow.extractRow(outputBatch, batchIndex, scrqtchRow);
        if (isPrimitive) {
            Object copyResult = ObjectInspectorUtils.copyToStandardObject(scrqtchRow[0], objectInspector, ObjectInspectorCopyOption.WRITABLE);
            results[keys[batchIndex]] = copyResult;
        } else {
            results[keys[batchIndex]] = scrqtchRow[0];
        }
    }
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)

Example 10 with TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo

use of org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo in project hive by apache.

the class AggregationBase method verifyAggregationResults.

protected void verifyAggregationResults(TypeInfo typeInfo, TypeInfo outputTypeInfo, int maxKeyCount, GenericUDAFEvaluator.Mode udafEvaluatorMode, Object[] resultsArray) {
    // Row-mode is the expected results.
    Object[] expectedResults = (Object[]) resultsArray[0];
    ObjectInspector objectInspector = TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo(outputTypeInfo);
    for (int v = 1; v < AggregationTestMode.count; v++) {
        Object[] vectorResults = (Object[]) resultsArray[v];
        for (short key = 0; key < maxKeyCount + 1; key++) {
            Object expectedResult = expectedResults[key];
            Object vectorResult = vectorResults[key];
            if (expectedResult == null || vectorResult == null) {
                if (expectedResult != null || vectorResult != null) {
                    Assert.fail("Key " + key + " typeName " + typeInfo.getTypeName() + " outputTypeName " + outputTypeInfo.getTypeName() + " " + AggregationTestMode.values()[v] + " result is NULL " + (vectorResult == null ? "YES" : "NO result " + vectorResult.toString()) + " does not match row-mode expected result is NULL " + (expectedResult == null ? "YES" : "NO result " + expectedResult.toString()) + " udafEvaluatorMode " + udafEvaluatorMode);
                }
            } else {
                if (!compareObjects(expectedResult, vectorResult, outputTypeInfo, objectInspector)) {
                    Assert.fail("Key " + key + " typeName " + typeInfo.getTypeName() + " outputTypeName " + outputTypeInfo.getTypeName() + " " + AggregationTestMode.values()[v] + " result " + vectorResult.toString() + " (" + vectorResult.getClass().getSimpleName() + ")" + " does not match row-mode expected result " + expectedResult.toString() + " (" + expectedResult.getClass().getSimpleName() + ")" + " udafEvaluatorMode " + udafEvaluatorMode);
                }
            }
        }
    }
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)

Aggregations

ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)44 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)31 ArrayList (java.util.ArrayList)22 PrimitiveTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)17 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)13 HiveConf (org.apache.hadoop.hive.conf.HiveConf)12 DecimalTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo)11 ExprNodeEvaluator (org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator)10 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)10 ExprNodeGenericFuncDesc (org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc)9 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)9 DataTypePhysicalVariation (org.apache.hadoop.hive.common.type.DataTypePhysicalVariation)8 ExprNodeColumnDesc (org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc)8 GenericUDF (org.apache.hadoop.hive.ql.udf.generic.GenericUDF)8 VectorRandomBatchSource (org.apache.hadoop.hive.ql.exec.vector.VectorRandomBatchSource)7 VectorRandomRowSource (org.apache.hadoop.hive.ql.exec.vector.VectorRandomRowSource)7 GenerationSpec (org.apache.hadoop.hive.ql.exec.vector.VectorRandomRowSource.GenerationSpec)7 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)7 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)6 CharTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.CharTypeInfo)6