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);
}
Aggregations