gszadovszky commented on code in PR #1328:
URL: https://github.com/apache/parquet-java/pull/1328#discussion_r1624452491


##########
parquet-column/src/main/java/org/apache/parquet/internal/column/columnindex/IndexIterator.java:
##########
@@ -55,6 +55,105 @@ static PrimitiveIterator.OfInt rangeTranslate(int from, int 
to, IntUnaryOperator
     return new IndexIterator(from, to + 1, i -> true, translator);
   }
 
+  static PrimitiveIterator.OfInt intersection(PrimitiveIterator.OfInt lhs, 
PrimitiveIterator.OfInt rhs) {
+    return new PrimitiveIterator.OfInt() {
+      private int next = fetchNext();
+
+      @Override
+      public int nextInt() {
+        int result = next;

Review Comment:
   Sorry for bothering with the iterator contract again. It should throw 
`NoSuchElementException` if there are no more elements (instead of returning 
`-1`).



##########
parquet-column/src/main/java/org/apache/parquet/internal/column/columnindex/IndexIterator.java:
##########
@@ -55,6 +55,105 @@ static PrimitiveIterator.OfInt rangeTranslate(int from, int 
to, IntUnaryOperator
     return new IndexIterator(from, to + 1, i -> true, translator);
   }
 
+  static PrimitiveIterator.OfInt intersection(PrimitiveIterator.OfInt lhs, 
PrimitiveIterator.OfInt rhs) {
+    return new PrimitiveIterator.OfInt() {
+      private int next = fetchNext();
+
+      @Override
+      public int nextInt() {
+        int result = next;
+        next = fetchNext();
+        return result;
+      }
+
+      @Override
+      public boolean hasNext() {
+        return next != -1;
+      }
+
+      private int fetchNext() {
+        if (!lhs.hasNext() || !rhs.hasNext()) {
+          return -1;
+        }
+
+        // Since we know both iterators are in sorted order, we can iterate 
linearly through until
+        // we find the next value that belongs to both iterators, or terminate 
if none exist
+        int nextL = lhs.next();
+        int nextR = rhs.next();
+        while (nextL < nextR && lhs.hasNext()) {
+          nextL = lhs.next();
+        }
+        if (nextL == nextR) {
+          return nextL;
+        }
+        while (nextR < nextL && rhs.hasNext()) {
+          nextR = rhs.next();
+        }
+        if (nextL == nextR) {
+          return nextL;
+        }
+
+        return -1;
+      }
+    };
+  }
+
+  static PrimitiveIterator.OfInt union(PrimitiveIterator.OfInt lhs, 
PrimitiveIterator.OfInt rhs) {
+    return new PrimitiveIterator.OfInt() {
+      private int peekL = -1;
+      private int peekR = -1;
+      private int next = fetchNext();
+
+      @Override
+      public int nextInt() {
+        int result = next;

Review Comment:
   Missing exception, see above.



-- 
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