You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "alexprosak (via GitHub)" <gi...@apache.org> on 2026/06/03 23:29:10 UTC
[PR] Spark: Support Initial Snapshot Load for Streaming Reads [iceberg]
alexprosak opened a new pull request, #16679:
URL: https://github.com/apache/iceberg/pull/16679
Closes <issue #>
Implements an initial-snapshot bootstrap for streaming reads of Iceberg tables in Spark. A streaming query started with a fresh checkpoint now reads the current snapshot in full as its first batch, then continues incrementally - matching how Delta Lake's streaming source behaves by default.
Currently a fresh Iceberg streaming query without options replays the table's history from the oldest ancestor snapshot, which is slow for long-lived tables and any expired/deleted snapshots cannot be streamed. The only existing workarounds (bootstrap via batch read + cut over by timestamp) are fragile, so users can't easily express the common pattern of loading the entire table and then keeping up with new append data.
## About the Change
This PR adds a `stream-from-snapshot` option:
| `stream-from-snapshot` | Behavior |
|---|---|
| *(not set)* | **new default**: read the current snapshot in full, then continue with new snapshots |
| `latest` | read snapshots committed after stream startup |
| `earliest` | read from the oldest ancestor (the existing default) |
| *`<snapshot-id>`* | read snapshots after the given snapshot id (exclusive) |
`stream-from-snapshot` and `stream-from-timestamp` are mutually exclusive. Previous oldest ancestor default behavior can be opted-in via `stream-from-snapshot=earliest`
The implementation reuses a `scanAllFiles` flag that already existed on `StreamingOffset` but has previously always been set to false. The new default returns `StreamingOffset(currentSnapshotId, 0, scanAllFiles=true)`. `SyncSparkMicroBatchPlanner.planFiles()` bypasses `shouldProcess` for the initial snapshot so an OVERWRITE / DELETE / REPLACE current snapshot is read for its full table state rather than rejected.
**Follow-ups**:
- Docs update with new default behavior & `stream-from-snapshot` option
- Ports to other supported spark versions
**Future Work**:
- Supporting row-level deletes in the initial-snapshot read: the streaming planner does not load delete manifests, so V2 positional/equality delete files and V3 deletion vectors aren't applied. To avoid silently emitting row-level-deleted rows, initial snapshot load will throw currently when the current snapshot has any delete manifests.
--
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
Re: [PR] Spark: Support Initial Snapshot Load for Streaming Reads [iceberg]
Posted by "alexprosak (via GitHub)" <gi...@apache.org>.
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: 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
Re: [PR] Spark: Support Initial Snapshot Load for Streaming Reads [iceberg]
Posted by "liucao-dd (via GitHub)" <gi...@apache.org>.
liucao-dd commented on code in PR #16679:
URL: https://github.com/apache/iceberg/pull/16679#discussion_r3354342817
##########
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);
+ }
+
+ static StreamingOffset determineStartingOffset(
+ Table table, long fromTimestamp, String fromSnapshot) {
+ ValidationException.check(
+ fromSnapshot == null || fromTimestamp == Long.MIN_VALUE,
+ "Cannot set both '%s' and '%s' options",
+ SparkReadOptions.STREAM_FROM_SNAPSHOT,
+ SparkReadOptions.STREAM_FROM_TIMESTAMP);
+
if (table.currentSnapshot() == null) {
return StreamingOffset.START_OFFSET;
}
+ if (fromSnapshot != null) {
+ return startingOffsetFromSnapshotOption(table, fromSnapshot);
+ }
+
if (fromTimestamp == Long.MIN_VALUE) {
- // start from the oldest snapshot, since default value is MIN_VALUE
- // avoids looping to find first snapshot
- return new StreamingOffset(SnapshotUtil.oldestAncestor(table).snapshotId(), 0, false);
+ // read the initial snapshot in full, then continue with incremental changes
+ Snapshot current = table.currentSnapshot();
+
+ // Refuse row-level deletes rather than silently emit them
+ ValidationException.check(
+ current.deleteManifests(table.io()).isEmpty(),
+ "Cannot stream initial snapshot %d in full: snapshot has row-level deletes "
+ + "(V2 positional/equality delete files or V3 deletion vectors), which the "
+ + "Iceberg streaming source does not apply. Set '%s' to one of: '%s' "
+ + "(skip the backlog), '%s' (replay history snapshot-by-snapshot, with "
+ + "'streaming-skip-overwrite-snapshots'/'streaming-skip-delete-snapshots' as "
+ + "needed), or a specific snapshot id to start after.",
+ current.snapshotId(),
+ SparkReadOptions.STREAM_FROM_SNAPSHOT,
+ SparkReadOptions.STREAM_FROM_SNAPSHOT_LATEST,
+ SparkReadOptions.STREAM_FROM_SNAPSHOT_EARLIEST);
+ return new StreamingOffset(current.snapshotId(), 0L, true);
Review Comment:
This changes the fresh-checkpoint default from replaying incremental history from the oldest ancestor to reading only the current table state. That is a breaking semantic change for existing streaming jobs/backfills that rely on the no-option behavior.
A concrete compatibility failure mode is a job that currently uses the incremental path with `streaming-skip-delete-snapshots=true` and/or `streaming-skip-overwrite-snapshots=true` to tolerate delete/overwrite snapshots. With this new default, a fresh checkpoint on a table whose current live state still has row-level delete manifests fails during initial offset creation at the `current.deleteManifests(table.io()).isEmpty()` guard. That happens before the planner reaches `shouldProcess`, so the existing skip options never get a chance to apply. The streaming source still does not apply delete manifests either way; this is about changing when and how an existing configured stream fails.
In all honesty, if we have this "reading only the current table state" from the beginning I would choose it as default. But I imagine at the current state of adoption it may be hard to making breaking changes. Open to ideas on this
--
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
Re: [PR] Spark: Support Initial Snapshot Load for Streaming Reads [iceberg]
Posted by "alexprosak (via GitHub)" <gi...@apache.org>.
alexprosak commented on PR #16679:
URL: https://github.com/apache/iceberg/pull/16679#issuecomment-4906296973
@singhpk234 @huaxingao could you take a look? Thanks in advance!
--
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
Re: [PR] Spark: Support Initial Snapshot Load for Streaming Reads [iceberg]
Posted by "alexprosak (via GitHub)" <gi...@apache.org>.
alexprosak commented on PR #16679:
URL: https://github.com/apache/iceberg/pull/16679#issuecomment-5667627370
reopened here https://github.com/apache/iceberg/pull/18068
--
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
Re: [PR] Spark: Support Initial Snapshot Load for Streaming Reads [iceberg]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #16679:
URL: https://github.com/apache/iceberg/pull/16679#issuecomment-5433210453
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.
--
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
Re: [PR] Spark: Support Initial Snapshot Load for Streaming Reads [iceberg]
Posted by "liucao-dd (via GitHub)" <gi...@apache.org>.
liucao-dd commented on code in PR #16679:
URL: https://github.com/apache/iceberg/pull/16679#discussion_r3354342817
##########
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);
+ }
+
+ static StreamingOffset determineStartingOffset(
+ Table table, long fromTimestamp, String fromSnapshot) {
+ ValidationException.check(
+ fromSnapshot == null || fromTimestamp == Long.MIN_VALUE,
+ "Cannot set both '%s' and '%s' options",
+ SparkReadOptions.STREAM_FROM_SNAPSHOT,
+ SparkReadOptions.STREAM_FROM_TIMESTAMP);
+
if (table.currentSnapshot() == null) {
return StreamingOffset.START_OFFSET;
}
+ if (fromSnapshot != null) {
+ return startingOffsetFromSnapshotOption(table, fromSnapshot);
+ }
+
if (fromTimestamp == Long.MIN_VALUE) {
- // start from the oldest snapshot, since default value is MIN_VALUE
- // avoids looping to find first snapshot
- return new StreamingOffset(SnapshotUtil.oldestAncestor(table).snapshotId(), 0, false);
+ // read the initial snapshot in full, then continue with incremental changes
+ Snapshot current = table.currentSnapshot();
+
+ // Refuse row-level deletes rather than silently emit them
+ ValidationException.check(
+ current.deleteManifests(table.io()).isEmpty(),
+ "Cannot stream initial snapshot %d in full: snapshot has row-level deletes "
+ + "(V2 positional/equality delete files or V3 deletion vectors), which the "
+ + "Iceberg streaming source does not apply. Set '%s' to one of: '%s' "
+ + "(skip the backlog), '%s' (replay history snapshot-by-snapshot, with "
+ + "'streaming-skip-overwrite-snapshots'/'streaming-skip-delete-snapshots' as "
+ + "needed), or a specific snapshot id to start after.",
+ current.snapshotId(),
+ SparkReadOptions.STREAM_FROM_SNAPSHOT,
+ SparkReadOptions.STREAM_FROM_SNAPSHOT_LATEST,
+ SparkReadOptions.STREAM_FROM_SNAPSHOT_EARLIEST);
+ return new StreamingOffset(current.snapshotId(), 0L, true);
Review Comment:
This changes the fresh-checkpoint default from replaying incremental history from the oldest ancestor to reading only the current table state. That is a breaking semantic change for existing streaming jobs/backfills that rely on the no-option behavior.
A concrete compatibility failure mode is a job that currently uses the incremental path with `streaming-skip-delete-snapshots=true` and/or `streaming-skip-overwrite-snapshots=true` to tolerate delete/overwrite snapshots. With this new default, a fresh checkpoint on a table whose current live state still has row-level delete manifests fails during initial offset creation at the `current.deleteManifests(table.io()).isEmpty()` guard. That happens before the planner reaches `shouldProcess`, so the existing skip options never get a chance to apply.
In all honesty, if we have this "reading only the current table state" from the beginning I would choose it as default. But I imagine at the current state of adoption it may be hard to making breaking changes. Open to ideas on this
--
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
Re: [PR] Spark: Support Initial Snapshot Load for Streaming Reads [iceberg]
Posted by "huan233usc (via GitHub)" <gi...@apache.org>.
huan233usc commented on code in PR #16679:
URL: https://github.com/apache/iceberg/pull/16679#discussion_r3360716253
##########
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);
+ }
+
+ static StreamingOffset determineStartingOffset(
+ Table table, long fromTimestamp, String fromSnapshot) {
+ ValidationException.check(
+ fromSnapshot == null || fromTimestamp == Long.MIN_VALUE,
+ "Cannot set both '%s' and '%s' options",
+ SparkReadOptions.STREAM_FROM_SNAPSHOT,
+ SparkReadOptions.STREAM_FROM_TIMESTAMP);
+
if (table.currentSnapshot() == null) {
return StreamingOffset.START_OFFSET;
}
+ if (fromSnapshot != null) {
+ return startingOffsetFromSnapshotOption(table, fromSnapshot);
+ }
+
if (fromTimestamp == Long.MIN_VALUE) {
- // start from the oldest snapshot, since default value is MIN_VALUE
- // avoids looping to find first snapshot
- return new StreamingOffset(SnapshotUtil.oldestAncestor(table).snapshotId(), 0, false);
+ // read the initial snapshot in full, then continue with incremental changes
+ Snapshot current = table.currentSnapshot();
+
+ // Refuse row-level deletes rather than silently emit them
+ ValidationException.check(
+ current.deleteManifests(table.io()).isEmpty(),
+ "Cannot stream initial snapshot %d in full: snapshot has row-level deletes "
+ + "(V2 positional/equality delete files or V3 deletion vectors), which the "
+ + "Iceberg streaming source does not apply. Set '%s' to one of: '%s' "
+ + "(skip the backlog), '%s' (replay history snapshot-by-snapshot, with "
+ + "'streaming-skip-overwrite-snapshots'/'streaming-skip-delete-snapshots' as "
+ + "needed), or a specific snapshot id to start after.",
+ current.snapshotId(),
+ SparkReadOptions.STREAM_FROM_SNAPSHOT,
+ SparkReadOptions.STREAM_FROM_SNAPSHOT_LATEST,
+ SparkReadOptions.STREAM_FROM_SNAPSHOT_EARLIEST);
+ return new StreamingOffset(current.snapshotId(), 0L, true);
Review Comment:
Can we make planInputPartition to make datafile reading path supports dv/delete file first? Those looks like a breakage but fixable.
--
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
Re: [PR] Spark: Support Initial Snapshot Load for Streaming Reads [iceberg]
Posted by "liucao-dd (via GitHub)" <gi...@apache.org>.
liucao-dd commented on code in PR #16679:
URL: https://github.com/apache/iceberg/pull/16679#discussion_r3354342817
##########
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);
+ }
+
+ static StreamingOffset determineStartingOffset(
+ Table table, long fromTimestamp, String fromSnapshot) {
+ ValidationException.check(
+ fromSnapshot == null || fromTimestamp == Long.MIN_VALUE,
+ "Cannot set both '%s' and '%s' options",
+ SparkReadOptions.STREAM_FROM_SNAPSHOT,
+ SparkReadOptions.STREAM_FROM_TIMESTAMP);
+
if (table.currentSnapshot() == null) {
return StreamingOffset.START_OFFSET;
}
+ if (fromSnapshot != null) {
+ return startingOffsetFromSnapshotOption(table, fromSnapshot);
+ }
+
if (fromTimestamp == Long.MIN_VALUE) {
- // start from the oldest snapshot, since default value is MIN_VALUE
- // avoids looping to find first snapshot
- return new StreamingOffset(SnapshotUtil.oldestAncestor(table).snapshotId(), 0, false);
+ // read the initial snapshot in full, then continue with incremental changes
+ Snapshot current = table.currentSnapshot();
+
+ // Refuse row-level deletes rather than silently emit them
+ ValidationException.check(
+ current.deleteManifests(table.io()).isEmpty(),
+ "Cannot stream initial snapshot %d in full: snapshot has row-level deletes "
+ + "(V2 positional/equality delete files or V3 deletion vectors), which the "
+ + "Iceberg streaming source does not apply. Set '%s' to one of: '%s' "
+ + "(skip the backlog), '%s' (replay history snapshot-by-snapshot, with "
+ + "'streaming-skip-overwrite-snapshots'/'streaming-skip-delete-snapshots' as "
+ + "needed), or a specific snapshot id to start after.",
+ current.snapshotId(),
+ SparkReadOptions.STREAM_FROM_SNAPSHOT,
+ SparkReadOptions.STREAM_FROM_SNAPSHOT_LATEST,
+ SparkReadOptions.STREAM_FROM_SNAPSHOT_EARLIEST);
+ return new StreamingOffset(current.snapshotId(), 0L, true);
Review Comment:
This changes the fresh-checkpoint default from replaying incremental history from the oldest ancestor to reading only the current table state. That is a breaking semantic change for existing streaming jobs/backfills that rely on the no-option behavior, and it can also turn previously valid streams into startup failures when the current snapshot has live row-level delete manifests.
Can we keep the existing default and make initial-snapshot loading explicit behind the new option? If the project wants to flip the default, it seems worth doing with a documented migration/deprecation path rather than in the same PR that introduces the feature.
##########
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:
I think this breaks `stream-from-snapshot=<current snapshot id>`. This persists `START_OFFSET` (`snapshotId=-1`, `position=-1`) even though the current snapshot is a valid exclusive starting point. The sync planner can later resolve this through `table.snapshot(-1)` and fail, while async paths may fall back into default starting-offset behavior.
This should probably return an offset at the end of the current snapshot, similar to `latest`, so the stream has no backlog and waits for future snapshots.
##########
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:
This overload now drops the new `stream-from-snapshot` option by always passing `null`. There is still an async planner path (`BaseSparkMicroBatchPlanner.nextValidSnapshot(null)`) that calls the two-arg overload, so async planning can bypass the new option's validation and semantics.
Can we plumb `readConf.streamFromSnapshot()` through that path instead of relying on this overload? A test with async planning enabled and an explicit `stream-from-snapshot` value would help catch this.
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/SparkReadOptions.java:
##########
@@ -80,6 +80,15 @@ private SparkReadOptions() {}
// Timestamp in milliseconds; start a stream from the snapshot that occurs after this timestamp
public static final String STREAM_FROM_TIMESTAMP = "stream-from-timestamp";
+ // Starting point for a streaming read. Accepts a snapshot id, "latest", or "earliest"
+ public static final String STREAM_FROM_SNAPSHOT = "stream-from-snapshot";
Review Comment:
TODO reminder for later: before this graduates from draft/merge, please update the Spark structured streaming/read-options docs and either port this option to the other active Spark source trees (`v4.0`/`v4.1`) or clearly document why this PR is intentionally scoped to Spark 3.5 only.
--
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
Re: [PR] Spark: Support Initial Snapshot Load for Streaming Reads [iceberg]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #16679: Spark: Support Initial Snapshot Load for Streaming Reads
URL: https://github.com/apache/iceberg/pull/16679
--
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
Re: [PR] Spark: Support Initial Snapshot Load for Streaming Reads [iceberg]
Posted by "alexprosak (via GitHub)" <gi...@apache.org>.
alexprosak commented on code in PR #16679:
URL: https://github.com/apache/iceberg/pull/16679#discussion_r3358030996
##########
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);
+ }
+
+ static StreamingOffset determineStartingOffset(
+ Table table, long fromTimestamp, String fromSnapshot) {
+ ValidationException.check(
+ fromSnapshot == null || fromTimestamp == Long.MIN_VALUE,
+ "Cannot set both '%s' and '%s' options",
+ SparkReadOptions.STREAM_FROM_SNAPSHOT,
+ SparkReadOptions.STREAM_FROM_TIMESTAMP);
+
if (table.currentSnapshot() == null) {
return StreamingOffset.START_OFFSET;
}
+ if (fromSnapshot != null) {
+ return startingOffsetFromSnapshotOption(table, fromSnapshot);
+ }
+
if (fromTimestamp == Long.MIN_VALUE) {
- // start from the oldest snapshot, since default value is MIN_VALUE
- // avoids looping to find first snapshot
- return new StreamingOffset(SnapshotUtil.oldestAncestor(table).snapshotId(), 0, false);
+ // read the initial snapshot in full, then continue with incremental changes
+ Snapshot current = table.currentSnapshot();
+
+ // Refuse row-level deletes rather than silently emit them
+ ValidationException.check(
+ current.deleteManifests(table.io()).isEmpty(),
+ "Cannot stream initial snapshot %d in full: snapshot has row-level deletes "
+ + "(V2 positional/equality delete files or V3 deletion vectors), which the "
+ + "Iceberg streaming source does not apply. Set '%s' to one of: '%s' "
+ + "(skip the backlog), '%s' (replay history snapshot-by-snapshot, with "
+ + "'streaming-skip-overwrite-snapshots'/'streaming-skip-delete-snapshots' as "
+ + "needed), or a specific snapshot id to start after.",
+ current.snapshotId(),
+ SparkReadOptions.STREAM_FROM_SNAPSHOT,
+ SparkReadOptions.STREAM_FROM_SNAPSHOT_LATEST,
+ SparkReadOptions.STREAM_FROM_SNAPSHOT_EARLIEST);
+ return new StreamingOffset(current.snapshotId(), 0L, true);
Review Comment:
Agreed this is a breaking change, and I appreciate the careful read. I'm in agreement with you that I'd would've preferred this new behavior as the default from the get-go since it matches Delta's default and is probably what most users actually want when they start a fresh stream.
That said, I'm open to make the initial snapshot load opt-in rather than the new default if maintainers agree.
One way to represent it could be to add `initial-snapshot` as the third accepted value for `stream-from-snapshot`, alongside `latest` / `<snapshot-id>`, where oldest ancestor would remain the default with no option specified.
--
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
Re: [PR] Spark: Support Initial Snapshot Load for Streaming Reads [iceberg]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #16679:
URL: https://github.com/apache/iceberg/pull/16679#issuecomment-5533886451
This pull request has been closed due to lack of activity. This is not a judgement on the merit of the PR in any way. It is just a way of keeping the PR queue manageable. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.
--
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
Re: [PR] Spark: Support Initial Snapshot Load for Streaming Reads [iceberg]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #16679:
URL: https://github.com/apache/iceberg/pull/16679#issuecomment-4888197242
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.
--
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
Re: [PR] Spark: Support Initial Snapshot Load for Streaming Reads [iceberg]
Posted by "liucao-dd (via GitHub)" <gi...@apache.org>.
liucao-dd commented on code in PR #16679:
URL: https://github.com/apache/iceberg/pull/16679#discussion_r3354342817
##########
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);
+ }
+
+ static StreamingOffset determineStartingOffset(
+ Table table, long fromTimestamp, String fromSnapshot) {
+ ValidationException.check(
+ fromSnapshot == null || fromTimestamp == Long.MIN_VALUE,
+ "Cannot set both '%s' and '%s' options",
+ SparkReadOptions.STREAM_FROM_SNAPSHOT,
+ SparkReadOptions.STREAM_FROM_TIMESTAMP);
+
if (table.currentSnapshot() == null) {
return StreamingOffset.START_OFFSET;
}
+ if (fromSnapshot != null) {
+ return startingOffsetFromSnapshotOption(table, fromSnapshot);
+ }
+
if (fromTimestamp == Long.MIN_VALUE) {
- // start from the oldest snapshot, since default value is MIN_VALUE
- // avoids looping to find first snapshot
- return new StreamingOffset(SnapshotUtil.oldestAncestor(table).snapshotId(), 0, false);
+ // read the initial snapshot in full, then continue with incremental changes
+ Snapshot current = table.currentSnapshot();
+
+ // Refuse row-level deletes rather than silently emit them
+ ValidationException.check(
+ current.deleteManifests(table.io()).isEmpty(),
+ "Cannot stream initial snapshot %d in full: snapshot has row-level deletes "
+ + "(V2 positional/equality delete files or V3 deletion vectors), which the "
+ + "Iceberg streaming source does not apply. Set '%s' to one of: '%s' "
+ + "(skip the backlog), '%s' (replay history snapshot-by-snapshot, with "
+ + "'streaming-skip-overwrite-snapshots'/'streaming-skip-delete-snapshots' as "
+ + "needed), or a specific snapshot id to start after.",
+ current.snapshotId(),
+ SparkReadOptions.STREAM_FROM_SNAPSHOT,
+ SparkReadOptions.STREAM_FROM_SNAPSHOT_LATEST,
+ SparkReadOptions.STREAM_FROM_SNAPSHOT_EARLIEST);
+ return new StreamingOffset(current.snapshotId(), 0L, true);
Review Comment:
This changes the fresh-checkpoint default from replaying incremental history from the oldest ancestor to reading only the current table state. That is a breaking semantic change for existing streaming jobs/backfills that rely on the no-option behavior.
One related compatibility concern is the row-level-delete failure mode: the streaming source does not apply delete manifests today, but the new default adds a startup guard when the current snapshot has live row-level delete manifests. That can fail jobs at startup in cases where the previous incremental path would have used the existing delete/overwrite snapshot handling options instead. This seems much safer as an explicit opt-in mode than as the new default.
Can we keep the existing default and make initial-snapshot loading explicit behind the new option? If the project wants to flip the default, it seems worth doing with a documented migration/deprecation path rather than in the same PR that introduces the feature.
--
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
Re: [PR] Spark: Support Initial Snapshot Load for Streaming Reads [iceberg]
Posted by "liucao-dd (via GitHub)" <gi...@apache.org>.
liucao-dd commented on code in PR #16679:
URL: https://github.com/apache/iceberg/pull/16679#discussion_r3354342817
##########
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);
+ }
+
+ static StreamingOffset determineStartingOffset(
+ Table table, long fromTimestamp, String fromSnapshot) {
+ ValidationException.check(
+ fromSnapshot == null || fromTimestamp == Long.MIN_VALUE,
+ "Cannot set both '%s' and '%s' options",
+ SparkReadOptions.STREAM_FROM_SNAPSHOT,
+ SparkReadOptions.STREAM_FROM_TIMESTAMP);
+
if (table.currentSnapshot() == null) {
return StreamingOffset.START_OFFSET;
}
+ if (fromSnapshot != null) {
+ return startingOffsetFromSnapshotOption(table, fromSnapshot);
+ }
+
if (fromTimestamp == Long.MIN_VALUE) {
- // start from the oldest snapshot, since default value is MIN_VALUE
- // avoids looping to find first snapshot
- return new StreamingOffset(SnapshotUtil.oldestAncestor(table).snapshotId(), 0, false);
+ // read the initial snapshot in full, then continue with incremental changes
+ Snapshot current = table.currentSnapshot();
+
+ // Refuse row-level deletes rather than silently emit them
+ ValidationException.check(
+ current.deleteManifests(table.io()).isEmpty(),
+ "Cannot stream initial snapshot %d in full: snapshot has row-level deletes "
+ + "(V2 positional/equality delete files or V3 deletion vectors), which the "
+ + "Iceberg streaming source does not apply. Set '%s' to one of: '%s' "
+ + "(skip the backlog), '%s' (replay history snapshot-by-snapshot, with "
+ + "'streaming-skip-overwrite-snapshots'/'streaming-skip-delete-snapshots' as "
+ + "needed), or a specific snapshot id to start after.",
+ current.snapshotId(),
+ SparkReadOptions.STREAM_FROM_SNAPSHOT,
+ SparkReadOptions.STREAM_FROM_SNAPSHOT_LATEST,
+ SparkReadOptions.STREAM_FROM_SNAPSHOT_EARLIEST);
+ return new StreamingOffset(current.snapshotId(), 0L, true);
Review Comment:
This changes the fresh-checkpoint default from replaying incremental history from the oldest ancestor to reading only the current table state. That is a breaking semantic change for existing streaming jobs/backfills that rely on the no-option behavior.
A concrete compatibility failure mode is a job that currently uses the incremental path with `streaming-skip-delete-snapshots=true` and/or `streaming-skip-overwrite-snapshots=true` to tolerate delete/overwrite snapshots. With this new default, a fresh checkpoint on a table whose current live state still has row-level delete manifests fails during initial offset creation at the `current.deleteManifests(table.io()).isEmpty()` guard. That happens before the planner reaches `shouldProcess`, so the existing skip options never get a chance to apply. The streaming source still does not apply delete manifests either way; this is about changing when and how an existing configured stream fails.
Can we keep the existing default and make initial-snapshot loading explicit behind the new option? If the project wants to flip the default, it seems worth doing with a documented migration/deprecation path rather than in the same PR that introduces the feature.
##########
spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/SparkReadOptions.java:
##########
@@ -80,6 +80,15 @@ private SparkReadOptions() {}
// Timestamp in milliseconds; start a stream from the snapshot that occurs after this timestamp
public static final String STREAM_FROM_TIMESTAMP = "stream-from-timestamp";
+ // Starting point for a streaming read. Accepts a snapshot id, "latest", or "earliest"
+ public static final String STREAM_FROM_SNAPSHOT = "stream-from-snapshot";
Review Comment:
TODO reminder for later: before this graduates from draft/merge, please update the Spark structured streaming/read-options docs and either port this option to the other active Spark source trees (`v4.0`/`v4.1`) or clearly document why this PR is intentionally scoped to Spark 3.5 only.
--
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
Re: [PR] Spark: Support Initial Snapshot Load for Streaming Reads [iceberg]
Posted by "alexprosak (via GitHub)" <gi...@apache.org>.
alexprosak commented on code in PR #16679:
URL: https://github.com/apache/iceberg/pull/16679#discussion_r3538259762
##########
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);
+ }
+
+ static StreamingOffset determineStartingOffset(
+ Table table, long fromTimestamp, String fromSnapshot) {
+ ValidationException.check(
+ fromSnapshot == null || fromTimestamp == Long.MIN_VALUE,
+ "Cannot set both '%s' and '%s' options",
+ SparkReadOptions.STREAM_FROM_SNAPSHOT,
+ SparkReadOptions.STREAM_FROM_TIMESTAMP);
+
if (table.currentSnapshot() == null) {
return StreamingOffset.START_OFFSET;
}
+ if (fromSnapshot != null) {
+ return startingOffsetFromSnapshotOption(table, fromSnapshot);
+ }
+
if (fromTimestamp == Long.MIN_VALUE) {
- // start from the oldest snapshot, since default value is MIN_VALUE
- // avoids looping to find first snapshot
- return new StreamingOffset(SnapshotUtil.oldestAncestor(table).snapshotId(), 0, false);
+ // read the initial snapshot in full, then continue with incremental changes
+ Snapshot current = table.currentSnapshot();
+
+ // Refuse row-level deletes rather than silently emit them
+ ValidationException.check(
+ current.deleteManifests(table.io()).isEmpty(),
+ "Cannot stream initial snapshot %d in full: snapshot has row-level deletes "
+ + "(V2 positional/equality delete files or V3 deletion vectors), which the "
+ + "Iceberg streaming source does not apply. Set '%s' to one of: '%s' "
+ + "(skip the backlog), '%s' (replay history snapshot-by-snapshot, with "
+ + "'streaming-skip-overwrite-snapshots'/'streaming-skip-delete-snapshots' as "
+ + "needed), or a specific snapshot id to start after.",
+ current.snapshotId(),
+ SparkReadOptions.STREAM_FROM_SNAPSHOT,
+ SparkReadOptions.STREAM_FROM_SNAPSHOT_LATEST,
+ SparkReadOptions.STREAM_FROM_SNAPSHOT_EARLIEST);
+ return new StreamingOffset(current.snapshotId(), 0L, true);
Review Comment:
@huan233usc Added the support for dv/delete files as it was more of a refactor than a later addition. But will still leave this thread open for discussion on whether or not initial load should be the new default behavior vs an additional option
--
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