Search in sources :

Example 1 with IfExprColumnNull

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

the class VectorizationContext method doGetIfExpression.

private VectorExpression doGetIfExpression(GenericUDFIf genericUDFIf, List<ExprNodeDesc> childExpr, TypeInfo returnType) throws HiveException {
    if (hiveVectorIfStmtMode == HiveVectorIfStmtMode.ADAPTOR) {
        return null;
    }
    // Align the THEN/ELSE types.
    childExpr = getChildExpressionsWithImplicitCast(genericUDFIf, childExpr, returnType);
    final ExprNodeDesc ifDesc = Objects.requireNonNull(childExpr).get(0);
    final ExprNodeDesc thenDesc = childExpr.get(1);
    final ExprNodeDesc elseDesc = childExpr.get(2);
    final boolean isThenNullConst = isNullConst(thenDesc);
    final boolean isElseNullConst = isNullConst(elseDesc);
    if (isThenNullConst && isElseNullConst) {
        // THEN NULL ELSE NULL: An unusual "case", but possible.
        final int outputColumnNum = ocm.allocateOutputColumn(returnType);
        final VectorExpression resultExpr = new IfExprNullNull(outputColumnNum);
        resultExpr.setOutputTypeInfo(returnType);
        resultExpr.setOutputDataTypePhysicalVariation(DataTypePhysicalVariation.NONE);
        return resultExpr;
    }
    final boolean isThenCondExpr = isCondExpr(thenDesc);
    final boolean isElseCondExpr = isCondExpr(elseDesc);
    final boolean isOnlyGood = (hiveVectorIfStmtMode == HiveVectorIfStmtMode.GOOD);
    if (isThenNullConst) {
        final VectorExpression whenExpr = getVectorExpression(ifDesc, VectorExpressionDescriptor.Mode.PROJECTION);
        final VectorExpression elseExpr = getVectorExpression(elseDesc, VectorExpressionDescriptor.Mode.PROJECTION);
        DataTypePhysicalVariation outputDataTypePhysicalVariation = (elseExpr.getOutputDataTypePhysicalVariation() == null) ? DataTypePhysicalVariation.NONE : elseExpr.getOutputDataTypePhysicalVariation();
        final int outputColumnNum = ocm.allocateOutputColumn(returnType, outputDataTypePhysicalVariation);
        final VectorExpression resultExpr;
        if (!isElseCondExpr || isOnlyGood) {
            resultExpr = new IfExprNullColumn(whenExpr.getOutputColumnNum(), elseExpr.getOutputColumnNum(), outputColumnNum);
        } else {
            resultExpr = new IfExprNullCondExpr(whenExpr.getOutputColumnNum(), elseExpr.getOutputColumnNum(), outputColumnNum);
        }
        resultExpr.setChildExpressions(new VectorExpression[] { whenExpr, elseExpr });
        resultExpr.setInputTypeInfos(whenExpr.getOutputTypeInfo(), TypeInfoFactory.voidTypeInfo, elseExpr.getOutputTypeInfo());
        resultExpr.setInputDataTypePhysicalVariations(whenExpr.getOutputDataTypePhysicalVariation(), outputDataTypePhysicalVariation, elseExpr.getOutputDataTypePhysicalVariation());
        resultExpr.setOutputTypeInfo(returnType);
        resultExpr.setOutputDataTypePhysicalVariation(outputDataTypePhysicalVariation);
        return resultExpr;
    }
    if (isElseNullConst) {
        final VectorExpression whenExpr = getVectorExpression(ifDesc, VectorExpressionDescriptor.Mode.PROJECTION);
        final VectorExpression thenExpr = getVectorExpression(thenDesc, VectorExpressionDescriptor.Mode.PROJECTION);
        DataTypePhysicalVariation outputDataTypePhysicalVariation = (thenExpr.getOutputDataTypePhysicalVariation() == null) ? DataTypePhysicalVariation.NONE : thenExpr.getOutputDataTypePhysicalVariation();
        final int outputColumnNum = ocm.allocateOutputColumn(returnType, outputDataTypePhysicalVariation);
        final VectorExpression resultExpr;
        if (!isThenCondExpr || isOnlyGood) {
            resultExpr = new IfExprColumnNull(whenExpr.getOutputColumnNum(), thenExpr.getOutputColumnNum(), outputColumnNum);
        } else {
            resultExpr = new IfExprCondExprNull(whenExpr.getOutputColumnNum(), thenExpr.getOutputColumnNum(), outputColumnNum);
        }
        resultExpr.setChildExpressions(new VectorExpression[] { whenExpr, thenExpr });
        resultExpr.setInputTypeInfos(whenExpr.getOutputTypeInfo(), thenExpr.getOutputTypeInfo(), TypeInfoFactory.voidTypeInfo);
        resultExpr.setInputDataTypePhysicalVariations(whenExpr.getOutputDataTypePhysicalVariation(), thenExpr.getOutputDataTypePhysicalVariation(), outputDataTypePhysicalVariation);
        resultExpr.setOutputTypeInfo(returnType);
        resultExpr.setOutputDataTypePhysicalVariation(outputDataTypePhysicalVariation);
        return resultExpr;
    }
    if ((isThenCondExpr || isElseCondExpr) && !isOnlyGood) {
        final VectorExpression whenExpr = getVectorExpression(ifDesc, VectorExpressionDescriptor.Mode.PROJECTION);
        final VectorExpression thenExpr = getVectorExpression(thenDesc, VectorExpressionDescriptor.Mode.PROJECTION);
        final VectorExpression elseExpr = getVectorExpression(elseDesc, VectorExpressionDescriptor.Mode.PROJECTION);
        // Only proceed if the THEN/ELSE types were aligned.
        if (thenExpr.getOutputColumnVectorType() == elseExpr.getOutputColumnVectorType()) {
            DataTypePhysicalVariation outputDataTypePhysicalVariation = (thenExpr.getOutputDataTypePhysicalVariation() == elseExpr.getOutputDataTypePhysicalVariation() && thenExpr.getOutputDataTypePhysicalVariation() != null) ? thenExpr.getOutputDataTypePhysicalVariation() : DataTypePhysicalVariation.NONE;
            final int outputColumnNum = ocm.allocateOutputColumn(returnType, outputDataTypePhysicalVariation);
            final VectorExpression resultExpr;
            if (isThenCondExpr && isElseCondExpr) {
                resultExpr = new IfExprCondExprCondExpr(whenExpr.getOutputColumnNum(), thenExpr.getOutputColumnNum(), elseExpr.getOutputColumnNum(), outputColumnNum);
            } else if (isThenCondExpr) {
                resultExpr = new IfExprCondExprColumn(whenExpr.getOutputColumnNum(), thenExpr.getOutputColumnNum(), elseExpr.getOutputColumnNum(), outputColumnNum);
            } else {
                resultExpr = new IfExprColumnCondExpr(whenExpr.getOutputColumnNum(), thenExpr.getOutputColumnNum(), elseExpr.getOutputColumnNum(), outputColumnNum);
            }
            resultExpr.setChildExpressions(new VectorExpression[] { whenExpr, thenExpr, elseExpr });
            resultExpr.setInputTypeInfos(whenExpr.getOutputTypeInfo(), thenExpr.getOutputTypeInfo(), elseExpr.getOutputTypeInfo());
            resultExpr.setInputDataTypePhysicalVariations(whenExpr.getOutputDataTypePhysicalVariation(), thenExpr.getOutputDataTypePhysicalVariation(), elseExpr.getOutputDataTypePhysicalVariation());
            resultExpr.setOutputTypeInfo(returnType);
            resultExpr.setOutputDataTypePhysicalVariation(outputDataTypePhysicalVariation);
            return resultExpr;
        }
    }
    Class<?> udfClass = genericUDFIf.getClass();
    return getVectorExpressionForUdf(genericUDFIf, udfClass, childExpr, VectorExpressionDescriptor.Mode.PROJECTION, returnType);
}
Also used : IfExprColumnCondExpr(org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprColumnCondExpr) IfExprCondExprColumn(org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprCondExprColumn) DataTypePhysicalVariation(org.apache.hadoop.hive.common.type.DataTypePhysicalVariation) IfExprColumnNull(org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprColumnNull) 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) IfExprNullNull(org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprNullNull) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) IfExprCondExprNull(org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprCondExprNull) IfExprCondExprCondExpr(org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprCondExprCondExpr) IfExprNullColumn(org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprNullColumn) IfExprNullCondExpr(org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprNullCondExpr)

Aggregations

DataTypePhysicalVariation (org.apache.hadoop.hive.common.type.DataTypePhysicalVariation)1 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 IfExprColumnCondExpr (org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprColumnCondExpr)1 IfExprColumnNull (org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprColumnNull)1 IfExprCondExprColumn (org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprCondExprColumn)1 IfExprCondExprCondExpr (org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprCondExprCondExpr)1 IfExprCondExprNull (org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprCondExprNull)1 IfExprNullColumn (org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprNullColumn)1 IfExprNullCondExpr (org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprNullCondExpr)1 IfExprNullNull (org.apache.hadoop.hive.ql.exec.vector.expressions.IfExprNullNull)1 VectorExpression (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression)1 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)1