pgaref commented on a change in pull request #2225:
URL: https://github.com/apache/hive/pull/2225#discussion_r681579584



##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/udf/ptf/ValueBoundaryScanner.java
##########
@@ -664,6 +632,87 @@ public Object computeValue(Object row) throws 
HiveException {
    */
   public abstract boolean isEqual(Object v1, Object v2);
 
+  protected int binarySearchBack(int r, PTFPartition p, Object sortKey, int 
amt,
+      Order order) throws HiveException {
+    boolean isOrderDesc = order.equals(Order.DESC);
+    Object rowVal = sortKey;
+
+    int rMin = -1;  // tracks lowest possible number fulfilling the range 
requirement
+    int rMax = r; // tracks highest possible number fulfilling the range 
requirement
+
+    boolean isDistanceGreater = true;
+    while (true) {
+      if (rMin == rMax) {
+        return rMin;
+      }
+      isDistanceGreater =
+          isDistanceGreater(isOrderDesc ? rowVal : sortKey, isOrderDesc ? 
sortKey : rowVal, amt);
+      if (!isDistanceGreater && r == 0) {
+        return 0;
+      }
+      if (isDistanceGreater) {
+        rMin = r + 1;
+      } else {
+        rMax = r;
+      }
+      r = rMin + (rMax - rMin) / 2;

Review comment:
       Right, makes sense




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to