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

    // NOTE: We do conditional vector expression so we do not call super.evaluateChildren(batch).

    thenSelectedCount = 0;
    elseSelectedCount = 0;
    isIfStatementResultRepeated = false;
    isIfStatementResultThen = false;   // Give it a value.

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

    // Child #1 is the IF boolean expression.
    childExpressions[0].evaluate(batch);
    LongColumnVector ifExprColVector = (LongColumnVector) batch.cols[inputColumnNum[0]];
    if (ifExprColVector.isRepeating) {
      isIfStatementResultRepeated = true;
      isIfStatementResultThen =
          ((ifExprColVector.noNulls || !ifExprColVector.isNull[0]) &&
              ifExprColVector.vector[0] == 1);
      return;
    }

    if (thenSelected == null || n > thenSelected.length) {

      // (Re)allocate larger to be a multiple of 1024 (DEFAULT_SIZE).
      final int roundUpSize =
          ((n + VectorizedRowBatch.DEFAULT_SIZE - 1) / VectorizedRowBatch.DEFAULT_SIZE)
              * VectorizedRowBatch.DEFAULT_SIZE;
      thenSelected = new int[roundUpSize];
      elseSelected = new int[roundUpSize];
    }

    int[] sel = batch.selected;
    long[] vector = ifExprColVector.vector;

    if (ifExprColVector.noNulls) {
      if (batch.selectedInUse) {
        for (int j = 0; j < n; j++) {
          final int i = sel[j];
          if (vector[i] == 1) {
            thenSelected[thenSelectedCount++] = i;
          } else {
            elseSelected[elseSelectedCount++] = i;
          }
        }
      } else {
        for (int i = 0; i < n; i++) {
          if (vector[i] == 1) {
            thenSelected[thenSelectedCount++] = i;
          } else {
            elseSelected[elseSelectedCount++] = i;
          }
        }
      }
    } else {
      boolean[] isNull = ifExprColVector.isNull;
      if (batch.selectedInUse) {
        for (int j = 0; j < n; j++) {
          final int i = sel[j];
          if (!isNull[i] && vector[i] == 1) {
            thenSelected[thenSelectedCount++] = i;
          } else {
            elseSelected[elseSelectedCount++] = i;
          }
        }
      } else {
        for (int i = 0; i < n; i++) {
          if (!isNull[i] && vector[i] == 1) {
            thenSelected[thenSelectedCount++] = i;
          } else {
            elseSelected[elseSelectedCount++] = i;
          }
        }
      }
    }

    if (thenSelectedCount == 0) {
      isIfStatementResultRepeated = true;
      isIfStatementResultThen = false;
    } else if (elseSelectedCount == 0) {
      isIfStatementResultRepeated = true;
      isIfStatementResultThen = true;
    }
  }
Base class that supports conditional execution of the THEN/ELSE vector expressions of
a SQL IF statement.
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/IfExprCondExprBase.java