lidavidm commented on code in PR #761:
URL: https://github.com/apache/arrow-java/pull/761#discussion_r2099586002


##########
vector/src/main/java/org/apache/arrow/vector/compare/RangeEqualsVisitor.java:
##########
@@ -270,42 +271,38 @@ protected boolean compareRunEndEncodedVectors(Range 
range) {
     RunEndEncodedVector leftVector = (RunEndEncodedVector) left;
     RunEndEncodedVector rightVector = (RunEndEncodedVector) right;
 
-    final int leftRangeEnd = range.getLeftStart() + range.getLength();
-    final int rightRangeEnd = range.getRightStart() + range.getLength();
+    final RunEndEncodedVector.RangeIterator leftIterator =
+        new RunEndEncodedVector.RangeIterator(leftVector, 
range.getLeftStart(), range.getLength());
+    final RunEndEncodedVector.RangeIterator rightIterator =
+        new RunEndEncodedVector.RangeIterator(
+            rightVector, range.getRightStart(), range.getLength());
 
     FieldVector leftValuesVector = leftVector.getValuesVector();
     FieldVector rightValuesVector = rightVector.getValuesVector();
 
     RangeEqualsVisitor innerVisitor = createInnerVisitor(leftValuesVector, 
rightValuesVector, null);
 
-    int leftLogicalIndex = range.getLeftStart();
-    int rightLogicalIndex = range.getRightStart();
+    while (nextRun(leftIterator, rightIterator)) {
+      int leftPhysicalIndex = leftIterator.getRunIndex();
+      int rightPhysicalIndex = rightIterator.getRunIndex();
 
-    while (leftLogicalIndex < leftRangeEnd) {
-      // TODO: implement it more efficient
-      // https://github.com/apache/arrow/issues/44157
-      int leftPhysicalIndex = leftVector.getPhysicalIndex(leftLogicalIndex);
-      int rightPhysicalIndex = rightVector.getPhysicalIndex(rightLogicalIndex);
       if (leftValuesVector.accept(
           innerVisitor, new Range(leftPhysicalIndex, rightPhysicalIndex, 1))) {
-        int leftRunEnd = leftVector.getRunEnd(leftLogicalIndex);
-        int rightRunEnd = rightVector.getRunEnd(rightLogicalIndex);
-
-        int leftRunLength = Math.min(leftRunEnd, leftRangeEnd) - 
leftLogicalIndex;
-        int rightRunLength = Math.min(rightRunEnd, rightRangeEnd) - 
rightLogicalIndex;
-
-        if (leftRunLength != rightRunLength) {
+        if (leftIterator.getRunLength() != rightIterator.getRunLength()) {

Review Comment:
   While the original code had this problem too, maybe it's better to check the 
run length first? That's presumably a cheaper check and so we can bail out 
earlier.



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to