Search in sources :

Example 1 with GroupingColumns

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

the class VectorizationContext method getGroupingExpression.

private VectorExpression getGroupingExpression(GenericUDFGrouping udf, List<ExprNodeDesc> childExprs, TypeInfo returnType) throws HiveException {
    ExprNodeDesc childExpr0 = childExprs.get(0);
    if (!(childExpr0 instanceof ExprNodeColumnDesc)) {
        return null;
    }
    ExprNodeColumnDesc groupingIdColDesc = (ExprNodeColumnDesc) childExpr0;
    int groupingIdColNum = getInputColumnIndex(groupingIdColDesc.getColumn());
    final int indexCount = childExprs.size() - 1;
    int[] indices = new int[indexCount];
    for (int i = 0; i < indexCount; i++) {
        ExprNodeDesc indexChildExpr = childExprs.get(i + 1);
        if (!(indexChildExpr instanceof ExprNodeConstantDesc)) {
            return null;
        }
        Object scalarObject = ((ExprNodeConstantDesc) indexChildExpr).getValue();
        final int index;
        if (scalarObject instanceof Integer) {
            index = (int) scalarObject;
        } else if (scalarObject instanceof Long) {
            index = (int) ((long) scalarObject);
        } else {
            return null;
        }
        indices[i] = index;
    }
    final int outputColumnNum = ocm.allocateOutputColumn(returnType);
    final VectorExpression ve;
    if (indices.length == 1) {
        ve = new GroupingColumn(groupingIdColNum, indices[0], outputColumnNum);
    } else {
        ve = new GroupingColumns(groupingIdColNum, indices, outputColumnNum);
    }
    ve.setInputTypeInfos(groupingIdColDesc.getTypeInfo());
    ve.setInputDataTypePhysicalVariations(DataTypePhysicalVariation.NONE);
    ve.setOutputTypeInfo(returnType);
    ve.setOutputDataTypePhysicalVariation(DataTypePhysicalVariation.NONE);
    return ve;
}
Also used : ExprNodeConstantDesc(org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) FilterConstantBooleanVectorExpression(org.apache.hadoop.hive.ql.exec.vector.expressions.FilterConstantBooleanVectorExpression) ConstantVectorExpression(org.apache.hadoop.hive.ql.exec.vector.expressions.ConstantVectorExpression) VectorExpression(org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression) DynamicValueVectorExpression(org.apache.hadoop.hive.ql.exec.vector.expressions.DynamicValueVectorExpression) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) GroupingColumn(org.apache.hadoop.hive.ql.exec.vector.expressions.GroupingColumn) GroupingColumns(org.apache.hadoop.hive.ql.exec.vector.expressions.GroupingColumns)

Aggregations

ConstantVectorExpression (org.apache.hadoop.hive.ql.exec.vector.expressions.ConstantVectorExpression)1 DynamicValueVectorExpression (org.apache.hadoop.hive.ql.exec.vector.expressions.DynamicValueVectorExpression)1 FilterConstantBooleanVectorExpression (org.apache.hadoop.hive.ql.exec.vector.expressions.FilterConstantBooleanVectorExpression)1 GroupingColumn (org.apache.hadoop.hive.ql.exec.vector.expressions.GroupingColumn)1 GroupingColumns (org.apache.hadoop.hive.ql.exec.vector.expressions.GroupingColumns)1 VectorExpression (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression)1 ExprNodeColumnDesc (org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc)1 ExprNodeConstantDesc (org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc)1 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)1