@Override
  public void evaluate(VectorizedRowBatch batch) throws HiveException {

    int n = batch.size;
    if (n <= 0) {
      // Nothing to do
      return;
    }

    /*
     * Do common analysis of the IF statement boolean expression.
     *
     * The following protected members can be examined afterwards:
     *
     *   boolean isIfStatementResultRepeated
     *   boolean isIfStatementResultThen
     *
     *   int thenSelectedCount
     *   int[] thenSelected
     *   int elseSelectedCount
     *   int[] elseSelected
     */
    super.evaluate(batch);

    ColumnVector outputColVector = batch.cols[outputColumnNum];
    boolean[] outputIsNull = outputColVector.isNull;

    // We do not need to do a column reset since we are carefully changing the output.
    outputColVector.isRepeating = false;

    // CONSIDER: Should be do this for all vector expressions that can
    //           work on BytesColumnVector output columns???
    outputColVector.init();

    ColumnVector thenColVector = batch.cols[inputColumnNum[1]];
    ColumnVector elseColVector = batch.cols[inputColumnNum[2]];

    final int thenCount = thenSelectedCount;
    final int elseCount = elseSelectedCount;

    if (isIfStatementResultRepeated) {
      if (isIfStatementResultThen) {
        // Evaluate THEN expression (only) and copy all its results.
        childExpressions[1].evaluate(batch);
        thenColVector.copySelected(batch.selectedInUse, batch.selected, n, outputColVector);
      } else {
        // Evaluate ELSE expression (only) and copy all its results.
        childExpressions[2].evaluate(batch);
        elseColVector.copySelected(batch.selectedInUse, batch.selected, n, outputColVector);
      }
      return;
    }

    // NOTE: We cannot use copySelected below since it is a whole column operation.

    // The THEN expression is either IdentityExpression (a column) or a ConstantVectorExpression
    // (a scalar) and trivial to evaluate.
    childExpressions[1].evaluate(batch);
    for (int i = 0; i < thenCount; i++) {
      final int batchIndex = thenSelected[i];
      outputIsNull[batchIndex] = false;
      outputColVector.setElement(batchIndex, batchIndex, thenColVector);
    }

    conditionalEvaluate(batch, childExpressions[2], elseSelected, elseCount);
    for (int i = 0; i < elseCount; i++) {
      final int batchIndex = elseSelected[i];
      outputIsNull[batchIndex] = false;
      outputColVector.setElement(batchIndex, batchIndex, elseColVector);
    }
  }
Do regular execution of the THEN vector expression (a column or scalar) and conditional execution
of the ELSE vector expression of a SQL IF statement.
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/IfExprColumnCondExpr.java