alexprosak commented on code in PR #16679:
URL: https://github.com/apache/iceberg/pull/16679#discussion_r3358032422
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/MicroBatchUtils.java:
##########
@@ -58,6 +91,57 @@ static StreamingOffset determineStartingOffset(Table table,
long fromTimestamp)
}
}
+ private static StreamingOffset startingOffsetFromSnapshotOption(
+ Table table, String fromSnapshot) {
+ String normalized = fromSnapshot.toLowerCase(Locale.ROOT);
+ Snapshot currentSnapshot = table.currentSnapshot();
+
+ if (SparkReadOptions.STREAM_FROM_SNAPSHOT_LATEST.equals(normalized)) {
+ // start from current snapshot, skipping backlog
+ return new StreamingOffset(
+ currentSnapshot.snapshotId(), addedFilesCount(table,
currentSnapshot), false);
+ }
+
+ if (SparkReadOptions.STREAM_FROM_SNAPSHOT_EARLIEST.equals(normalized)) {
+ // start from oldest snapshot
+ return new
StreamingOffset(SnapshotUtil.oldestAncestor(table).snapshotId(), 0L, false);
+ }
+
+ long fromSnapshotId;
+ try {
+ fromSnapshotId = Long.parseLong(fromSnapshot);
+ } catch (NumberFormatException e) {
+ throw new ValidationException(
+ "Invalid value for '%s': %s. Expected a snapshot id, '%s', or '%s'.",
+ SparkReadOptions.STREAM_FROM_SNAPSHOT,
+ fromSnapshot,
+ SparkReadOptions.STREAM_FROM_SNAPSHOT_LATEST,
+ SparkReadOptions.STREAM_FROM_SNAPSHOT_EARLIEST);
+ }
+
+ ValidationException.check(
+ table.snapshot(fromSnapshotId) != null,
+ "Cannot find snapshot for '%s': %s",
+ SparkReadOptions.STREAM_FROM_SNAPSHOT,
+ fromSnapshotId);
+ ValidationException.check(
+ SnapshotUtil.isAncestorOf(table, currentSnapshot.snapshotId(),
fromSnapshotId),
+ "Snapshot %s is not an ancestor of the current snapshot",
+ fromSnapshotId);
+
+ if (fromSnapshotId == currentSnapshot.snapshotId()) {
+ // The requested snapshot is the current snapshot, nothing after it yet
+ return StreamingOffset.START_OFFSET;
Review Comment:
good catch, updated + added test
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/MicroBatchUtils.java:
##########
@@ -31,14 +35,43 @@ class MicroBatchUtils {
private MicroBatchUtils() {}
static StreamingOffset determineStartingOffset(Table table, long
fromTimestamp) {
+ return determineStartingOffset(table, fromTimestamp, null);
Review Comment:
updated
--
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]