protected int computeStartFollowing(int rowIdx, PTFPartition p) throws HiveException {
    int amt = start.getAmt();
    Object sortKey = computeValueUseCache(rowIdx, p);

    Object rowVal = sortKey;

    if ( sortKey == null ) {
      // Use Case 9.
      if (nullsLast || expressionDef.getOrder() == Order.DESC) {
        return p.size();
      }
      else { // Use Case 10.
        while (rowIdx < p.size() && rowVal == null ) {
          Pair<Integer, Object> stepResult = skipOrStepForward(rowIdx, p);
          rowIdx = stepResult.getLeft();
          rowVal = stepResult.getRight();
        }
        return rowIdx;
      }
    }

    // Use Case 11,12
    if (enableBinarySearch) {
      return binarySearchForward(rowIdx, p, sortKey, amt, expressionDef.getOrder());
    } else {
      return linearSearchForward(rowIdx, p, sortKey, amt, expressionDef.getOrder());
    }
  }
Uses cache to lookup row value. Computes it on the fly on cache miss.
@param r
@param p
@return row value.
@throws HiveException
ql/src/java/org/apache/hadoop/hive/ql/udf/ptf/ValueBoundaryScanner.java