You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/02/18 04:08:53 UTC

[GitHub] [iceberg] kbendick commented on a change in pull request #4060: Flink: DataIteratorBatcher that converts iterator of T to iterator of…

kbendick commented on a change in pull request #4060:
URL: https://github.com/apache/iceberg/pull/4060#discussion_r809659361



##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/DataIterator.java
##########
@@ -41,16 +42,59 @@
   private final FileScanTaskReader<T> fileScanTaskReader;
 
   private final InputFilesDecryptor inputFilesDecryptor;
+  private final CombinedScanTask combinedTask;
+
   private Iterator<FileScanTask> tasks;
   private CloseableIterator<T> currentIterator;
+  private int fileOffset;
+  private long recordOffset;
 
   public DataIterator(FileScanTaskReader<T> fileScanTaskReader, CombinedScanTask task,
                       FileIO io, EncryptionManager encryption) {
     this.fileScanTaskReader = fileScanTaskReader;
 
     this.inputFilesDecryptor = new InputFilesDecryptor(task, io, encryption);
+    this.combinedTask = task;
+
     this.tasks = task.files().iterator();
     this.currentIterator = CloseableIterator.empty();
+
+    // fileOffset starts at -1 because we started
+    // from an empty iterator that is not from the split files.
+    this.fileOffset = -1;
+    // record offset points to the record that next() should return when called
+    this.recordOffset = 0L;
+  }
+
+  /**
+   * (startingFileOffset, startingRecordOffset) points to the next row that reader should resume from.
+   * E.g., if the seek position is (file=0, record=1), seek moves the iterator position to the 2nd row
+   * in file 0. When next() is called after seek, 2nd row from file 0 should be returned.
+   */
+  public void seek(int startingFileOffset, long startingRecordOffset) {
+    Preconditions.checkState(fileOffset == -1,
+        "Seek should be called before any other iterator actions");
+    // skip files
+    Preconditions.checkState(startingFileOffset < combinedTask.files().size(),
+        "Invalid startingFileOffset %d for CombinedScanTask with %d files: %s",
+        startingFileOffset, combinedTask.files().size(), combinedTask);
+    for (long i = 0L; i < startingFileOffset; ++i) {
+      tasks.next();
+    }
+
+    updateCurrentIterator();
+    // skip records within the file
+    for (long i = 0; i < startingRecordOffset; ++i) {
+      if (currentFileHasNext() && hasNext()) {
+        next();
+      } else {
+        throw new IllegalStateException(String.format("Invalid startingRecordOffset %d for file %d " +
+            "from CombinedScanTask: %s", startingRecordOffset, startingFileOffset, combinedTask));

Review comment:
       Nit when you update the exception language:
   
   Is it possible to move the arguments around so you don’t have to use `+` on two strings inside of String.format? Not the end of the world but if you’re updating that spot already, it’s something to consider.




-- 
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: issues-unsubscribe@iceberg.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org