Search in sources :

Example 6 with VectorExpressionWriter

use of org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpressionWriter in project hive by apache.

the class VectorGroupByOperator method initializeOp.

@Override
protected void initializeOp(Configuration hconf) throws HiveException {
    super.initializeOp(hconf);
    VectorExpression.doTransientInit(keyExpressions);
    List<ObjectInspector> objectInspectors = new ArrayList<ObjectInspector>();
    List<ExprNodeDesc> keysDesc = conf.getKeys();
    try {
        List<String> outputFieldNames = conf.getOutputColumnNames();
        final int outputCount = outputFieldNames.size();
        for (int i = 0; i < outputKeyLength; ++i) {
            VectorExpressionWriter vew = VectorExpressionWriterFactory.genVectorExpressionWritable(keysDesc.get(i));
            ObjectInspector oi = vew.getObjectInspector();
            objectInspectors.add(oi);
        }
        final int aggregateCount = vecAggrDescs.length;
        aggregators = new VectorAggregateExpression[aggregateCount];
        for (int i = 0; i < aggregateCount; ++i) {
            VectorAggregationDesc vecAggrDesc = vecAggrDescs[i];
            Class<? extends VectorAggregateExpression> vecAggrClass = vecAggrDesc.getVecAggrClass();
            Constructor<? extends VectorAggregateExpression> ctor = null;
            try {
                ctor = vecAggrClass.getConstructor(VectorAggregationDesc.class);
            } catch (Exception e) {
                throw new HiveException("Constructor " + vecAggrClass.getSimpleName() + "(VectorAggregationDesc) not available");
            }
            VectorAggregateExpression vecAggrExpr = null;
            try {
                vecAggrExpr = ctor.newInstance(vecAggrDesc);
            } catch (Exception e) {
                throw new HiveException("Failed to create " + vecAggrClass.getSimpleName() + "(VectorAggregationDesc) object ", e);
            }
            VectorExpression.doTransientInit(vecAggrExpr.getInputExpression());
            aggregators[i] = vecAggrExpr;
            ObjectInspector objInsp = TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo(vecAggrDesc.getOutputTypeInfo());
            Preconditions.checkState(objInsp != null);
            objectInspectors.add(objInsp);
        }
        keyWrappersBatch = VectorHashKeyWrapperBatch.compileKeyWrapperBatch(keyExpressions);
        aggregationBatchInfo = new VectorAggregationBufferBatch();
        aggregationBatchInfo.compileAggregationBatchInfo(aggregators);
        outputObjInspector = ObjectInspectorFactory.getStandardStructObjectInspector(outputFieldNames, objectInspectors);
        vrbCtx = new VectorizedRowBatchCtx(outputFieldNames.toArray(new String[0]), outputTypeInfos, outputDataTypePhysicalVariations, /* dataColumnNums */
        null, /* partitionColumnCount */
        0, /* virtualColumnCount */
        0, /* neededVirtualColumns */
        null, vOutContext.getScratchColumnTypeNames(), vOutContext.getScratchDataTypePhysicalVariations());
        outputBatch = vrbCtx.createVectorizedRowBatch();
    } catch (HiveException he) {
        throw he;
    } catch (Throwable e) {
        throw new HiveException(e);
    }
    forwardCache = new Object[outputKeyLength + aggregators.length];
    setupGroupingSets();
    switch(vectorDesc.getProcessingMode()) {
        case GLOBAL:
            Preconditions.checkState(outputKeyLength == 0);
            Preconditions.checkState(!groupingSetsPresent);
            processingMode = this.new ProcessingModeGlobalAggregate();
            break;
        case HASH:
            processingMode = this.new ProcessingModeHashAggregate();
            break;
        case MERGE_PARTIAL:
            Preconditions.checkState(!groupingSetsPresent);
            processingMode = this.new ProcessingModeReduceMergePartial();
            break;
        case STREAMING:
            processingMode = this.new ProcessingModeStreaming();
            break;
        default:
            throw new RuntimeException("Unsupported vector GROUP BY processing mode " + vectorDesc.getProcessingMode().name());
    }
    processingMode.initialize(hconf);
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) ArrayList(java.util.ArrayList) VectorAggregateExpression(org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression) VectorExpressionWriter(org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpressionWriter) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc)

Aggregations

ArrayList (java.util.ArrayList)6 VectorExpressionWriter (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpressionWriter)6 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)6 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)4 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)3 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)3 List (java.util.List)2 ExprNodeEvaluator (org.apache.hadoop.hive.ql.exec.ExprNodeEvaluator)2 VectorExpression (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression)2 VectorExpressionWriterFactory (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpressionWriterFactory)2 BytesColumnVector (org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector)1 ColumnVector (org.apache.hadoop.hive.ql.exec.vector.ColumnVector)1 VectorAggregateExpression (org.apache.hadoop.hive.ql.exec.vector.expressions.aggregates.VectorAggregateExpression)1 BinarySortableSerDe (org.apache.hadoop.hive.serde2.binarysortable.BinarySortableSerDe)1 BinarySortableDeserializeRead (org.apache.hadoop.hive.serde2.binarysortable.fast.BinarySortableDeserializeRead)1 LazyBinaryDeserializeRead (org.apache.hadoop.hive.serde2.lazybinary.fast.LazyBinaryDeserializeRead)1 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)1 KeyValueReader (org.apache.tez.runtime.library.api.KeyValueReader)1 KeyValuesReader (org.apache.tez.runtime.library.api.KeyValuesReader)1