protected int computeEndPreceding(int rowIdx, PTFPartition p) throws HiveException {
    int amt = end.getAmt();
    // Use Case 1.
    // amt == UNBOUNDED, is caught during translation

    Object sortKey = computeValueUseCache(rowIdx, p);

    if ( sortKey == null ) {
      // Use Case 2.
      if (nullsLast || expressionDef.getOrder() == Order.DESC ) {
        return p.size();
      }
      else { // Use Case 3.
        return 0;
      }
    }

    int r = rowIdx;

    // Use Case 4,5
    if (enableBinarySearch) {
      return binarySearchBack(r, p, sortKey, amt, expressionDef.getOrder());
    } else {
      return linearSearchBack(r, 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