rdblue commented on a change in pull request #4060:
URL: https://github.com/apache/iceberg/pull/4060#discussion_r804861208
##########
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:
We usually like to use plain language rather than variable or class
names.
--
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]